vega-frontend-monorepo/apps/token/src/stores/transactions.ts
m.ray 7ea7edc1e2
feat(#2565): orderbook populate limit (#2690)
Co-authored-by: asiaznik <artur@vegaprotocol.io>
2023-01-25 11:38:26 -08:00

43 lines
1.0 KiB
TypeScript

import type ethers from 'ethers';
import type { GetState, SetState } from 'zustand';
import { create } from 'zustand';
export interface TxData {
tx: ethers.ContractTransaction;
receipt: ethers.ContractReceipt | null;
pending: boolean;
requiredConfirmations: number;
}
interface TransactionStore {
transactions: Array<TxData>;
add: (tx: TxData) => void;
update: (tx: TxData) => void;
remove: (tx: TxData) => void;
}
export const useTransactionStore = create(
(set: SetState<TransactionStore>, get: GetState<TransactionStore>) => ({
transactions: [],
add: (tx) => {
const { transactions } = get();
set({ transactions: [...transactions, tx] });
},
update: (tx) => {
const { transactions } = get();
set({
transactions: [
...transactions.filter((t) => t.tx.hash !== tx.tx.hash),
tx,
],
});
},
remove: (tx) => {
const { transactions } = get();
set({
transactions: transactions.filter((t) => t.tx.hash !== tx.tx.hash),
});
},
})
);