From 747b1a5aee6733f932473963abf32ae2931976bd Mon Sep 17 00:00:00 2001 From: Bill He Date: Tue, 2 Jan 2024 21:02:58 -0800 Subject: [PATCH] CCTP deposit/withdraw to throw error if nobleClient is not initialized --- src/lib/abacus/dydxChainTransactions.ts | 4 ++++ src/views/forms/AccountManagementForms/DepositForm.tsx | 4 ++++ src/views/forms/AccountManagementForms/WithdrawForm.tsx | 9 +++++---- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/lib/abacus/dydxChainTransactions.ts b/src/lib/abacus/dydxChainTransactions.ts index 56c4a8c..efe0fb8 100644 --- a/src/lib/abacus/dydxChainTransactions.ts +++ b/src/lib/abacus/dydxChainTransactions.ts @@ -56,6 +56,10 @@ class DydxChainTransactions implements AbacusDYDXChainTransactionsProtocol { this.store = undefined; } + get isNobleClientConnected(): boolean { + return this.nobleClient?.isConnected ?? false; + } + setStore(store: RootStore): void { this.store = store; } diff --git a/src/views/forms/AccountManagementForms/DepositForm.tsx b/src/views/forms/AccountManagementForms/DepositForm.tsx index a0235e1..3089572 100644 --- a/src/views/forms/AccountManagementForms/DepositForm.tsx +++ b/src/views/forms/AccountManagementForms/DepositForm.tsx @@ -235,6 +235,10 @@ export const DepositForm = ({ onDeposit, onError }: DepositFormProps) => { throw new Error('Missing request payload'); } + if (isCctp && !abacusStateManager.chainTransactions.isNobleClientConnected) { + throw new Error('Noble client unable to initialize'); + } + setIsLoading(true); await validateTokenApproval(); diff --git a/src/views/forms/AccountManagementForms/WithdrawForm.tsx b/src/views/forms/AccountManagementForms/WithdrawForm.tsx index b98f104..a26a2cf 100644 --- a/src/views/forms/AccountManagementForms/WithdrawForm.tsx +++ b/src/views/forms/AccountManagementForms/WithdrawForm.tsx @@ -148,6 +148,10 @@ export const WithdrawForm = () => { throw new Error('Invalid request payload'); } + if (isCctp && !abacusStateManager.chainTransactions.isNobleClientConnected) { + throw new Error('Noble client unable to initialize'); + } + setIsLoading(true); setError(undefined); @@ -289,10 +293,7 @@ export const WithdrawForm = () => { const errorMessage = useMemo(() => { if (error) { - return stringGetter({ - key: STRING_KEYS.SOMETHING_WENT_WRONG_WITH_MESSAGE, - params: { ERROR_MESSAGE: error }, - }); + return error; } if (routeErrors) {