11import { useCallback , useEffect , useMemo , useRef , useState } from "react" ;
2+ import { trackPayEvent } from "../../../analytics/track/pay.js" ;
23import type { status as OnrampStatus } from "../../../bridge/OnrampStatus.js" ;
34import { ApiError } from "../../../bridge/types/Errors.js" ;
45import type {
@@ -9,6 +10,7 @@ import type { Status } from "../../../bridge/types/Status.js";
910import { getCachedChain } from "../../../chains/utils.js" ;
1011import type { ThirdwebClient } from "../../../client/client.js" ;
1112import { waitForReceipt } from "../../../transaction/actions/wait-for-tx-receipt.js" ;
13+ import { stringify } from "../../../utils/json.js" ;
1214import { waitForCallsReceipt } from "../../../wallets/eip5792/wait-for-calls-receipt.js" ;
1315import type { Account , Wallet } from "../../../wallets/interfaces/wallet.js" ;
1416import type { WindowAdapter } from "../adapters/WindowAdapter.js" ;
@@ -481,6 +483,22 @@ export function useStepExecutor(
481483 return ;
482484 }
483485
486+ trackPayEvent ( {
487+ client,
488+ event : `ub:ui:execution:start` ,
489+ toChainId :
490+ preparedQuote . steps [ preparedQuote . steps . length - 1 ] ?. destinationToken
491+ . chainId ,
492+ toToken :
493+ preparedQuote . steps [ preparedQuote . steps . length - 1 ] ?. destinationToken
494+ . address ,
495+ fromToken : preparedQuote . steps [ 0 ] ?. originToken . address ,
496+ chainId : preparedQuote . steps [ 0 ] ?. destinationToken . chainId ,
497+ amountWei : preparedQuote . steps [ 0 ] ?. originAmount ?. toString ( ) ,
498+ walletAddress : wallet ?. getAccount ( ) ?. address ,
499+ walletType : wallet ?. id ,
500+ } ) ;
501+
484502 setExecutionState ( "executing" ) ;
485503 setError ( undefined ) ;
486504 const completedStatusResults : CompletedStatusResult [ ] = [ ] ;
@@ -625,9 +643,41 @@ export function useStepExecutor(
625643 if ( onComplete ) {
626644 onComplete ( completedStatusResults ) ;
627645 }
646+
647+ trackPayEvent ( {
648+ client,
649+ event : `ub:ui:execution:success` ,
650+ toChainId :
651+ preparedQuote . steps [ preparedQuote . steps . length - 1 ]
652+ ?. destinationToken . chainId ,
653+ toToken :
654+ preparedQuote . steps [ preparedQuote . steps . length - 1 ]
655+ ?. destinationToken . address ,
656+ fromToken : preparedQuote . steps [ 0 ] ?. originToken . address ,
657+ chainId : preparedQuote . steps [ 0 ] ?. destinationToken . chainId ,
658+ amountWei : preparedQuote . steps [ 0 ] ?. originAmount ?. toString ( ) ,
659+ walletAddress : wallet ?. getAccount ( ) ?. address ,
660+ walletType : wallet ?. id ,
661+ } ) ;
628662 }
629663 } catch ( err ) {
630664 console . error ( "Error executing payment" , err ) ;
665+ trackPayEvent ( {
666+ client,
667+ error : err instanceof Error ? err . message : stringify ( err ) ,
668+ event : `ub:ui:execution:error` ,
669+ toChainId :
670+ preparedQuote . steps [ preparedQuote . steps . length - 1 ] ?. destinationToken
671+ . chainId ,
672+ toToken :
673+ preparedQuote . steps [ preparedQuote . steps . length - 1 ] ?. destinationToken
674+ . address ,
675+ fromToken : preparedQuote . steps [ 0 ] ?. originToken . address ,
676+ chainId : preparedQuote . steps [ 0 ] ?. destinationToken . chainId ,
677+ amountWei : preparedQuote . steps [ 0 ] ?. originAmount ?. toString ( ) ,
678+ walletAddress : wallet ?. getAccount ( ) ?. address ,
679+ walletType : wallet ?. id ,
680+ } ) ;
631681 if ( err instanceof ApiError ) {
632682 setError ( err ) ;
633683 } else {
@@ -655,6 +705,7 @@ export function useStepExecutor(
655705 executeOnramp ,
656706 onComplete ,
657707 preparedQuote ,
708+ client ,
658709 ] ) ;
659710
660711 // Start execution
0 commit comments