diff --git a/src/sections/transaction/ReviewTransaction.tsx b/src/sections/transaction/ReviewTransaction.tsx index 222cde2dd..3607e0af7 100644 --- a/src/sections/transaction/ReviewTransaction.tsx +++ b/src/sections/transaction/ReviewTransaction.tsx @@ -35,7 +35,7 @@ export const ReviewTransaction = (props: Transaction) => { txLink, txHash, bridge, - } = useSendTx() + } = useSendTx(props.xcallMeta) if (!isLoaded) return null @@ -145,9 +145,9 @@ export const ReviewTransaction = (props: Transaction) => { props.onSubmitted?.() sendEvmTx(data) }} - onSigned={(tx, xcallMeta) => { + onSigned={(tx) => { props.onSubmitted?.() - sendTx({ tx, xcallMeta }) + sendTx({ tx }) }} onPermitDispatched={(permit) => { props.onSubmitted?.() diff --git a/src/sections/transaction/ReviewTransaction.utils.tsx b/src/sections/transaction/ReviewTransaction.utils.tsx index df9b60287..7a3dcc91d 100644 --- a/src/sections/transaction/ReviewTransaction.utils.tsx +++ b/src/sections/transaction/ReviewTransaction.utils.tsx @@ -44,6 +44,7 @@ import { isAnyParachain, Maybe } from "utils/helpers" import { createSubscanLink } from "utils/formatting" import { QUERY_KEYS } from "utils/queryKeys" import { useIsTestnet } from "api/provider" +import { tags } from "@galacticcouncil/xcm-cfg" const EVM_PERMIT_BLOCKTIME = 20_000 @@ -177,27 +178,23 @@ export const useSendEvmTransactionMutation = ( { evmTx: TransactionResponse tx?: SubmittableExtrinsic<"promise"> - xcallMeta?: Record } > = {}, + xcallMeta?: Record, ) => { const [txState, setTxState] = useState(null) const [txHash, setTxHash] = useState("") const [txData, setTxData] = useState() - const [xcallMeta, setCallMeta] = useState | undefined>( - undefined, - ) const { account } = useEvmAccount() const isTestnet = useIsTestnet() - const sendTx = useMutation(async ({ evmTx, xcallMeta }) => { + const sendTx = useMutation(async ({ evmTx }) => { return await new Promise(async (resolve, reject) => { try { setTxState("Broadcast") setTxHash(evmTx?.hash ?? "") setTxData(evmTx?.data) - setCallMeta(xcallMeta) const receipt = await evmTx.wait() setTxState("InBlock") @@ -208,9 +205,12 @@ export const useSendEvmTransactionMutation = ( }) }, options) + const isSnowBridge = xcallMeta?.tags === tags.Tag.Snowbridge const chain = account?.chainId ? getEvmChainById(account.chainId) : null const txLink = - txHash && chain ? getEvmTxLink(txHash, txData, chain.key, isTestnet) : "" + txHash && chain + ? getEvmTxLink(txHash, txData, chain.key, isTestnet, isSnowBridge) + : "" const isApproveTx = txData?.startsWith("0x095ea7b3") @@ -226,11 +226,10 @@ export const useSendEvmTransactionMutation = ( txState, txLink, txHash, - bridge: isApproveTx ? undefined : bridge, + bridge: isApproveTx || isSnowBridge ? undefined : bridge, reset: () => { setTxState(null) setTxHash("") - setCallMeta(undefined) sendTx.reset() }, } @@ -301,21 +300,19 @@ export const useSendDispatchPermit = ( unknown, { permit: PermitResult - xcallMeta?: Record } > = {}, + xcallMeta?: Record, ) => { const { api } = useRpcProvider() const { wallet } = useWallet() const queryClient = useQueryClient() const [txState, setTxState] = useState(null) const [txHash, setTxHash] = useState("") - const [xcallMeta, setCallMeta] = useState | undefined>( - undefined, - ) + const isMounted = useMountedState() - const sendTx = useMutation(async ({ permit, xcallMeta }) => { + const sendTx = useMutation(async ({ permit }) => { return await new Promise(async (resolve, reject) => { try { const extrinsic = api.tx.multiTransactionPayment.dispatchPermit( @@ -337,7 +334,6 @@ export const useSendDispatchPermit = ( if (isMounted()) { setTxHash(result.txHash.toHex()) setTxState(result.status.type) - setCallMeta(xcallMeta) } const account = new H160(permit.message.from).toAccount() @@ -392,6 +388,8 @@ export const useSendDispatchPermit = ( }) }, options) + const isSnowBridge = xcallMeta?.tags === tags.Tag.Snowbridge + const destChain = xcallMeta?.dstChain ? chainsMap.get(xcallMeta.dstChain) : undefined @@ -403,7 +401,8 @@ export const useSendDispatchPermit = ( ? createSubscanLink("extrinsic", txHash, srcChain.key) : undefined - const bridge = destChain?.isEvmChain() ? "substrate" : undefined + const bridge = + destChain?.isEvmChain() && !isSnowBridge ? "substrate" : undefined return { ...sendTx, @@ -425,19 +424,16 @@ export const useSendTransactionMutation = ( unknown, { tx: SubmittableExtrinsic<"promise"> - xcallMeta?: Record } > = {}, + xcallMeta?: Record, ) => { const { api } = useRpcProvider() const isMounted = useMountedState() const [txState, setTxState] = useState(null) const [txHash, setTxHash] = useState("") - const [xcallMeta, setCallMeta] = useState | undefined>( - undefined, - ) - const sendTx = useMutation(async ({ tx, xcallMeta }) => { + const sendTx = useMutation(async ({ tx }) => { return await new Promise(async (resolve, reject) => { try { const unsubscribe = await tx.send(async (result) => { @@ -446,7 +442,6 @@ export const useSendTransactionMutation = ( if (isMounted()) { setTxHash(result.txHash.toHex()) setTxState(result.status.type) - setCallMeta(xcallMeta) } const externalChain = @@ -477,6 +472,8 @@ export const useSendTransactionMutation = ( }) }, options) + const isSnowBridge = xcallMeta?.tags === tags.Tag.Snowbridge + const destChain = xcallMeta?.dstChain ? chainsMap.get(xcallMeta.dstChain) : undefined @@ -488,7 +485,8 @@ export const useSendTransactionMutation = ( ? createSubscanLink("extrinsic", txHash, srcChain.key) : undefined - const bridge = destChain?.isEvmChain() ? "substrate" : undefined + const bridge = + destChain?.isEvmChain() && !isSnowBridge ? "substrate" : undefined return { ...sendTx, @@ -499,7 +497,6 @@ export const useSendTransactionMutation = ( reset: () => { setTxState(null) setTxHash("") - setCallMeta(undefined) sendTx.reset() }, } @@ -620,7 +617,7 @@ const useStoreExternalAssetsOnSign = () => { ) } -export const useSendTx = () => { +export const useSendTx = (xcallMeta?: Record) => { const [txType, setTxType] = useState<"default" | "evm" | "permit" | null>( null, ) @@ -628,31 +625,40 @@ export const useSendTx = () => { const boundReferralToast = useBoundReferralToast() const storeExternalAssetsOnSign = useStoreExternalAssetsOnSign() - const sendTx = useSendTransactionMutation({ - onMutate: ({ tx }) => { - boundReferralToast.onLoading(tx) - storeExternalAssetsOnSign(getAssetIdsFromTx(tx)) - setTxType("default") - }, - onSuccess: boundReferralToast.onSuccess, - }) - - const sendEvmTx = useSendEvmTransactionMutation({ - onMutate: ({ tx }) => { - if (tx) { + const sendTx = useSendTransactionMutation( + { + onMutate: ({ tx }) => { boundReferralToast.onLoading(tx) storeExternalAssetsOnSign(getAssetIdsFromTx(tx)) - } - setTxType("evm") + setTxType("default") + }, + onSuccess: boundReferralToast.onSuccess, }, - onSuccess: boundReferralToast.onSuccess, - }) + xcallMeta, + ) - const sendPermitTx = useSendDispatchPermit({ - onMutate: () => { - setTxType("permit") + const sendEvmTx = useSendEvmTransactionMutation( + { + onMutate: ({ tx }) => { + if (tx) { + boundReferralToast.onLoading(tx) + storeExternalAssetsOnSign(getAssetIdsFromTx(tx)) + } + setTxType("evm") + }, + onSuccess: boundReferralToast.onSuccess, }, - }) + xcallMeta, + ) + + const sendPermitTx = useSendDispatchPermit( + { + onMutate: () => { + setTxType("permit") + }, + }, + xcallMeta, + ) const activeMutation = txType === "default" ? sendTx : txType === "evm" ? sendEvmTx : sendPermitTx diff --git a/src/sections/transaction/ReviewTransactionForm.tsx b/src/sections/transaction/ReviewTransactionForm.tsx index 787b68b47..d718b1e38 100644 --- a/src/sections/transaction/ReviewTransactionForm.tsx +++ b/src/sections/transaction/ReviewTransactionForm.tsx @@ -47,22 +47,12 @@ type TxProps = Omit & { type Props = TxProps & { onCancel: () => void - onPermitDispatched: ({ - permit, - xcallMeta, - }: { - permit: PermitResult - xcallMeta?: Record - }) => void + onPermitDispatched: ({ permit }: { permit: PermitResult }) => void onEvmSigned: (data: { evmTx: TransactionResponse tx: SubmittableExtrinsic<"promise"> - xcallMeta?: Record }) => void - onSigned: ( - signed: SubmittableExtrinsic<"promise">, - xcallMeta?: Record, - ) => void + onSigned: (signed: SubmittableExtrinsic<"promise">) => void onSignError?: (error: unknown) => void } @@ -141,7 +131,6 @@ export const ReviewTransactionForm: FC = (props) => { const permit = await wallet.signer.getPermit(txData, nonce) return props.onPermitDispatched({ permit, - xcallMeta: props.xcallMeta, }) } @@ -149,7 +138,7 @@ export const ReviewTransactionForm: FC = (props) => { txData, props.xcallMeta?.srcChain, ) - return props.onEvmSigned({ evmTx, tx, xcallMeta: props.xcallMeta }) + return props.onEvmSigned({ evmTx, tx }) } const srcChain = props?.xcallMeta?.srcChain @@ -171,7 +160,7 @@ export const ReviewTransactionForm: FC = (props) => { withSignedTransaction: true, }) - return props.onSigned(signature, props.xcallMeta) + return props.onSigned(signature) } catch (error) { props.onSignError?.(error) } diff --git a/src/utils/evm.ts b/src/utils/evm.ts index bfdd4e2c3..a74cc6380 100644 --- a/src/utils/evm.ts +++ b/src/utils/evm.ts @@ -78,6 +78,7 @@ export function getEvmTxLink( txData: string | undefined, chainKey = "hydration", isTestnet = false, + isSnowbridge: boolean, ) { const chain = chainsMap.get(chainKey) @@ -86,7 +87,7 @@ export function getEvmTxLink( if (chain.isEvmChain()) { const isApproveTx = txData?.startsWith("0x095ea7b3") - return isApproveTx + return isApproveTx || isSnowbridge ? `https://etherscan.io/tx/${txHash}` : `https://wormholescan.io/#/tx/${txHash}` }