@@ -4,25 +4,10 @@ const buy: ModElement[] = [
44 {
55 type : "padding" ,
66 elements : [
7+ // If no buy amount, go back to #view
78 {
89 type : "horizontal-layout" ,
910 elements : [
10- {
11- type : "circular-progress" ,
12- } ,
13- {
14- type : "text" ,
15- label :
16- "Buying ~${{refs.buyAmountUsd}} of {{refs.tokenReq.response.data.name}}..." ,
17- variant : "secondary" ,
18- } ,
19- ] ,
20- } ,
21-
22- {
23- type : "horizontal-layout" ,
24- elements : [
25- // If there is no buyAmountUsd value, go to #view
2611 {
2712 if : {
2813 value : "{{refs.buyAmountUsd}}" ,
@@ -31,12 +16,40 @@ const buy: ModElement[] = [
3116 } ,
3217 } ,
3318 then : {
34- type : "horizontal -layout" ,
19+ type : "vertical -layout" ,
3520 onload : "#view" ,
3621 } ,
3722 } ,
3823 ] ,
3924 } ,
25+ //
26+ {
27+ if : [
28+ {
29+ value : "{{refs.swapTx.isSuccess}}" ,
30+ match : {
31+ NOT : {
32+ equals : "true" ,
33+ } ,
34+ } ,
35+ } ,
36+ ] ,
37+ then : {
38+ type : "horizontal-layout" ,
39+ elements : [
40+ {
41+ type : "circular-progress" ,
42+ } ,
43+ {
44+ type : "text" ,
45+ label :
46+ "Buying ~${{refs.buyAmountUsd}} of {{refs.tokenReq.response.data.name}}..." ,
47+ variant : "secondary" ,
48+ } ,
49+ ] ,
50+ } ,
51+ } ,
52+
4053 {
4154 type : "vertical-layout" ,
4255 onload : {
@@ -45,7 +58,7 @@ const buy: ModElement[] = [
4558 ref : "swapTxDataReq" ,
4659 onsuccess : {
4760 type : "SENDETHTRANSACTION" ,
48- ref : "swapTxReq " ,
61+ ref : "swapTx " ,
4962 txData : {
5063 from : "{{refs.swapTxDataReq.response.data.transaction.from}}" ,
5164 to : "{{refs.swapTxDataReq.response.data.transaction.to}}" ,
@@ -55,14 +68,86 @@ const buy: ModElement[] = [
5568 chainId : "{{refs.balancesReq.response.data.chain.id}}" ,
5669 onerror : {
5770 type : "SETSTATE" ,
58- ref : "buyAmountUsd" ,
59- value : "" ,
71+ state : {
72+ buyAmountUsd : "" ,
73+ } ,
6074 } ,
6175 } ,
6276 onerror : {
6377 type : "SETSTATE" ,
64- ref : "buyAmountUsd" ,
65- value : "" ,
78+ state : {
79+ buyAmountUsd : "" ,
80+ } ,
81+ } ,
82+ } ,
83+ } ,
84+ {
85+ if : {
86+ value : "{{refs.swapTx.hash}}" ,
87+ match : {
88+ NOT : {
89+ equals : "" ,
90+ } ,
91+ } ,
92+ } ,
93+ then : {
94+ if : {
95+ value : "{{refs.swapTx.isSuccess}}" ,
96+ match : {
97+ equals : "true" ,
98+ } ,
99+ } ,
100+ then : {
101+ type : "horizontal-layout" ,
102+ elements : [
103+ {
104+ type : "button" ,
105+ label : "Back" ,
106+ variant : "secondary" ,
107+ onclick : {
108+ type : "SETSTATE" ,
109+ state : {
110+ isBuying : "false" ,
111+ buyAmountUsd : "" ,
112+ } ,
113+ } ,
114+ } ,
115+ {
116+ type : "text" ,
117+ label : "Transaction successful" ,
118+ variant : "secondary" ,
119+ } ,
120+ {
121+ type : "link" ,
122+ label : "Explorer" ,
123+ url : "{{refs.swapTxDataReq.response.data.explorer.url}}/tx/{{refs.swapTx.hash}}" ,
124+ } ,
125+ ] ,
126+ } ,
127+ else : {
128+ if : {
129+ value : "{{refs.swapTx.isSuccess}}" ,
130+ match : {
131+ equals : "false" ,
132+ } ,
133+ } ,
134+ then : {
135+ type : "link" ,
136+ label : "Failed" ,
137+ variant : "link" ,
138+ url : "{{refs.swapTxDataReq.response.data.explorer.url}}/tx/{{refs.swapTx.hash}}" ,
139+ } ,
140+ else : {
141+ type : "horizontal-layout" ,
142+ elements : [
143+ {
144+ type : "link" ,
145+ label : "Confirming..." ,
146+ variant : "link" ,
147+ url : "{{refs.swapTxDataReq.response.data.explorer.url}}/tx/{{refs.swapTx.hash}}" ,
148+ } ,
149+ ] ,
150+ } ,
66151 } ,
67152 } ,
68153 } ,
0 commit comments