Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(request): store correct destination hash for xchain #437

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions src/components/Request/Pay/Views/Initial.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
33 changes: 29 additions & 4 deletions src/components/Request/Pay/Views/Success.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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({
jjramirezn marked this conversation as resolved.
Show resolved Hide resolved
chainId: requestLinkData.chainId,
hash: explorerUrlDestChainWithTxHash.transactionId,
Comment on lines +26 to +27
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Just so I understand this, does the requestLinkFulfillment only get submitted once the destination chain tx is through? So, if the user closes the page, it would never submit the fulfillment right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. I think the way to go around this is submit the origin transaction to the backend (but not mark as paid) and then with the destination chain tx we can do as today (if the user did not close the page) or in the backend we can check

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 (
<div className="flex w-full flex-col items-center justify-center gap-6 py-2 pb-20 text-center">
<label className="text-h2">Yay!</label>
Expand All @@ -36,7 +61,7 @@ export const SuccessView = ({ transactionHash, requestLinkData }: _consts.IPaySc
{utils.shortenAddressLong(transactionHash ?? '')}
</Link>
</div>
{requestLinkData.chainId !== selectedChainID && (
{isXChain && (
<>
<div className="flex w-full flex-row items-center justify-start gap-1">
<label className="">Axelar:</label>
Expand Down