* feat: add eth and vega transaction stores feat: replace useStoredEthereumTransaction with useEthTransactionManager feat: add event bus subsciption to vega transaction store feat: handle order cancellation feat: rename Deposit, Order and Withdraw status field to be unique Revert "feat: rename Deposit, Order and Withdraw status field to be unique" This reverts commit f0b314d53fb3ada6fbebaba4fd1e5af6f38beaed. feat: split transaction update subscription feat: handle order and deposit transaction feat: handle withdrawal creation through transaction store feat: handle withdraw approval feat: handle panding withdrawls, add createdAt feat: handle transaction toast/dialog dismissal feat: add use vega transaction store tests feat: add use vega transaction store tests feat: add use vega transaction menager tests feat: add use vega transaction menager tests feat: add use vega transaction updater tests feat: improve use vega transaction updater tests feat: add use eth transaction store feat: add use eth withdraw approvals store feat: add use eth transaction updater tests fixed tests * feat: toasts feat: toasts feat: toasts * feat: add use eth withdraw approval manager tests * feat: add use eth transaction manager tests * feat: add use eth transaction manager tests * feat: add useEthWithdrawApprovalsManager tests * feat: remove Web3Container react container from CreateWithdrawalDialog * feat: remove Web3Container react container around TransactionsHandler * feat: remove unnecessary async from PendingWithdrawalsTable * feat: remove comments from WithdrawalFeedback * fixed z-index issue * cypress Co-authored-by: Bartłomiej Głownia <bglownia@gmail.com>
61 lines
2.5 KiB
TypeScript
61 lines
2.5 KiB
TypeScript
import { useEthWithdrawApprovalsStore } from './use-ethereum-withdraw-approvals-store';
|
|
import type { VegaStoredTxState } from '@vegaprotocol/wallet';
|
|
import { ApprovalStatus } from './use-ethereum-withdraw-approvals-store';
|
|
import type { EthWithdrawalApprovalState } from './use-ethereum-withdraw-approvals-store';
|
|
|
|
const mockFindVegaTransaction = jest.fn<VegaStoredTxState, []>();
|
|
const mockDismissVegaTransaction = jest.fn();
|
|
|
|
jest.mock('@vegaprotocol/wallet', () => ({
|
|
useVegaTransactionStore: {
|
|
getState: () => ({
|
|
transactions: {
|
|
find: mockFindVegaTransaction,
|
|
},
|
|
dismiss: mockDismissVegaTransaction,
|
|
}),
|
|
},
|
|
}));
|
|
describe('useEthWithdrawApprovalsStore', () => {
|
|
const withdrawal = {} as unknown as EthWithdrawalApprovalState['withdrawal'];
|
|
const approval = {} as unknown as NonNullable<
|
|
EthWithdrawalApprovalState['approval']
|
|
>;
|
|
|
|
it('creates approval with default values, dismiss possible vega transaction', () => {
|
|
const vegaTransaction = { id: 0 } as unknown as VegaStoredTxState;
|
|
mockFindVegaTransaction.mockReturnValueOnce(vegaTransaction);
|
|
useEthWithdrawApprovalsStore.getState().create(withdrawal, approval);
|
|
const transaction = useEthWithdrawApprovalsStore.getState().transactions[0];
|
|
expect(transaction?.createdAt).toBeTruthy();
|
|
expect(transaction?.withdrawal).toBe(withdrawal);
|
|
expect(transaction?.approval).toBe(approval);
|
|
expect(transaction?.status).toEqual(ApprovalStatus.Idle);
|
|
expect(transaction?.dialogOpen).toEqual(true);
|
|
expect(mockDismissVegaTransaction).toBeCalledWith(vegaTransaction.id);
|
|
});
|
|
it('updates approval by index/id', () => {
|
|
useEthWithdrawApprovalsStore.getState().create(withdrawal);
|
|
useEthWithdrawApprovalsStore.getState().create(withdrawal);
|
|
useEthWithdrawApprovalsStore.getState().create(withdrawal);
|
|
useEthWithdrawApprovalsStore
|
|
.getState()
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
.update(1, { status: ApprovalStatus.Pending });
|
|
expect(
|
|
useEthWithdrawApprovalsStore.getState().transactions.map((t) => t?.status)
|
|
).toEqual([
|
|
ApprovalStatus.Idle,
|
|
ApprovalStatus.Pending,
|
|
ApprovalStatus.Idle,
|
|
]);
|
|
});
|
|
it('sets dialogOpen to false on dismiss', () => {
|
|
const id = useEthWithdrawApprovalsStore.getState().create(withdrawal);
|
|
useEthWithdrawApprovalsStore.getState().dismiss(id);
|
|
expect(
|
|
useEthWithdrawApprovalsStore.getState().transactions[id]?.dialogOpen
|
|
).toEqual(false);
|
|
});
|
|
});
|