Skip to content

Commit 975c766

Browse files
committed
GUI updates to execute Torus swaps
1 parent 57a5844 commit 975c766

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,15 @@ public SwapPanel(Convex convex, TokenInfo token1, TokenInfo token2) {
6464
// Main action buttons
6565
ActionPanel actionPanel=new ActionPanel();
6666
actionPanel.add(new ActionButton("Trade!",0xe933,e->{
67+
executeTrade();
6768
super.closeGUI();
6869
}));
6970
actionPanel.add(new ActionButton("Close",0xe5c9,e->{
7071
super.closeGUI();
7172
}));
73+
actionPanel.add(new ActionButton("Refresh",0xe5d5,e->{
74+
refreshRates();
75+
}));
7276
add(actionPanel,"dock south");
7377
}
7478

@@ -138,6 +142,35 @@ protected void refreshRates() {
138142
e.printStackTrace();
139143
}
140144
}
145+
146+
protected void executeTrade() {
147+
ACell torus=TokenInfo.getTorusAddress(convex);
148+
receiveLabel.setDecimals(token2.getDecimals());
149+
AInteger amount=amountField.getAmount();
150+
String qs;
151+
if (token1.isConvex()) {
152+
System.err.println(amount +" :dec "+token1.getDecimals());
153+
qs="("+torus+"/sell-cvx "+token2.getID()+" "+amount+")";
154+
} else if (token2.isConvex()) {
155+
qs="("+torus+"/sell-tokens "+token1.getID()+" "+amount+")";
156+
} else {
157+
qs="("+torus+"/sell "+token1.getID()+" "+amount+" "+token2.getID()+")";
158+
}
159+
System.out.println(qs);
160+
try {
161+
convex.transact(qs).thenAccept(r->{
162+
ACell val=r.getValue();
163+
System.out.println(r);
164+
if (val instanceof AInteger) {
165+
receiveLabel.setBalance((AInteger) val);
166+
} else {
167+
receiveLabel.setBalance(null);
168+
}
169+
});
170+
} catch (IOException | TimeoutException e) {
171+
e.printStackTrace();
172+
}
173+
}
141174

142175
public static void main(String[] args) throws InterruptedException, IOException, TimeoutException {
143176
// call to set up Look and Feel

0 commit comments

Comments
 (0)