diff --git a/libs/web3/src/lib/use-ethereum-withdraw-approvals-manager.spec.tsx b/libs/web3/src/lib/use-ethereum-withdraw-approvals-manager.spec.tsx index 0ef87e8e8..960c77b37 100644 --- a/libs/web3/src/lib/use-ethereum-withdraw-approvals-manager.spec.tsx +++ b/libs/web3/src/lib/use-ethereum-withdraw-approvals-manager.spec.tsx @@ -1,5 +1,5 @@ import { useEthWithdrawApprovalsManager } from './use-ethereum-withdraw-approvals-manager'; -import { renderHook } from '@testing-library/react'; +import { renderHook, waitFor } from '@testing-library/react'; import type { MockedResponse } from '@apollo/client/testing'; import type { ReactNode } from 'react'; import { MockedProvider } from '@apollo/client/testing'; @@ -318,5 +318,25 @@ describe('useEthWithdrawApprovalsManager', () => { expect(update.mock.calls[0][1].message).toEqual( 'You are on the wrong network' ); + mockChainId = 111111; + }); + + it('catch ethereum errors', async () => { + const transaction = createWithdrawTransaction(); + mockUseGetWithdrawThreshold.mockReturnValueOnce(() => { + throw new Error('call revert exception'); + }); + + mockEthTransactionStoreState.mockReturnValue({ create }); + mockEthWithdrawApprovalsStoreState.mockReturnValue({ + transactions: [transaction], + update, + }); + render(); + await waitFor(() => { + const lastCall = update.mock.calls.pop(); + expect(lastCall[1].status).toEqual(ApprovalStatus.Error); + expect(lastCall[1].message).toEqual('Something went wrong'); + }); }); }); diff --git a/libs/web3/src/lib/use-ethereum-withdraw-approvals-manager.tsx b/libs/web3/src/lib/use-ethereum-withdraw-approvals-manager.tsx index a5cb4a8aa..c79bdd6c5 100644 --- a/libs/web3/src/lib/use-ethereum-withdraw-approvals-manager.tsx +++ b/libs/web3/src/lib/use-ethereum-withdraw-approvals-manager.tsx @@ -5,6 +5,7 @@ import { addDecimal } from '@vegaprotocol/utils'; import { useGetWithdrawThreshold } from './use-get-withdraw-threshold'; import { useGetWithdrawDelay } from './use-get-withdraw-delay'; import { t } from '@vegaprotocol/i18n'; +import { localLoggerFactory } from '@vegaprotocol/utils'; import { CollateralBridge } from '@vegaprotocol/smart-contracts'; @@ -128,7 +129,16 @@ export const useEthWithdrawApprovalsManager = () => { approval.signatures, ] ); - })(); + })().catch((err) => { + localLoggerFactory({ application: 'web3' }).error( + 'create withdrawal transaction', + err + ); + update(transaction.id, { + status: ApprovalStatus.Error, + message: t('Something went wrong'), + }); + }); }, [ getThreshold, getDelay,