diff --git a/src/lib/abacus/stateNotification.ts b/src/lib/abacus/stateNotification.ts index e7ef1ca..be8d352 100644 --- a/src/lib/abacus/stateNotification.ts +++ b/src/lib/abacus/stateNotification.ts @@ -22,7 +22,6 @@ import { setSubaccount, setTransfers, setWallet, - setTransferStatuses, } from '@/state/account'; import { setApiState } from '@/state/app'; @@ -70,14 +69,6 @@ class AbacusStateNotifier implements AbacusStateNotificationProtocol { dispatch(setInputs(updatedState.input)); } - if (changes.has(Changes.transferStatuses) && updatedState.transferStatuses) { - const transferStatuses: Record = {}; - updatedState.transferStatuses.forEach((transferStatus) => { - transferStatuses[transferStatus.k] = transferStatus.v; - }); - dispatch(setTransferStatuses(transferStatuses)); - } - if (changes.has(Changes.wallet)) { dispatch(setWallet(updatedState.wallet)); } diff --git a/src/state/account.ts b/src/state/account.ts index efa4ce7..5fab6e3 100644 --- a/src/state/account.ts +++ b/src/state/account.ts @@ -12,7 +12,6 @@ import type { SubaccountTransfers, HistoricalPnlPeriods, SubAccountHistoricalPNLs, - TransferStatus, } from '@/constants/abacus'; import { OnboardingGuard, OnboardingState } from '@/constants/account'; @@ -36,16 +35,6 @@ export type AccountState = { wallet?: Nullable; walletType?: WalletType; historicalPnlPeriod?: HistoricalPnlPeriods; - squidTransfer?: Record< - string, - { - hash: string; - toChainId: string; - fromChainId?: string; - toAmount?: number; - status?: TransferStatus; - } - >; }; const initialState: AccountState = { @@ -159,24 +148,6 @@ export const accountSlice = createSlice({ viewedOrders: (state) => { state.hasUnseenOrderUpdates = false; }, - addSquidTransfer: ( - state, - action: PayloadAction<{ - hash: string; - toChainId: string; - fromChainId?: string; - toAmount?: number; - }> - ) => { - if (!state.squidTransfer) state.squidTransfer = {}; - state.squidTransfer[action.payload.hash] = { ...action.payload }; - }, - setTransferStatuses: (state, action: PayloadAction>) => { - Object.keys(action.payload).forEach((key) => { - if (state.squidTransfer && state.squidTransfer[key]) - state.squidTransfer[key].status = action.payload[key]; - }); - }, }, }); @@ -194,6 +165,4 @@ export const { removeUncommittedOrderClientId, viewedFills, viewedOrders, - addSquidTransfer, - setTransferStatuses, } = accountSlice.actions; diff --git a/src/state/accountSelectors.ts b/src/state/accountSelectors.ts index 45cf622..29aa72e 100644 --- a/src/state/accountSelectors.ts +++ b/src/state/accountSelectors.ts @@ -319,8 +319,3 @@ export const getUserStats = (state: RootState) => ({ makerVolume30D: state.account?.wallet?.user?.makerVolume30D, takerVolume30D: state.account?.wallet?.user?.takerVolume30D, }); - -/** - * @returns Get the current squid transfers - */ -export const getSquidTransfers = (state: RootState) => state.account?.squidTransfer; diff --git a/src/state/transferStatus.ts b/src/state/transferStatus.ts deleted file mode 100644 index 2b21d50..0000000 --- a/src/state/transferStatus.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { createSlice, type PayloadAction } from '@reduxjs/toolkit'; - -import type { - InputError, - Inputs, - Nullable, - TradeInputs, - ClosePositionInputs, - TransferInputs, -} from '@/constants/abacus'; - -export interface InputsState { - current?: Nullable; - inputErrors?: Nullable; - tradeInputs?: Nullable; - closePositionInputs?: Nullable; - transferInputs?: Nullable; -} - -const initialState: InputsState = { - current: undefined, - inputErrors: undefined, - tradeInputs: undefined, - transferInputs: undefined, -}; - -export const inputsSlice = createSlice({ - name: 'Inputs', - initialState, - reducers: { - setInputs: (state, action: PayloadAction>) => { - const { current, errors, trade, closePosition, transfer } = action.payload || {}; - - return { - ...state, - current: current?.rawValue, - inputErrors: errors?.toArray(), - tradeInputs: trade, - closePositionInputs: closePosition, - transferInputs: transfer, - }; - }, - }, -}); - -export const { setInputs } = inputsSlice.actions; diff --git a/src/state/transferStatusSelectors.ts b/src/state/transferStatusSelectors.ts deleted file mode 100644 index bf429cd..0000000 --- a/src/state/transferStatusSelectors.ts +++ /dev/null @@ -1,113 +0,0 @@ -import { shallowEqual, useSelector } from 'react-redux'; -import { createSelector } from 'reselect'; - -import type { RootState } from './_store'; - -/** - * @param state - * @returns TradeInputs - */ -export const getInputTradeData = (state: RootState) => state.inputs.tradeInputs; - -/** - * @param state - * @returns Size data in TradeInputs - */ -export const getInputTradeSizeData = (state: RootState) => state.inputs.tradeInputs?.size; - -/** - * @param state - * @returns AbacusOrderSide in TradeInputs - */ -export const getTradeSide = (state: RootState) => state.inputs.tradeInputs?.side; - -/** - * @param state - * @returns TradeInputs options (config for what TradeInputFields to render) - */ -export const getInputTradeOptions = (state: RootState) => state.inputs.tradeInputs?.options; - -/** - * @param state - * @returns ValidationErrors of the current Input type (Trade or Transfer) - */ -export const getInputErrors = (state: RootState) => state.inputs.inputErrors; - -/** - * @param state - * @returns trade or closePosition transfer, depending on which form was last edited. - */ -export const getCurrentInput = (state: RootState) => state.inputs.current; - -/** - * @param state - * @returns input errors for Trade - */ -export const getTradeInputErrors = (state: RootState) => { - const currentInput = state.inputs.current; - return currentInput === 'trade' ? getInputErrors(state) : []; -}; - -/** - * @param state - * @returns input errors for Transfer - */ -export const getTransferInputErrors = (state: RootState) => { - const currentInput = state.inputs.current; - return currentInput === 'transfer' ? getInputErrors(state) : []; -}; - -/** - * @param state - * @returns TransferInputs - */ -export const getTransferInputs = (state: RootState) => state.inputs.transferInputs; - -/** - * @param state - * @returns ClosePositionInputs - */ -export const getInputClosePositionData = (state: RootState) => state.inputs.closePositionInputs; - -/** - * @returns Data needed for the TradeForm (price, size, summary, input render options, and errors/input validation) - */ -export const useTradeFormData = () => { - return useSelector( - createSelector( - [getInputTradeData, getInputTradeOptions, getTradeInputErrors], - (tradeData, tradeOptions, tradeErrors) => { - const { price, size, summary } = tradeData || {}; - - const { - needsLimitPrice, - needsTrailingPercent, - needsTriggerPrice, - executionOptions, - needsGoodUntil, - needsPostOnly, - needsReduceOnly, - timeInForceOptions, - } = tradeOptions || {}; - - return { - price, - size, - summary, - - needsLimitPrice, - needsTrailingPercent, - needsTriggerPrice, - executionOptions, - needsGoodUntil, - needsPostOnly, - needsReduceOnly, - timeInForceOptions, - - tradeErrors, - }; - } - ), - shallowEqual - ); -}; diff --git a/src/views/forms/AccountManagementForms/DepositForm.tsx b/src/views/forms/AccountManagementForms/DepositForm.tsx index f62d3aa..bc6d97d 100644 --- a/src/views/forms/AccountManagementForms/DepositForm.tsx +++ b/src/views/forms/AccountManagementForms/DepositForm.tsx @@ -197,6 +197,7 @@ export const DepositForm = ({ onDeposit, onError }: DepositFormProps) => { toChainId: TESTNET_CHAIN_ID, fromChainId: chainIdStr || undefined, toAmount: summary?.usdcSize || undefined, + triggeredAt: Date.now(), }); abacusStateManager.clearTransferInputValues(); setFromAmount(''); diff --git a/src/views/forms/AccountManagementForms/WithdrawForm.tsx b/src/views/forms/AccountManagementForms/WithdrawForm.tsx index d2247cb..265ac63 100644 --- a/src/views/forms/AccountManagementForms/WithdrawForm.tsx +++ b/src/views/forms/AccountManagementForms/WithdrawForm.tsx @@ -5,11 +5,7 @@ import type { NumberFormatValues } from 'react-number-format'; import { shallowEqual, useSelector } from 'react-redux'; import { TESTNET_CHAIN_ID } from '@dydxprotocol/v4-client'; -import { - TransferInputField, - TransferInputTokenResource, - TransferType, -} from '@/constants/abacus'; +import { TransferInputField, TransferInputTokenResource, TransferType } from '@/constants/abacus'; import { AlertType } from '@/constants/alerts'; import { ButtonAction, ButtonSize, ButtonType } from '@/constants/buttons'; import { STRING_KEYS } from '@/constants/localization'; @@ -135,17 +131,18 @@ export const WithdrawForm = () => { setIsLoading(true); const txHash = await sendSquidWithdraw(debouncedAmountBN.toNumber(), requestPayload?.data); - + if (txHash?.hash) { const hash = `0x${Buffer.from(txHash.hash).toString('hex')}`; - + setTransactionHash(hash); - + addTransferNotification({ txHash: hash, fromChainId: TESTNET_CHAIN_ID, toChainId: chainIdStr || undefined, toAmount: debouncedAmountBN.toNumber(), + triggeredAt: Date.now(), }); abacusStateManager.clearTransferInputValues(); setWithdrawAmount(''); @@ -304,17 +301,7 @@ export const WithdrawForm = () => { } /> - {errorMessage ? ( - {errorMessage} - ) : ( - transactionHash && ( - - - {stringGetter({ key: STRING_KEYS.WITHDRAW_IN_PROGRESS })} - - - ) - )} + {errorMessage && {errorMessage}}