Compare commits

..
Author SHA1 Message Date
maciek f95d064237 chore: catch ethereum errors and capture to sentry 2023-03-02 13:15:00 +01:00
3 changed files with 40 additions and 14 deletions
@@ -37,7 +37,6 @@ import {
usePersistedOrderStoreSubscription,
} from '@vegaprotocol/orders';
import { OrderType } from '@vegaprotocol/types';
import isNumber from 'lodash/isNumber';
export type TransactionStatus = 'default' | 'pending';
@@ -83,17 +82,14 @@ export const DealTicket = ({
const order = watch();
useEffect(() => {
const { unsubscribe } = watch((orderData) => {
const persistable = !(
orderData.type === OrderType.TYPE_LIMIT && orderData.price === ''
);
if (persistable) {
setPersistedOrder(orderData as DealTicketFormFields);
}
});
return () => unsubscribe();
}, [setPersistedOrder, watch]);
watch((orderData) => {
const persistable = !(
orderData.type === OrderType.TYPE_LIMIT && orderData.price === ''
);
if (persistable) {
setPersistedOrder(orderData as DealTicketFormFields);
}
});
usePersistedOrderStoreSubscription(market.id, (storedOrder) => {
if (order.price !== storedOrder.price) {
@@ -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');
});
});
});
@@ -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,