Skip to content

Commit

Permalink
Add TX errors to EVM
Browse files Browse the repository at this point in the history
  • Loading branch information
jvonasek committed Apr 11, 2024
1 parent 860af39 commit 95175fb
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions src/sections/transaction/ReviewTransaction.utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export const useSendEvmTransactionMutation = (
ISubmittableResult & {
transactionLink?: string
},
unknown,
TransactionError,
{
evmTx: TransactionResponse
tx?: SubmittableExtrinsic<"promise">
Expand Down Expand Up @@ -158,7 +158,7 @@ export const useSendEvmTransactionMutation = (
})
} catch (err) {
const { error } = decodeError(err)
reject(new Error(error))
reject(new TransactionError(error))
} finally {
clearTimeout(timeout)
}
Expand Down Expand Up @@ -322,33 +322,38 @@ const useBoundReferralToast = () => {
}
}

const useErrorToastUpdate = (id: string) => {
const { edit } = useToast()

return (err: TransactionError) => {
if (err?.method) {
defer(() => {
edit(id, {
description: (
<p>
<strong>{err.method}</strong>
{err.docs ? ` - ${err.docs}` : ""}
</p>
),
})
})
}
}
}

export const useSendTx = ({ id }: { id: string }) => {
const [txType, setTxType] = useState<"default" | "evm" | null>(null)

const { edit } = useToast()

const boundReferralToast = useBoundReferralToast()
const updateErrorToast = useErrorToastUpdate(id)

const sendTx = useSendTransactionMutation({
onMutate: (tx) => {
boundReferralToast.onLoading(tx)
setTxType("default")
},
onSuccess: boundReferralToast.onSuccess,
onError: (err) => {
if (err?.method) {
defer(() => {
edit(id, {
description: (
<p>
<strong>{err.method}</strong>
{err.docs ? ` - ${err.docs}` : ""}
</p>
),
})
})
}
},
onError: updateErrorToast,
})

const sendEvmTx = useSendEvmTransactionMutation({
Expand All @@ -357,6 +362,7 @@ export const useSendTx = ({ id }: { id: string }) => {
setTxType("evm")
},
onSuccess: boundReferralToast.onSuccess,
onError: updateErrorToast,
})

const activeMutation = txType === "default" ? sendTx : sendEvmTx
Expand Down

0 comments on commit 95175fb

Please sign in to comment.