chore(trading): add handle wrong chainId in withdrawal (#3015)
This commit is contained in:
parent
f128f41ea0
commit
76bf45b461
@ -21,9 +21,11 @@ import type { NetworkParamsQuery } from '@vegaprotocol/react-helpers';
|
|||||||
|
|
||||||
const mockWeb3Provider = jest.fn();
|
const mockWeb3Provider = jest.fn();
|
||||||
|
|
||||||
|
let mockChainId = 111111;
|
||||||
jest.mock('@web3-react/core', () => ({
|
jest.mock('@web3-react/core', () => ({
|
||||||
useWeb3React: () => ({
|
useWeb3React: () => ({
|
||||||
provider: mockWeb3Provider(),
|
provider: mockWeb3Provider(),
|
||||||
|
chainId: mockChainId,
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -63,15 +65,16 @@ jest.mock('./use-get-withdraw-delay', () => ({
|
|||||||
useGetWithdrawDelay: () => mockUseGetWithdrawDelay(),
|
useGetWithdrawDelay: () => mockUseGetWithdrawDelay(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const mockUseEthereumConfig = jest.fn(() => ({
|
const mockUseEthereumConfig = {
|
||||||
collateral_bridge_contract: {
|
collateral_bridge_contract: {
|
||||||
address: 'address',
|
address: 'address',
|
||||||
},
|
},
|
||||||
}));
|
chain_id: '111111',
|
||||||
|
};
|
||||||
|
|
||||||
jest.mock('./use-ethereum-config', () => ({
|
jest.mock('./use-ethereum-config', () => ({
|
||||||
useEthereumConfig: () => ({
|
useEthereumConfig: () => ({
|
||||||
config: mockUseEthereumConfig(),
|
config: mockUseEthereumConfig,
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -301,4 +304,19 @@ describe('useEthWithdrawApprovalsManager', () => {
|
|||||||
erc20WithdrawalApproval.signatures,
|
erc20WithdrawalApproval.signatures,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('detect wrong chainId', () => {
|
||||||
|
mockChainId = 1;
|
||||||
|
const transaction = createWithdrawTransaction();
|
||||||
|
mockEthTransactionStoreState.mockReturnValue({ create });
|
||||||
|
mockEthWithdrawApprovalsStoreState.mockReturnValue({
|
||||||
|
transactions: [transaction],
|
||||||
|
update,
|
||||||
|
});
|
||||||
|
render();
|
||||||
|
expect(update.mock.calls[0][1].status).toEqual(ApprovalStatus.Error);
|
||||||
|
expect(update.mock.calls[0][1].message).toEqual(
|
||||||
|
'You are on the wrong network'
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -28,7 +28,7 @@ export const useEthWithdrawApprovalsManager = () => {
|
|||||||
const getThreshold = useGetWithdrawThreshold();
|
const getThreshold = useGetWithdrawThreshold();
|
||||||
const getDelay = useGetWithdrawDelay();
|
const getDelay = useGetWithdrawDelay();
|
||||||
const { query } = useApolloClient();
|
const { query } = useApolloClient();
|
||||||
const { provider } = useWeb3React();
|
const { provider, chainId } = useWeb3React();
|
||||||
const { config } = useEthereumConfig();
|
const { config } = useEthereumConfig();
|
||||||
const createEthTransaction = useEthTransactionStore((state) => state.create);
|
const createEthTransaction = useEthTransactionStore((state) => state.create);
|
||||||
const update = useEthWithdrawApprovalsStore((state) => state.update);
|
const update = useEthWithdrawApprovalsStore((state) => state.update);
|
||||||
@ -57,6 +57,13 @@ export const useEthWithdrawApprovalsManager = () => {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (chainId?.toString() !== config?.chain_id) {
|
||||||
|
update(transaction.id, {
|
||||||
|
status: ApprovalStatus.Error,
|
||||||
|
message: t(`You are on the wrong network`),
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
update(transaction.id, {
|
update(transaction.id, {
|
||||||
status: ApprovalStatus.Pending,
|
status: ApprovalStatus.Pending,
|
||||||
message: t('Verifying withdrawal approval'),
|
message: t('Verifying withdrawal approval'),
|
||||||
@ -131,5 +138,6 @@ export const useEthWithdrawApprovalsManager = () => {
|
|||||||
query,
|
query,
|
||||||
transaction,
|
transaction,
|
||||||
update,
|
update,
|
||||||
|
chainId,
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
@ -216,7 +216,7 @@ export const getVerifyDialogProps = (status: ApprovalStatus) => {
|
|||||||
|
|
||||||
export const VerificationStatus = ({ state }: { state: VerifyState }) => {
|
export const VerificationStatus = ({ state }: { state: VerifyState }) => {
|
||||||
if (state.status === ApprovalStatus.Error) {
|
if (state.status === ApprovalStatus.Error) {
|
||||||
return <p>{t('Something went wrong')}</p>;
|
return <p>{state.message || t('Something went wrong')}</p>;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.status === ApprovalStatus.Pending) {
|
if (state.status === ApprovalStatus.Pending) {
|
||||||
|
Loading…
Reference in New Issue
Block a user