Skip to content

Commit

Permalink
GUI updates working towards Torus swaps in wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed May 6, 2024
1 parent 779adb8 commit 4edc715
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 15 deletions.
2 changes: 1 addition & 1 deletion convex-core/src/main/java/convex/core/init/Init.java
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ private static State doCurrencyDeploy(State s, AVector<ACell> row) {
double cvx = cvxPrice * supply / subDivisions;


Context ctx = Context.createFake(s, DISTRIBUTION_ADDRESS);
Context ctx = Context.createFake(s, GENESIS_ADDRESS);
ctx = ctx.eval(Reader
.read("(do (import convex.fungible :as fun) (deploy (fun/build-token {:supply " + supply + " :decimals "+decimals+"})))"));
Address addr = ctx.getResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void setBalance(AInteger a) {
append(chs,c,decimalSize);
}
for (int i=decimals; i<9; i++) {
append(" ",balanceColour,decimalSize);
append("\u2007",balanceColour,decimalSize);
}

Toolkit.addPopupMenu(this, new BalanceMenu());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static Convex tryConnect(JComponent parent,String prompt) {
try {
String target=pan.hostField.getText();
InetSocketAddress sa=Utils.toInetSocketAddress(target);
System.err.println("Attempting connect to: "+sa);
log.info("Attempting connect to: "+sa);
Convex convex=Convex.connect(sa);
convex.setAddress(pan.addressField.getAddress());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class ScrollyList<E> extends JScrollPane {
private final ListModel<E> model;
private final ScrollablePanel listPanel = new ScrollablePanel();

private final MigLayout listLayout;

public void refreshList() {
EventQueue.invokeLater(()->{;
listPanel.removeAll();
Expand Down Expand Up @@ -74,7 +76,8 @@ public ScrollyList(ListModel<E> model, Function<E, Component> builder) {
this.model = model;
// this.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

listPanel.setLayout(new MigLayout("wrap 1"));
listLayout=new MigLayout("wrap");
listPanel.setLayout(listLayout);
setViewportView(listPanel);
getViewport().setBackground(null);

Expand All @@ -84,7 +87,7 @@ public void intervalAdded(ListDataEvent e) {
int start=e.getIndex0();
int last=e.getIndex1();
for (int i=start; i<=last; i++) {
listPanel.add(builder.apply(model.getElementAt(i)),"span");
listPanel.add(builder.apply(model.getElementAt(i)),"wrap");
}
}

Expand Down
18 changes: 15 additions & 3 deletions convex-gui/src/main/java/convex/gui/keys/KeyRingPanel.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package convex.gui.keys;

import java.awt.Color;
import java.util.concurrent.CompletableFuture;

import javax.swing.DefaultListModel;
import javax.swing.JButton;
Expand All @@ -15,9 +16,13 @@
import convex.core.crypto.AKeyPair;
import convex.core.crypto.wallet.AWalletEntry;
import convex.core.crypto.wallet.HotWalletEntry;
import convex.core.data.ACell;
import convex.core.data.AccountKey;
import convex.core.data.Address;
import convex.core.data.Blob;
import convex.core.lang.RT;
import convex.core.lang.Symbols;
import convex.core.lang.ops.Special;
import convex.gui.components.ActionPanel;
import convex.gui.components.ScrollyList;
import convex.gui.components.Toast;
Expand Down Expand Up @@ -105,8 +110,15 @@ public static DefaultListModel<AWalletEntry> getListModel() {
public static AWalletEntry findWalletEntry(Convex convex) {
Address a=convex.getAddress();
if (a==null) return null;
AccountKey key=convex.getAccountKey(a);
AWalletEntry we=Toolkit.getKeyRingEntry(key);
return we;
AccountKey key;
try {
CompletableFuture<ACell> cf=convex.query(Special.forSymbol(Symbols.STAR_KEY)).thenApply(r->r.getValue());
key = RT.ensureAccountKey(cf.get());
AWalletEntry we=Toolkit.getKeyRingEntry(key);
return we;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public TokenComponent(Convex convex, TokenInfo token) {
add(symLabel);

balanceLabel = new BalanceLabel();
balanceLabel.setFont(Toolkit.MONO_FONT);
balanceLabel.setDecimals(token.getDecimals());
balanceLabel.setFont(Toolkit.MONO_FONT);
balanceLabel.setBalance(0);
balanceLabel.setToolTipText("Account balance for "+symbolName);
add(balanceLabel,"align right");
Expand Down
4 changes: 4 additions & 0 deletions convex-gui/src/main/java/convex/gui/wallet/TokenInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,8 @@ public static TokenInfo getMulti(Convex convex, String key) {
}
return null;
}

public int getDecimals() {
return decimals;
}
}
8 changes: 4 additions & 4 deletions convex-gui/src/main/java/convex/gui/wallet/WalletPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public WalletPanel(Convex convex) {

// add(new AccountChooserPanel(convex),"dock south");
ActionPanel ap=new ActionPanel();
ap.add(new ActionButton("Track Token",0xe145,e->{
ap.add(ActionButton.build("Track Token",0xe145,e->{
String newID=JOptionPane.showInputDialog(WalletPanel.this, "Enter Token ID");
if (newID==null) return;
try {
Expand All @@ -59,10 +59,10 @@ public WalletPanel(Convex convex) {
} catch (Exception ex) {
Toast.display(WalletPanel.this, "Error adding token: "+ex.getMessage(),Color.ORANGE);
}
}));
ap.add(new ActionButton("Refresh",0xe5d5,e->{
},"Add a token to the tracked token list"));
ap.add(ActionButton.build("Refresh",0xe5d5,e->{
list.refreshList();
}));
},"Refresh token details and balances"));
add(ap,"dock south");

ThreadUtils.runVirtual(this::updateLoop);
Expand Down
4 changes: 2 additions & 2 deletions convex-peer/src/main/java/convex/api/Convex.java
Original file line number Diff line number Diff line change
Expand Up @@ -851,8 +851,8 @@ public Result querySync(ACell query, Address address, long timeoutMillis) throws
result = cf.get(timeoutMillis, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
throw Utils.sneakyThrow(e);
} catch (Exception e) {
return Result.fromException(e);
} catch (ExecutionException e) {
return Result.fromException(e.getCause());
} finally {
cf.cancel(true);
}
Expand Down

0 comments on commit 4edc715

Please sign in to comment.