import { createSlice , PayloadAction } from "@reduxjs/toolkit" ; export interface IPendingTxn { readonly txnHash : string ; readonly text : string ; readonly type : string ; } const initialState = [ ] ; const pendingTxnsSlice = createSlice ( { name : "pendingTransactions" , initialState , reducers : { fetchPendingTxns ( state , action ) { state . push ( action . payload ) ; } , clearPendingTxn ( state , action ) { const target = state . find ( x => x . txnHash === action . payload ) ; if ( target ) { state . splice ( state . indexOf ( target ) , 1 ) ; } } , } , } ) ; export const getStakingTypeText = ( action ) => { return action . toLowerCase ( ) === "stake" ? "Staking TIME" : "Unstaking MEMO" ; } ; export const getWrappingTypeText = ( isWrap ) => { return isWrap ? "Wrap MEMO" : "Unwrap wMEMO" ; } ; export const isPendingTxn = ( pendingTransactions , type ) => { return pendingTransactions . map ( x => x . type ) . includes ( type ) ; } ; export const txnButtonText = ( pendingTransactions , type , defaultText ) => { return isPendingTxn ( pendingTransactions , type ) ? "Pending..." : defaultText ; } ; export const { fetchPendingTxns , clearPendingTxn } = pendingTxnsSlice . actions ; export default pendingTxnsSlice . reducer ;