1
1
import { WalletConnectModal } from "@walletconnect/modal" ;
2
2
import { useEffect , useState , useCallback } from "react" ;
3
- import { SAMPLES , SAMPLE_KINDS } from "./utils/samples" ;
3
+ import { SAMPLES , SAMPLE_KINDS , getBakerAddress } from "./utils/samples" ;
4
4
import {
5
5
TezosProvider ,
6
6
TezosChainDataTestnet ,
7
7
TezosGetAccountResponse ,
8
8
TezosSendResponse ,
9
9
TezosSignResponse ,
10
- ChainData ,
11
10
TezosChainDataMainnet ,
12
11
} from "@trili/tezos-provider" ;
13
12
import { ErrorObject } from "@walletconnect/utils" ;
@@ -123,7 +122,8 @@ const App = () => {
123
122
} catch ( error ) {
124
123
console . error ( "Error connecting to Tezos:" , error ) ;
125
124
}
126
- } , [ provider ] ,
125
+ } ,
126
+ [ provider ] ,
127
127
) ;
128
128
129
129
// Disconnect from Tezos
@@ -156,9 +156,12 @@ const App = () => {
156
156
break ;
157
157
case SAMPLE_KINDS . SIGN : {
158
158
const formattedInput = ` Payload from TezosProvider dapp generated at ${ new Date ( ) . toISOString ( ) } ` ;
159
+ // build payload following https://taquito.io/docs/signing/#generating-a-signature-with-beacon-sdk
159
160
const bytes = stringToBytes ( formattedInput ) ;
160
- const payload =
161
- "05" + "0100" + stringToBytes ( bytes . length . toString ( ) ) + bytes ;
161
+ const bytesLength = ( bytes . length / 2 ) . toString ( 16 ) ;
162
+ const addPadding = `00000000${ bytesLength } ` ;
163
+ const paddedBytesLength = addPadding . slice ( - 8 ) ;
164
+ const payload = "05" + "01" + paddedBytesLength + bytes ;
162
165
res = await provider . sign ( payload ) ;
163
166
break ;
164
167
}
@@ -168,9 +171,10 @@ const App = () => {
168
171
) ;
169
172
break ;
170
173
case SAMPLE_KINDS . SEND_DELEGATION :
171
- res = await provider . sendDelegation (
172
- SAMPLES [ SAMPLE_KINDS . SEND_DELEGATION ] ,
173
- ) ;
174
+ res = await provider . sendDelegation ( {
175
+ ...SAMPLES [ SAMPLE_KINDS . SEND_DELEGATION ] ,
176
+ delegate : getBakerAddress ( provider ?. getChainId ( ) ) ,
177
+ } ) ;
174
178
break ;
175
179
case SAMPLE_KINDS . SEND_UNDELEGATION :
176
180
res = await provider . sendUndelegation ( ) ;
@@ -248,10 +252,16 @@ const App = () => {
248
252
( kind : SAMPLE_KINDS ) => {
249
253
switch ( kind ) {
250
254
case SAMPLE_KINDS . SEND_TRANSACTION :
251
- case SAMPLE_KINDS . SEND_DELEGATION :
252
255
case SAMPLE_KINDS . SEND_UNDELEGATION :
253
256
setDescription ( SAMPLES [ kind ] ) ;
254
257
break ;
258
+ case SAMPLE_KINDS . SEND_DELEGATION :
259
+ // provider address depends on the chain
260
+ setDescription ( {
261
+ ...SAMPLES [ kind ] ,
262
+ delegate : getBakerAddress ( provider ?. getChainId ( ) ) ,
263
+ } ) ;
264
+ break ;
255
265
case SAMPLE_KINDS . SEND_ORGINATION :
256
266
setDescription ( SAMPLES [ kind ] as unknown as Record < string , unknown > ) ;
257
267
break ;
@@ -298,6 +308,10 @@ const App = () => {
298
308
< b > Public Key: </ b >
299
309
{ provider ?. connection ?. address ?? "No account connected" }
300
310
</ p >
311
+ < p >
312
+ < b > Chain: </ b >
313
+ { provider ?. getChainId ( ) ?? "No chain connected" }
314
+ </ p >
301
315
< p >
302
316
< b > Balance: </ b >
303
317
{ balance }
0 commit comments