@@ -90,19 +90,13 @@ export async function handleSignatureStepItem({
9090 }
9191
9292 try {
93- const getData = async function ( ) {
94- let response = await axios . request ( {
95- url : postOrderUrl . href ,
96- data : postData . body ? JSON . stringify ( postData . body ) : undefined ,
97- method : postData . method ,
98- params : request . params ,
99- headers
100- } )
101-
102- return response
103- }
104-
105- const res = await getData ( )
93+ const res = await axios . request ( {
94+ url : postOrderUrl . href ,
95+ data : postData . body ? JSON . stringify ( postData . body ) : undefined ,
96+ method : postData . method ,
97+ params : request . params ,
98+ headers
99+ } )
106100
107101 // Append new steps if returned in response
108102 if ( res . data && res . data . steps && Array . isArray ( res . data . steps ) ) {
@@ -150,15 +144,9 @@ export async function handleSignatureStepItem({
150144 // If check, poll check until validated
151145 if ( stepItem ?. check ) {
152146 stepItem . progressState = 'validating'
153- setState ( {
154- steps : [ ...json . steps ] ,
155- fees : { ...json ?. fees } ,
156- breakdown : json ?. breakdown ,
157- details : json ?. details
158- } )
159147 stepItem . isValidatingSignature = true
160148 setState ( {
161- steps : [ ...json ? .steps ] ,
149+ steps : [ ...json . steps ] ,
162150 fees : { ...json ?. fees } ,
163151 breakdown : json ?. breakdown ,
164152 details : json ?. details
@@ -193,60 +181,154 @@ export async function handleSignatureStepItem({
193181
194182 // Start polling for signature validation
195183 const pollWithCancellation = async ( ) => {
184+ // Helper to update state
185+ const updateState = ( ) => {
186+ setState ( {
187+ steps : [ ...json ?. steps ] ,
188+ fees : { ...json ?. fees } ,
189+ breakdown : json ?. breakdown ,
190+ details : json ?. details
191+ } )
192+ }
193+
194+ // Helper to extract and set origin txHashes
195+ const extractOriginTxHashes = (
196+ inTxHashesData : string [ ] ,
197+ originChainId ?: number
198+ ) => {
199+ const chainInTxHashes : NonNullable <
200+ Execute [ 'steps' ] [ 0 ] [ 'items' ]
201+ > [ 0 ] [ 'txHashes' ] = inTxHashesData . map ( ( hash : string ) => ( {
202+ txHash : hash ,
203+ chainId : originChainId ?? chain ?. id
204+ } ) )
205+ stepItem . internalTxHashes = chainInTxHashes
206+ }
207+
208+ // Helper to extract and set destination txHashes
209+ const extractDestinationTxHashes = (
210+ txHashesData : string [ ] ,
211+ destinationChainId ?: number
212+ ) => {
213+ const chainTxHashes : NonNullable <
214+ Execute [ 'steps' ] [ 0 ] [ 'items' ]
215+ > [ 0 ] [ 'txHashes' ] = txHashesData . map ( ( hash : string ) => ( {
216+ txHash : hash ,
217+ chainId : destinationChainId ?? chain ?. id
218+ } ) )
219+ stepItem . txHashes = chainTxHashes
220+ }
221+
196222 let attemptCount = 0
197223 while ( attemptCount < maximumAttempts ) {
198224 try {
225+ let endpoint = stepItem ?. check ?. endpoint || ''
226+
227+ // Override v2 status endpoint to v3 to get 'submitted' status
228+ if (
229+ endpoint . includes ( '/intents/status' ) &&
230+ ! endpoint . includes ( '/v3' )
231+ ) {
232+ endpoint = endpoint . replace ( '/intents/status' , '/intents/status/v3' )
233+ }
234+
199235 const res = await axios . request ( {
200- url : `${ request . baseURL } ${ stepItem ?. check ?. endpoint } ` ,
236+ url : `${ request . baseURL } ${ endpoint } ` ,
201237 method : stepItem ?. check ?. method ,
202- headers
238+ headers,
239+ validateStatus : ( status ) => status < 500 // Don't throw on 4xx responses
203240 } )
204241
205- client . log (
206- [ `Execute Steps: Polling execute status to check if indexed` , res ] ,
207- LogLevel . Verbose
208- )
209-
210242 // Check status
211- if ( res ?. data ?. status === 'success' && res ?. data ?. txHashes ) {
212- const chainTxHashes : NonNullable <
213- Execute [ 'steps' ] [ 0 ] [ 'items' ]
214- > [ 0 ] [ 'txHashes' ] = res . data ?. txHashes ?. map ( ( hash : string ) => {
215- return {
216- txHash : hash ,
217- chainId : res . data . destinationChainId ?? chain ?. id
218- }
219- } )
243+ if ( res ?. data ?. status === 'pending' ) {
244+ // Extract origin txHashes if provided
245+ if ( res ?. data ?. inTxHashes && res . data . inTxHashes . length > 0 ) {
246+ extractOriginTxHashes ( res . data . inTxHashes , res . data . originChainId )
247+ }
248+
249+ stepItem . checkStatus = 'pending'
250+ stepItem . progressState = undefined
251+ stepItem . isValidatingSignature = false
252+ updateState ( )
253+ client . log (
254+ [ 'Origin tx confirmed, backend processing' ] ,
255+ LogLevel . Verbose
256+ )
257+ } else if ( res ?. data ?. status === 'submitted' ) {
258+ // Extract destination txHashes if provided
259+ if ( res ?. data ?. txHashes && res . data . txHashes . length > 0 ) {
260+ extractDestinationTxHashes (
261+ res . data . txHashes ,
262+ res . data . destinationChainId
263+ )
264+ }
265+
266+ // Extract origin txHashes if provided
267+ if ( res ?. data ?. inTxHashes && res . data . inTxHashes . length > 0 ) {
268+ extractOriginTxHashes ( res . data . inTxHashes , res . data . originChainId )
269+ }
220270
271+ stepItem . checkStatus = 'submitted'
272+ stepItem . progressState = undefined
273+ stepItem . isValidatingSignature = false
274+ updateState ( )
275+ client . log (
276+ [ 'Destination tx submitted, continuing validation' ] ,
277+ LogLevel . Verbose
278+ )
279+ } else if ( res ?. data ?. status === 'success' && res ?. data ?. txHashes ) {
280+ // Extract destination txHashes
281+ extractDestinationTxHashes (
282+ res . data . txHashes ,
283+ res . data . destinationChainId
284+ )
285+
286+ // Extract origin txHashes if provided (keeping original chainId order)
221287 if ( res ?. data ?. inTxHashes ) {
222288 const chainInTxHashes : NonNullable <
223289 Execute [ 'steps' ] [ 0 ] [ 'items' ]
224- > [ 0 ] [ 'txHashes' ] = res . data . inTxHashes . map ( ( hash : string ) => {
225- return {
226- txHash : hash ,
227- chainId : chain ?. id ?? res . data . originChainId
228- }
229- } )
290+ > [ 0 ] [ 'txHashes' ] = res . data . inTxHashes . map ( ( hash : string ) => ( {
291+ txHash : hash ,
292+ chainId : chain ?. id ?? res . data . originChainId
293+ } ) )
230294 stepItem . internalTxHashes = chainInTxHashes
231295 }
232- stepItem . txHashes = chainTxHashes
296+
297+ stepItem . checkStatus = 'success'
298+ stepItem . status = 'complete'
299+ stepItem . progressState = 'complete'
300+ updateState ( )
301+ client . log ( [ 'Transaction completed successfully' ] , LogLevel . Verbose )
233302 return // Success - exit polling
234303 } else if ( res ?. data ?. status === 'failure' ) {
235304 throw Error ( res ?. data ?. details || 'Transaction failed' )
236- } else if ( res ?. data ?. status === 'delayed' ) {
237- stepItem . progressState = 'validating_delayed'
238- setState ( {
239- steps : [ ...json ?. steps ] ,
240- fees : { ...json ?. fees } ,
241- breakdown : json ?. breakdown ,
242- details : json ?. details
243- } )
305+ } else if ( res . status >= 400 ) {
306+ // Handle HTTP error responses that don't have our expected data structure
307+ throw Error (
308+ res ?. data ?. details || res ?. data ?. message || 'Failed to check'
309+ )
310+ }
311+
312+ attemptCount ++
313+ await new Promise ( ( resolve ) => setTimeout ( resolve , pollingInterval ) )
314+ } catch ( error : any ) {
315+ // If it's a deliberate failure response, re-throw immediately
316+ if (
317+ error . message &&
318+ ( error . message . includes ( 'Transaction failed' ) ||
319+ error . message . includes ( 'Failed to check' ) ||
320+ error . message === 'Failed to check' )
321+ ) {
322+ throw error
244323 }
245324
325+ // For network errors or other recoverable issues, continue polling
326+ client . log (
327+ [ 'Check request failed, retrying...' , error ] ,
328+ LogLevel . Verbose
329+ )
246330 attemptCount ++
247331 await new Promise ( ( resolve ) => setTimeout ( resolve , pollingInterval ) )
248- } catch ( error ) {
249- throw error
250332 }
251333 }
252334
0 commit comments