1
1
import { WalletConnectModal } from "@walletconnect/modal" ;
2
2
import { useEffect , useState , useCallback } from "react" ;
3
3
import { SAMPLES , SAMPLE_KINDS } from "./utils/samples" ;
4
- import TezosProvider , { TezosChainDataMainnet , TezosChainDataTestnet } from "@walletconnect/tezos-provider" ;
4
+ import TezosProvider , {
5
+ TezosChainDataMainnet ,
6
+ TezosChainDataTestnet ,
7
+ } from "@walletconnect/tezos-provider" ;
5
8
6
9
const projectId = import . meta. env . VITE_PROJECT_ID ;
7
10
@@ -13,7 +16,9 @@ const App = () => {
13
16
const [ lastKind , setLastKind ] = useState < SAMPLE_KINDS | null > ( null ) ;
14
17
const [ result , setResult ] = useState < any > ( null ) ;
15
18
const [ description , setDescription ] = useState < any > ( null ) ;
16
- const [ contractAddress , setContractAddress ] = useState ( "[click Origination to get contract address]" ) ;
19
+ const [ contractAddress , setContractAddress ] = useState (
20
+ "[click Origination to get contract address]" ,
21
+ ) ;
17
22
const [ balance , setBalance ] = useState ( "" ) ;
18
23
19
24
// Initialize WalletConnect Modal and TezosProvider
@@ -36,28 +41,43 @@ const App = () => {
36
41
await modal . openModal ( { uri } ) ;
37
42
} ) ;
38
43
39
- signer ?. on ( "session_ping" , ( { id, topic } : { id : string ; topic : string } ) =>
40
- console . log ( "Session Ping:" , id , topic ) ) ;
41
- signer ?. on ( "session_event" , ( { event, chainId } : { event : any ; chainId : string } ) =>
42
- console . log ( "Session Event:" , event , chainId ) ) ;
43
- signer ?. on ( "session_update" , ( { event, chainId } : { event : any ; chainId : string } ) =>
44
- console . log ( "Session Update:" , event , chainId ) ) ;
44
+ signer ?. on (
45
+ "session_ping" ,
46
+ ( { id, topic } : { id : string ; topic : string } ) =>
47
+ console . log ( "Session Ping:" , id , topic ) ,
48
+ ) ;
49
+ signer ?. on (
50
+ "session_event" ,
51
+ ( { event, chainId } : { event : any ; chainId : string } ) =>
52
+ console . log ( "Session Event:" , event , chainId ) ,
53
+ ) ;
54
+ signer ?. on (
55
+ "session_update" ,
56
+ ( { event, chainId } : { event : any ; chainId : string } ) =>
57
+ console . log ( "Session Update:" , event , chainId ) ,
58
+ ) ;
45
59
46
- signer ?. on ( "session_delete" , ( { id, topic } : { id : string ; topic : string } ) => {
47
- console . log ( "Session Delete:" , id , topic ) ;
48
- setIsConnected ( false ) ;
49
- setProvider ( null ) ;
50
- } ) ;
60
+ signer ?. on (
61
+ "session_delete" ,
62
+ ( { id, topic } : { id : string ; topic : string } ) => {
63
+ console . log ( "Session Delete:" , id , topic ) ;
64
+ setIsConnected ( false ) ;
65
+ setProvider ( null ) ;
66
+ } ,
67
+ ) ;
51
68
52
69
signer ?. on ( "connect" , ( { id, topic } : { id : string ; topic : string } ) => {
53
70
console . log ( "Connected:" , id , topic ) ;
54
71
setIsConnected ( true ) ;
55
72
} ) ;
56
73
57
- signer ?. on ( "disconnect" , ( { id, topic } : { id : string ; topic : string } ) => {
58
- console . log ( "Disconnected:" , id , topic ) ;
59
- setIsConnected ( false ) ;
60
- } ) ;
74
+ signer ?. on (
75
+ "disconnect" ,
76
+ ( { id, topic } : { id : string ; topic : string } ) => {
77
+ console . log ( "Disconnected:" , id , topic ) ;
78
+ setIsConnected ( false ) ;
79
+ } ,
80
+ ) ;
61
81
} ;
62
82
initProvider ( ) ;
63
83
} , [ ] ) ;
@@ -67,7 +87,9 @@ const App = () => {
67
87
if ( ! provider ) return ;
68
88
69
89
try {
70
- await provider . connect ( { chains : [ TezosChainDataTestnet , TezosChainDataMainnet ] } ) ;
90
+ await provider . connect ( {
91
+ chains : [ TezosChainDataTestnet , TezosChainDataMainnet ] ,
92
+ } ) ;
71
93
setIsConnected ( true ) ;
72
94
console . log ( "Connected to Tezos" ) ;
73
95
const balance = await provider . getBalance ( ) ;
@@ -109,21 +131,32 @@ const App = () => {
109
131
res = await provider . tezosSign ( "05010000004254" ) ;
110
132
break ;
111
133
case SAMPLE_KINDS . SEND_TRANSACTION :
112
- res = await provider . tezosSendTransaction ( SAMPLES [ SAMPLE_KINDS . SEND_TRANSACTION ] ) ;
134
+ res = await provider . tezosSendTransaction (
135
+ SAMPLES [ SAMPLE_KINDS . SEND_TRANSACTION ] ,
136
+ ) ;
113
137
break ;
114
138
case SAMPLE_KINDS . SEND_DELEGATION :
115
- res = await provider . tezosSendDelegation ( SAMPLES [ SAMPLE_KINDS . SEND_DELEGATION ] ) ;
139
+ res = await provider . tezosSendDelegation (
140
+ SAMPLES [ SAMPLE_KINDS . SEND_DELEGATION ] ,
141
+ ) ;
116
142
break ;
117
143
case SAMPLE_KINDS . SEND_UNDELEGATION :
118
144
res = await provider . tezosSendUndelegation ( ) ;
119
145
break ;
120
146
case SAMPLE_KINDS . SEND_ORGINATION :
121
- res = await provider . tezosSendOrigination ( SAMPLES [ SAMPLE_KINDS . SEND_ORGINATION ] ) ;
147
+ res = await provider . tezosSendOrigination (
148
+ SAMPLES [ SAMPLE_KINDS . SEND_ORGINATION ] ,
149
+ ) ;
122
150
for ( let attempt = 0 ; attempt < 5 ; attempt ++ ) {
123
- const contractAddressList = await provider . getContractAddress ( res . hash ) ;
151
+ const contractAddressList = await provider . getContractAddress (
152
+ res . hash ,
153
+ ) ;
124
154
if ( contractAddressList . length > 0 ) {
125
155
setContractAddress ( contractAddressList [ 0 ] ) ;
126
- console . log ( "TezosRpc stored contract:" , contractAddressList [ 0 ] ) ;
156
+ console . log (
157
+ "TezosRpc stored contract:" ,
158
+ contractAddressList [ 0 ] ,
159
+ ) ;
127
160
break ;
128
161
}
129
162
console . log ( "Waiting for contract address..." ) ;
@@ -141,13 +174,19 @@ const App = () => {
141
174
} ) ;
142
175
break ;
143
176
case SAMPLE_KINDS . SEND_STAKE :
144
- res = await provider . tezosSendStake ( SAMPLES [ SAMPLE_KINDS . SEND_STAKE ] ) ;
177
+ res = await provider . tezosSendStake (
178
+ SAMPLES [ SAMPLE_KINDS . SEND_STAKE ] ,
179
+ ) ;
145
180
break ;
146
181
case SAMPLE_KINDS . SEND_UNSTAKE :
147
- res = await provider . tezosSendUnstake ( SAMPLES [ SAMPLE_KINDS . SEND_UNSTAKE ] ) ;
182
+ res = await provider . tezosSendUnstake (
183
+ SAMPLES [ SAMPLE_KINDS . SEND_UNSTAKE ] ,
184
+ ) ;
148
185
break ;
149
186
case SAMPLE_KINDS . SEND_FINALIZE :
150
- res = await provider . tezosSendFinalizeUnstake ( SAMPLES [ SAMPLE_KINDS . SEND_FINALIZE ] ) ;
187
+ res = await provider . tezosSendFinalizeUnstake (
188
+ SAMPLES [ SAMPLE_KINDS . SEND_FINALIZE ] ,
189
+ ) ;
151
190
break ;
152
191
case SAMPLE_KINDS . SEND_INCREASE_PAID_STORAGE :
153
192
res = await provider . tezosSendIncreasePaidStorage ( {
@@ -171,7 +210,7 @@ const App = () => {
171
210
}
172
211
}
173
212
} ,
174
- [ provider , contractAddress ]
213
+ [ provider , contractAddress ] ,
175
214
) ;
176
215
177
216
// Provide operation descriptions
@@ -200,7 +239,7 @@ const App = () => {
200
239
setDescription ( "No description available" ) ;
201
240
}
202
241
} ,
203
- [ contractAddress , provider ?. address ]
242
+ [ contractAddress , provider ?. address ] ,
204
243
) ;
205
244
206
245
const describeClear = useCallback ( ( ) => {
@@ -211,29 +250,98 @@ const App = () => {
211
250
< div className = "App" >
212
251
< h1 > TezosProvider</ h1 >
213
252
< h2 > WalletConnect for Tezos</ h2 >
214
- { ( ! projectId || projectId === "YOUR_PROJECT_ID" ) ? (
253
+ { ! projectId || projectId === "YOUR_PROJECT_ID" ? (
215
254
< div className = "warning" >
216
- < p > < b > The project is not initialized</ b > </ p >
255
+ < p >
256
+ < b > The project is not initialized</ b >
257
+ </ p >
217
258
< p > Set your project ID in the .env file</ p >
218
259
</ div >
219
260
) : isConnected ? (
220
261
< >
221
- < p > < b > Public Key: </ b > { provider ?. address ?? "No account connected" } </ p >
222
- < p > < b > Balance: </ b > { balance } </ p >
262
+ < p >
263
+ < b > Public Key: </ b >
264
+ { provider ?. address ?? "No account connected" }
265
+ </ p >
266
+ < p >
267
+ < b > Balance: </ b >
268
+ { balance }
269
+ </ p >
223
270
< div className = "layout-container" >
224
271
< div className = "btn-container" >
225
- < button onClick = { disconnect } onMouseEnter = { describeClear } > Disconnect</ button >
226
- < button onClick = { ( ) => handleOp ( SAMPLE_KINDS . GET_ACCOUNTS ) } onMouseEnter = { describeClear } > Get Accounts</ button >
227
- < button onClick = { ( ) => handleOp ( SAMPLE_KINDS . SIGN ) } onMouseEnter = { describeClear } > Sign</ button >
228
- < button onClick = { ( ) => handleOp ( SAMPLE_KINDS . SEND_TRANSACTION ) } onMouseEnter = { ( ) => describe ( SAMPLE_KINDS . SEND_TRANSACTION ) } > Send Transaction</ button >
229
- < button onClick = { ( ) => handleOp ( SAMPLE_KINDS . SEND_DELEGATION ) } onMouseEnter = { ( ) => describe ( SAMPLE_KINDS . SEND_DELEGATION ) } > Delegate</ button >
230
- < button onClick = { ( ) => handleOp ( SAMPLE_KINDS . SEND_UNDELEGATION ) } onMouseEnter = { ( ) => describe ( SAMPLE_KINDS . SEND_UNDELEGATION ) } > Undelegate</ button >
231
- < button onClick = { ( ) => handleOp ( SAMPLE_KINDS . SEND_ORGINATION ) } onMouseEnter = { ( ) => describe ( SAMPLE_KINDS . SEND_ORGINATION ) } > Originate</ button >
232
- < button onClick = { ( ) => handleOp ( SAMPLE_KINDS . SEND_CONTRACT_CALL ) } onMouseEnter = { ( ) => describe ( SAMPLE_KINDS . SEND_CONTRACT_CALL ) } > Contract call</ button >
233
- < button onClick = { ( ) => handleOp ( SAMPLE_KINDS . SEND_STAKE ) } onMouseEnter = { ( ) => describe ( SAMPLE_KINDS . SEND_STAKE ) } > Stake</ button >
234
- < button onClick = { ( ) => handleOp ( SAMPLE_KINDS . SEND_UNSTAKE ) } onMouseEnter = { ( ) => describe ( SAMPLE_KINDS . SEND_UNSTAKE ) } > Unstake</ button >
235
- < button onClick = { ( ) => handleOp ( SAMPLE_KINDS . SEND_FINALIZE ) } onMouseEnter = { ( ) => describe ( SAMPLE_KINDS . SEND_FINALIZE ) } > Finalize</ button >
236
- < button onClick = { ( ) => handleOp ( SAMPLE_KINDS . SEND_INCREASE_PAID_STORAGE ) } onMouseEnter = { ( ) => describe ( SAMPLE_KINDS . SEND_INCREASE_PAID_STORAGE ) } > Increase paid storage</ button >
272
+ < button onClick = { disconnect } onMouseEnter = { describeClear } >
273
+ Disconnect
274
+ </ button >
275
+ < button
276
+ onClick = { ( ) => handleOp ( SAMPLE_KINDS . GET_ACCOUNTS ) }
277
+ onMouseEnter = { describeClear }
278
+ >
279
+ Get Accounts
280
+ </ button >
281
+ < button
282
+ onClick = { ( ) => handleOp ( SAMPLE_KINDS . SIGN ) }
283
+ onMouseEnter = { describeClear }
284
+ >
285
+ Sign
286
+ </ button >
287
+ < button
288
+ onClick = { ( ) => handleOp ( SAMPLE_KINDS . SEND_TRANSACTION ) }
289
+ onMouseEnter = { ( ) => describe ( SAMPLE_KINDS . SEND_TRANSACTION ) }
290
+ >
291
+ Send Transaction
292
+ </ button >
293
+ < button
294
+ onClick = { ( ) => handleOp ( SAMPLE_KINDS . SEND_DELEGATION ) }
295
+ onMouseEnter = { ( ) => describe ( SAMPLE_KINDS . SEND_DELEGATION ) }
296
+ >
297
+ Delegate
298
+ </ button >
299
+ < button
300
+ onClick = { ( ) => handleOp ( SAMPLE_KINDS . SEND_UNDELEGATION ) }
301
+ onMouseEnter = { ( ) => describe ( SAMPLE_KINDS . SEND_UNDELEGATION ) }
302
+ >
303
+ Undelegate
304
+ </ button >
305
+ < button
306
+ onClick = { ( ) => handleOp ( SAMPLE_KINDS . SEND_ORGINATION ) }
307
+ onMouseEnter = { ( ) => describe ( SAMPLE_KINDS . SEND_ORGINATION ) }
308
+ >
309
+ Originate
310
+ </ button >
311
+ < button
312
+ onClick = { ( ) => handleOp ( SAMPLE_KINDS . SEND_CONTRACT_CALL ) }
313
+ onMouseEnter = { ( ) => describe ( SAMPLE_KINDS . SEND_CONTRACT_CALL ) }
314
+ >
315
+ Contract call
316
+ </ button >
317
+ < button
318
+ onClick = { ( ) => handleOp ( SAMPLE_KINDS . SEND_STAKE ) }
319
+ onMouseEnter = { ( ) => describe ( SAMPLE_KINDS . SEND_STAKE ) }
320
+ >
321
+ Stake
322
+ </ button >
323
+ < button
324
+ onClick = { ( ) => handleOp ( SAMPLE_KINDS . SEND_UNSTAKE ) }
325
+ onMouseEnter = { ( ) => describe ( SAMPLE_KINDS . SEND_UNSTAKE ) }
326
+ >
327
+ Unstake
328
+ </ button >
329
+ < button
330
+ onClick = { ( ) => handleOp ( SAMPLE_KINDS . SEND_FINALIZE ) }
331
+ onMouseEnter = { ( ) => describe ( SAMPLE_KINDS . SEND_FINALIZE ) }
332
+ >
333
+ Finalize
334
+ </ button >
335
+ < button
336
+ onClick = { ( ) =>
337
+ handleOp ( SAMPLE_KINDS . SEND_INCREASE_PAID_STORAGE )
338
+ }
339
+ onMouseEnter = { ( ) =>
340
+ describe ( SAMPLE_KINDS . SEND_INCREASE_PAID_STORAGE )
341
+ }
342
+ >
343
+ Increase paid storage
344
+ </ button >
237
345
</ div >
238
346
< div className = "result-column" >
239
347
{ result && (
0 commit comments