11import { useSnapshot } from 'valtio' ;
22import { useCallback , useEffect , useMemo , useState } from 'react' ;
3- import { View , StyleSheet , Image , Text , Alert } from 'react-native' ;
3+ import {
4+ View ,
5+ StyleSheet ,
6+ Image ,
7+ Text ,
8+ Alert ,
9+ NativeModules ,
10+ } from 'react-native' ;
411import { SignClientTypes } from '@walletconnect/types' ;
512import { ChainAbstractionTypes } from '@reown/walletkit' ;
613import {
@@ -22,12 +29,13 @@ import {isVerified} from '@/utils/HelperUtil';
2229import { VerifiedDomain } from '@/components/VerifiedDomain' ;
2330import { Loader } from '@/components/Loader' ;
2431import { ethers } from 'ethers' ;
32+ import { TransactionType } from '@/utils/TypesUtil' ;
2533
2634export default function SessionSendTransactionModal ( ) {
2735 const { data} = useSnapshot ( ModalStore . state ) ;
2836 const [ payingAmount , setPayingAmount ] = useState ( '' ) ;
2937 const [ bridgingTransactions , setBridgingTransactions ] =
30- useState < ChainAbstractionTypes . Transaction [ ] > ( ) ;
38+ useState < TransactionType [ ] > ( ) ;
3139 const [ fundingFrom , setFundingFrom ] =
3240 useState <
3341 { symbol : string ; chainId : string ; amount : string ; tokenContract : string } [ ]
@@ -49,7 +57,9 @@ export default function SessionSendTransactionModal() {
4957 const params = requestEvent ?. params ;
5058 const chainId = params ?. chainId as string ;
5159 const request = params ?. request ;
52- const [ transaction , setTransaction ] = useState < any > ( request ?. params [ 0 ] ) ;
60+ const [ transaction , setTransaction ] = useState < TransactionType > (
61+ request ?. params [ 0 ] ,
62+ ) ;
5363 const isLinkMode = session ?. transportType === 'link_mode' ;
5464 const peerMetadata = session ?. peer ?. metadata as SignClientTypes . Metadata ;
5565
@@ -70,7 +80,7 @@ export default function SessionSendTransactionModal() {
7080
7181 useEffect ( ( ) => {
7282 const value = transaction . value ;
73- if ( value > 0 ) {
83+ if ( value ) {
7484 setPayingAmount ( `${ value } ETH` ) ;
7585 return ;
7686 }
@@ -104,6 +114,7 @@ export default function SessionSendTransactionModal() {
104114 from : transaction . from ,
105115 to : transaction . to ,
106116 data : transaction . data ,
117+ chainId : chainId ,
107118 nonce : await getNonce ( transaction . from , chainId ) ,
108119 value : transaction . value || '0' ,
109120 maxFeePerGas : fees . maxFeePerGas ,
@@ -121,68 +132,78 @@ export default function SessionSendTransactionModal() {
121132 }
122133 setFetchingRoutes ( true ) ;
123134 setFetchingGas ( true ) ;
124- console . log ( 'fetching routes...' ) ;
125- const result = await walletKit . canFulfil ( {
126- transaction : {
127- from : transaction . from ,
128- to : transaction . to ,
129- data : transaction . data ,
130- nonce : '1' ,
131- gas : '0' ,
132- gasPrice : '0' ,
133- value : '0' ,
134- maxFeePerGas : '0' ,
135- maxPriorityFeePerGas : '0' ,
136- chainId : chainId ,
137- } ,
138- } ) ;
139- console . log ( 'routes done' ) ;
140- if ( result . status === 'error' ) {
141- setRoutingStatus ( `Error: ${ result . reason } ` ) ;
142- setHasError ( true ) ;
143- } else if ( result . status === 'available' ) {
144- const data = result . data ;
145- const routes = data . routes ;
135+ try {
136+ console . log ( 'fetching routes...' ) ;
137+ const result = await walletKit . prepareFulfilment ( {
138+ transaction : {
139+ from : transaction . from ,
140+ to : transaction . to ,
141+ data : transaction . data ,
142+ chainId : chainId ,
143+ } ,
144+ } ) ;
145+ console . log ( 'routes done' ) ;
146+ if ( result . status === 'error' ) {
147+ setRoutingStatus ( `Error: ${ result . reason } ` ) ;
148+ setHasError ( true ) ;
149+ } else if ( result . status === 'available' ) {
150+ console . log ( 'checking details --------' ) ;
146151
147- console . log ( 'ui fields' , JSON . stringify ( data . routesDetails , null , 2 ) ) ;
148- const uiFields = data . routesDetails ;
152+ const details = await walletKit . getFulfilmentDetails ( {
153+ fulfilmentId : result . data . fulfilmentId ,
154+ } ) ;
149155
150- const transactions : any [ ] = [ ] ;
151- for ( const tx of routes . transactions ) {
152- const txData = {
153- ...tx ,
154- gasLimit : tx . gas ,
155- ...( await calculateEip155Gas ( tx , tx . chainId ) ) ,
156- } ;
157- delete txData . gas ;
158- delete txData . gasPrice ;
159- transactions . push ( txData ) ;
160- }
156+ console . log ( 'details --------' , JSON . stringify ( details , null , 2 ) ) ;
161157
162- console . log ( 'bridging txs' , JSON . stringify ( transactions , null , 2 ) ) ;
158+ const transactions : any [ ] = [ ] ;
163159
164- setNetworkFee (
165- `${ uiFields . totalFees . formattedAlt } ${ uiFields . totalFees . symbol } ` ,
166- ) ;
167- const txData = {
168- ...transaction ,
169- ...( await calculateEip155Gas ( transaction , chainId ) ) ,
170- } ;
171- delete txData . gas ;
172- delete txData . gasPrice ;
160+ const routes = result . data ;
161+ for ( const detail of details . routeDetails ) {
162+ const tx : TransactionType = {
163+ data : detail . transaction . input ,
164+ from : detail . transaction . from ,
165+ to : detail . transaction . to ,
166+ nonce : detail . transaction . nonce ,
167+ value : detail . transaction . value ,
168+ gasLimit : detail . transaction . gasLimit ,
169+ maxFeePerGas : detail . transaction . maxFeePerGas ,
170+ maxPriorityFeePerGas : detail . transaction . maxPriorityFeePerGas ,
171+ chainId : detail . transaction . chainId ,
172+ } ;
173+ transactions . push ( tx ) ;
174+ }
173175
174- setTransaction ( {
175- ...txData ,
176- nonce : await getNonce ( transaction . from , chainId ) ,
177- } ) ;
176+ setNetworkFee (
177+ `${ details . totalFee . formattedAlt } ${ details . totalFee . symbol } ` ,
178+ ) ;
178179
179- setBridgingTransactions ( transactions ) ;
180- setFundingFrom ( routes . funding ) ;
181- } else {
182- setRoutingStatus ( result . status ) ;
183- await calculateInitialTxFees ( ) ;
184- }
180+ const initialTransaction : TransactionType = {
181+ data : details . initialTransactionDetails . transaction . input ,
182+ from : details . initialTransactionDetails . transaction . from ,
183+ to : details . initialTransactionDetails . transaction . to ,
184+ nonce : details . initialTransactionDetails . transaction . nonce ,
185+ value : details . initialTransactionDetails . transaction . value ,
186+ gasLimit : details . initialTransactionDetails . transaction . gasLimit ,
187+ maxFeePerGas :
188+ details . initialTransactionDetails . transaction . maxFeePerGas ,
189+ maxPriorityFeePerGas :
190+ details . initialTransactionDetails . transaction . maxPriorityFeePerGas ,
191+ chainId : details . initialTransactionDetails . transaction . chainId ,
192+ } ;
185193
194+ setTransaction ( initialTransaction ) ;
195+ setBridgingTransactions ( transactions ) ;
196+ setFundingFrom ( routes . funding ) ;
197+ } else {
198+ setRoutingStatus ( result . status ) ;
199+ await calculateInitialTxFees ( ) ;
200+ }
201+ } catch ( e ) {
202+ console . log ( 'error' , e ) ;
203+ const error = e as Error ;
204+ setRoutingStatus ( error . message ) ;
205+ setHasError ( true ) ;
206+ }
186207 setFetchingRoutes ( false ) ;
187208 setFetchingGas ( false ) ;
188209 // eslint-disable-next-line react-hooks/exhaustive-deps
0 commit comments