Skip to content

Commit 4edc715

Browse files
committed
GUI updates working towards Torus swaps in wallet
1 parent 779adb8 commit 4edc715

File tree

9 files changed

+35
-15
lines changed

9 files changed

+35
-15
lines changed

convex-core/src/main/java/convex/core/init/Init.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ private static State doCurrencyDeploy(State s, AVector<ACell> row) {
379379
double cvx = cvxPrice * supply / subDivisions;
380380

381381

382-
Context ctx = Context.createFake(s, DISTRIBUTION_ADDRESS);
382+
Context ctx = Context.createFake(s, GENESIS_ADDRESS);
383383
ctx = ctx.eval(Reader
384384
.read("(do (import convex.fungible :as fun) (deploy (fun/build-token {:supply " + supply + " :decimals "+decimals+"})))"));
385385
Address addr = ctx.getResult();

convex-gui/src/main/java/convex/gui/components/BalanceLabel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public void setBalance(AInteger a) {
102102
append(chs,c,decimalSize);
103103
}
104104
for (int i=decimals; i<9; i++) {
105-
append(" ",balanceColour,decimalSize);
105+
append("\u2007",balanceColour,decimalSize);
106106
}
107107

108108
Toolkit.addPopupMenu(this, new BalanceMenu());

convex-gui/src/main/java/convex/gui/components/ConnectPanel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static Convex tryConnect(JComponent parent,String prompt) {
6767
try {
6868
String target=pan.hostField.getText();
6969
InetSocketAddress sa=Utils.toInetSocketAddress(target);
70-
System.err.println("Attempting connect to: "+sa);
70+
log.info("Attempting connect to: "+sa);
7171
Convex convex=Convex.connect(sa);
7272
convex.setAddress(pan.addressField.getAddress());
7373

convex-gui/src/main/java/convex/gui/components/ScrollyList.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public class ScrollyList<E> extends JScrollPane {
2727
private final ListModel<E> model;
2828
private final ScrollablePanel listPanel = new ScrollablePanel();
2929

30+
private final MigLayout listLayout;
31+
3032
public void refreshList() {
3133
EventQueue.invokeLater(()->{;
3234
listPanel.removeAll();
@@ -74,7 +76,8 @@ public ScrollyList(ListModel<E> model, Function<E, Component> builder) {
7476
this.model = model;
7577
// this.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
7678

77-
listPanel.setLayout(new MigLayout("wrap 1"));
79+
listLayout=new MigLayout("wrap");
80+
listPanel.setLayout(listLayout);
7881
setViewportView(listPanel);
7982
getViewport().setBackground(null);
8083

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

convex-gui/src/main/java/convex/gui/keys/KeyRingPanel.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package convex.gui.keys;
22

33
import java.awt.Color;
4+
import java.util.concurrent.CompletableFuture;
45

56
import javax.swing.DefaultListModel;
67
import javax.swing.JButton;
@@ -15,9 +16,13 @@
1516
import convex.core.crypto.AKeyPair;
1617
import convex.core.crypto.wallet.AWalletEntry;
1718
import convex.core.crypto.wallet.HotWalletEntry;
19+
import convex.core.data.ACell;
1820
import convex.core.data.AccountKey;
1921
import convex.core.data.Address;
2022
import convex.core.data.Blob;
23+
import convex.core.lang.RT;
24+
import convex.core.lang.Symbols;
25+
import convex.core.lang.ops.Special;
2126
import convex.gui.components.ActionPanel;
2227
import convex.gui.components.ScrollyList;
2328
import convex.gui.components.Toast;
@@ -105,8 +110,15 @@ public static DefaultListModel<AWalletEntry> getListModel() {
105110
public static AWalletEntry findWalletEntry(Convex convex) {
106111
Address a=convex.getAddress();
107112
if (a==null) return null;
108-
AccountKey key=convex.getAccountKey(a);
109-
AWalletEntry we=Toolkit.getKeyRingEntry(key);
110-
return we;
113+
AccountKey key;
114+
try {
115+
CompletableFuture<ACell> cf=convex.query(Special.forSymbol(Symbols.STAR_KEY)).thenApply(r->r.getValue());
116+
key = RT.ensureAccountKey(cf.get());
117+
AWalletEntry we=Toolkit.getKeyRingEntry(key);
118+
return we;
119+
} catch (Exception e) {
120+
e.printStackTrace();
121+
return null;
122+
}
111123
}
112124
}

convex-gui/src/main/java/convex/gui/wallet/TokenComponent.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public TokenComponent(Convex convex, TokenInfo token) {
4444
add(symLabel);
4545

4646
balanceLabel = new BalanceLabel();
47-
balanceLabel.setFont(Toolkit.MONO_FONT);
47+
balanceLabel.setDecimals(token.getDecimals());
48+
balanceLabel.setFont(Toolkit.MONO_FONT);
4849
balanceLabel.setBalance(0);
4950
balanceLabel.setToolTipText("Account balance for "+symbolName);
5051
add(balanceLabel,"align right");

convex-gui/src/main/java/convex/gui/wallet/TokenInfo.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,8 @@ public static TokenInfo getMulti(Convex convex, String key) {
157157
}
158158
return null;
159159
}
160+
161+
public int getDecimals() {
162+
return decimals;
163+
}
160164
}

convex-gui/src/main/java/convex/gui/wallet/WalletPanel.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public WalletPanel(Convex convex) {
4343

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

6868
ThreadUtils.runVirtual(this::updateLoop);

convex-peer/src/main/java/convex/api/Convex.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -851,8 +851,8 @@ public Result querySync(ACell query, Address address, long timeoutMillis) throws
851851
result = cf.get(timeoutMillis, TimeUnit.MILLISECONDS);
852852
} catch (InterruptedException e) {
853853
throw Utils.sneakyThrow(e);
854-
} catch (Exception e) {
855-
return Result.fromException(e);
854+
} catch (ExecutionException e) {
855+
return Result.fromException(e.getCause());
856856
} finally {
857857
cf.cancel(true);
858858
}

0 commit comments

Comments
 (0)