diff --git a/src/components/Request/Pay/Views/Initial.view.tsx b/src/components/Request/Pay/Views/Initial.view.tsx index f4f9ff82..9d3c998a 100644 --- a/src/components/Request/Pay/Views/Initial.view.tsx +++ b/src/components/Request/Pay/Views/Initial.view.tsx @@ -252,26 +252,6 @@ export const InitialView = ({ feeOptions: undefined, }) setLoadingState('Executing transaction') - - await peanut.submitRequestLinkFulfillment({ - chainId: requestLinkData.chainId, - hash: hash ?? '', - payerAddress: address ?? '', - link: requestLinkData.link, - apiUrl: '/api/proxy/patch/', - amountUsd, - }) - - const currentDate = new Date().toISOString() - utils.saveRequestLinkFulfillmentToLocalStorage({ - details: { - ...requestLinkData, - destinationChainFulfillmentHash: hash ?? '', - createdAt: currentDate, - }, - link: requestLinkData.link, - }) - setTransactionHash(hash ?? '') onNext() } diff --git a/src/components/Request/Pay/Views/Success.view.tsx b/src/components/Request/Pay/Views/Success.view.tsx index ee51a60d..1acfb37e 100644 --- a/src/components/Request/Pay/Views/Success.view.tsx +++ b/src/components/Request/Pay/Views/Success.view.tsx @@ -5,9 +5,12 @@ import * as utils from '@/utils' import { useContext, useEffect, useMemo, useState } from 'react' import { fetchDestinationChain } from '@/components/utils/utils' import * as context from '@/context' +import { peanut } from '@squirrel-labs/peanut-sdk' +import { useAccount } from 'wagmi' -export const SuccessView = ({ transactionHash, requestLinkData }: _consts.IPayScreenProps) => { - const { selectedChainID } = useContext(context.tokenSelectorContext) +export const SuccessView = ({ transactionHash, requestLinkData, tokenPriceData }: _consts.IPayScreenProps) => { + const { selectedChainID, isXChain } = useContext(context.tokenSelectorContext) + const { address } = useAccount() const sourceUrlWithTx = useMemo( () => `${utils.getExplorerUrl(selectedChainID)}/tx/${transactionHash}`, [transactionHash, selectedChainID] @@ -18,10 +21,32 @@ export const SuccessView = ({ transactionHash, requestLinkData }: _consts.IPaySc const explorerUrlAxelarWithTx = 'https://axelarscan.io/gmp/' + transactionHash useEffect(() => { - if (transactionHash) { + if (explorerUrlDestChainWithTxHash) { + peanut.submitRequestLinkFulfillment({ + chainId: requestLinkData.chainId, + hash: explorerUrlDestChainWithTxHash.transactionId, + payerAddress: address ?? '', + link: requestLinkData.link, + apiUrl: '/api/proxy/patch/', + amountUsd: (Number(requestLinkData.tokenAmount) * (tokenPriceData?.price ?? 0)).toFixed(2), + }) + utils.saveRequestLinkFulfillmentToLocalStorage({ + details: { + ...requestLinkData, + destinationChainFulfillmentHash: explorerUrlDestChainWithTxHash.transactionId, + createdAt: new Date().toISOString(), + }, + link: requestLinkData.link, + }) + } + }, [explorerUrlDestChainWithTxHash]) + + useEffect(() => { + if (isXChain && transactionHash) { fetchDestinationChain(transactionHash, setExplorerUrlDestChainWithTxHash) } }, []) + return (