@@ -64,11 +64,15 @@ public SwapPanel(Convex convex, TokenInfo token1, TokenInfo token2) {
64
64
// Main action buttons
65
65
ActionPanel actionPanel =new ActionPanel ();
66
66
actionPanel .add (new ActionButton ("Trade!" ,0xe933 ,e ->{
67
+ executeTrade ();
67
68
super .closeGUI ();
68
69
}));
69
70
actionPanel .add (new ActionButton ("Close" ,0xe5c9 ,e ->{
70
71
super .closeGUI ();
71
72
}));
73
+ actionPanel .add (new ActionButton ("Refresh" ,0xe5d5 ,e ->{
74
+ refreshRates ();
75
+ }));
72
76
add (actionPanel ,"dock south" );
73
77
}
74
78
@@ -138,6 +142,35 @@ protected void refreshRates() {
138
142
e .printStackTrace ();
139
143
}
140
144
}
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
+ }
141
174
142
175
public static void main (String [] args ) throws InterruptedException , IOException , TimeoutException {
143
176
// call to set up Look and Feel
0 commit comments