Skip to content

Commit

Permalink
chore: unify naming of trade input actions and selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
woodenfurniture committed Nov 12, 2024
1 parent e5a4ec0 commit 2b14c3b
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ export const LimitOrderInput = ({
switchAssets,
setSellAsset,
setBuyAsset,
setSellAssetAccountId,
setBuyAssetAccountId,
setSellAccountId,
setBuyAccountId,
setLimitPriceBuyAsset,
setSlippagePreferencePercentage,
setIsInputtingFiatSellAmount,
Expand Down Expand Up @@ -281,14 +281,14 @@ export const LimitOrderInput = ({
onChangeIsInputtingFiatSellAmount={setIsInputtingFiatSellAmount}
onChangeSellAmountCryptoPrecision={setSellAmountCryptoPrecision}
setSellAsset={setSellAsset}
setSellAccountId={setSellAssetAccountId}
setSellAccountId={setSellAccountId}
>
<Stack>
<LimitOrderBuyAsset
asset={buyAsset}
accountId={buyAccountId}
isInputtingFiatSellAmount={isInputtingFiatSellAmount}
onAccountIdChange={setBuyAssetAccountId}
onAccountIdChange={setBuyAccountId}
onSetBuyAsset={setBuyAsset}
/>
<Divider />
Expand All @@ -315,12 +315,12 @@ export const LimitOrderInput = ({
sellAmountCryptoPrecision,
sellAsset,
setBuyAsset,
setBuyAssetAccountId,
setBuyAccountId,
setIsInputtingFiatSellAmount,
setLimitPriceBuyAsset,
setSellAmountCryptoPrecision,
setSellAsset,
setSellAssetAccountId,
setSellAccountId,
switchAssets,
])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { useIsManualReceiveAddressRequired } from 'components/MultiHopTrade/hook
import { useReceiveAddress } from 'components/MultiHopTrade/hooks/useReceiveAddress'
import { limitOrderInput } from 'state/slices/limitOrderInputSlice/limitOrderInputSlice'
import {
selectIsManualReceiveAddressEditing,
selectIsManualReceiveAddressValid,
selectIsManualReceiveAddressValidating,
selectManualReceiveAddress,
selectManualReceiveAddressIsEditing,
selectManualReceiveAddressIsValid,
selectManualReceiveAddressIsValidating,
} from 'state/slices/limitOrderInputSlice/selectors'
import { useAppDispatch, useAppSelector } from 'state/store'

Expand All @@ -28,9 +28,9 @@ export const useLimitOrderRecipientAddress = ({
const dispatch = useAppDispatch()

const manualReceiveAddress = useAppSelector(selectManualReceiveAddress)
const isManualReceiveAddressValid = useAppSelector(selectManualReceiveAddressIsValid)
const isManualReceiveAddressEditing = useAppSelector(selectManualReceiveAddressIsEditing)
const isManualReceiveAddressValidating = useAppSelector(selectManualReceiveAddressIsValidating)
const isManualReceiveAddressValid = useAppSelector(selectIsManualReceiveAddressValid)
const isManualReceiveAddressEditing = useAppSelector(selectIsManualReceiveAddressEditing)
const isManualReceiveAddressValidating = useAppSelector(selectIsManualReceiveAddressValidating)

const { walletReceiveAddress, isLoading: isWalletReceiveAddressLoading } = useReceiveAddress({
sellAccountId,
Expand All @@ -43,40 +43,40 @@ export const useLimitOrderRecipientAddress = ({
}, [dispatch])

const handleEditManualReceiveAddress = useCallback(() => {
dispatch(limitOrderInput.actions.setManualReceiveAddressIsEditing(true))
dispatch(limitOrderInput.actions.setIsManualReceiveAddressEditing(true))
}, [dispatch])

const handleCancelManualReceiveAddress = useCallback(() => {
dispatch(limitOrderInput.actions.setManualReceiveAddressIsEditing(false))
dispatch(limitOrderInput.actions.setIsManualReceiveAddressEditing(false))
// Reset form value and valid state on cancel so the valid check doesn't wrongly evaluate to false after bailing out of editing an invalid address
dispatch(limitOrderInput.actions.setManualReceiveAddressIsValid(undefined))
dispatch(limitOrderInput.actions.setIsManualReceiveAddressValid(undefined))
}, [dispatch])

const handleResetManualReceiveAddress = useCallback(() => {
// Reset the manual receive address in store
dispatch(limitOrderInput.actions.setManualReceiveAddress(undefined))
// Reset the valid state in store
dispatch(limitOrderInput.actions.setManualReceiveAddressIsValid(undefined))
dispatch(limitOrderInput.actions.setIsManualReceiveAddressValid(undefined))
}, [dispatch])

const handleSubmitManualReceiveAddress = useCallback(
(address: string) => {
dispatch(limitOrderInput.actions.setManualReceiveAddress(address))
dispatch(limitOrderInput.actions.setManualReceiveAddressIsEditing(false))
dispatch(limitOrderInput.actions.setIsManualReceiveAddressEditing(false))
},
[dispatch],
)

const handleIsManualReceiveAddressValidatingChange = useCallback(
(isValidating: boolean) => {
dispatch(limitOrderInput.actions.setManualReceiveAddressIsValidating(isValidating))
dispatch(limitOrderInput.actions.setIsManualReceiveAddressValidating(isValidating))
},
[dispatch],
)

const handleIsManualReceiveAddressValidChange = useCallback(
(isValid: boolean) => {
dispatch(limitOrderInput.actions.setManualReceiveAddressIsValid(isValid))
dispatch(limitOrderInput.actions.setIsManualReceiveAddressValid(isValid))
},
[dispatch],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import {
selectInputBuyAsset,
selectInputSellAmountUsd,
selectInputSellAsset,
selectManualReceiveAddressIsEditing,
selectManualReceiveAddressIsValid,
selectManualReceiveAddressIsValidating,
selectIsManualReceiveAddressEditing,
selectIsManualReceiveAddressValid,
selectIsManualReceiveAddressValidating,
} from 'state/slices/selectors'
import {
selectActiveQuote,
Expand Down Expand Up @@ -83,9 +83,9 @@ export const ConfirmSummary = ({

const buyAmountAfterFeesCryptoPrecision = useAppSelector(selectBuyAmountAfterFeesCryptoPrecision)
const totalNetworkFeeFiatPrecision = useAppSelector(selectTotalNetworkFeeUserCurrencyPrecision)
const isManualReceiveAddressValidating = useAppSelector(selectManualReceiveAddressIsValidating)
const isManualReceiveAddressEditing = useAppSelector(selectManualReceiveAddressIsEditing)
const isManualReceiveAddressValid = useAppSelector(selectManualReceiveAddressIsValid)
const isManualReceiveAddressValidating = useAppSelector(selectIsManualReceiveAddressValidating)
const isManualReceiveAddressEditing = useAppSelector(selectIsManualReceiveAddressEditing)
const isManualReceiveAddressValid = useAppSelector(selectIsManualReceiveAddressValid)
const slippagePercentageDecimal = useAppSelector(selectTradeSlippagePercentageDecimal)
const totalProtocolFees = useAppSelector(selectTotalProtocolFeeByAsset)
const activeQuoteErrors = useAppSelector(selectActiveQuoteErrors)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ export const RecipientAddress = ({

const handleIsValidatingChange = useCallback(
(isValidating: boolean) => {
dispatch(tradeInput.actions.setManualReceiveAddressIsValidating(isValidating))
dispatch(tradeInput.actions.setIsManualReceiveAddressValidating(isValidating))
},
[dispatch],
)

const handleIsValidChange = useCallback(
(isValid: boolean) => {
dispatch(tradeInput.actions.setManualReceiveAddressIsValid(isValid))
dispatch(tradeInput.actions.setIsManualReceiveAddressValid(isValid))
},
[dispatch],
)
Expand All @@ -46,26 +46,26 @@ export const RecipientAddress = ({
}, [dispatch])

const handleEdit = useCallback(() => {
dispatch(tradeInput.actions.setManualReceiveAddressIsEditing(true))
dispatch(tradeInput.actions.setIsManualReceiveAddressEditing(true))
}, [dispatch])

const handleCancel = useCallback(() => {
dispatch(tradeInput.actions.setManualReceiveAddressIsEditing(false))
dispatch(tradeInput.actions.setIsManualReceiveAddressEditing(false))
// Reset form value and valid state on cancel so the valid check doesn't wrongly evaluate to false after bailing out of editing an invalid address
dispatch(tradeInput.actions.setManualReceiveAddressIsValid(undefined))
dispatch(tradeInput.actions.setIsManualReceiveAddressValid(undefined))
}, [dispatch])

const handleReset = useCallback(() => {
// Reset the manual receive address in store
dispatch(tradeInput.actions.setManualReceiveAddress(undefined))
// Reset the valid state in store
dispatch(tradeInput.actions.setManualReceiveAddressIsValid(undefined))
dispatch(tradeInput.actions.setIsManualReceiveAddressValid(undefined))
}, [dispatch])

const handleSubmit = useCallback(
(address: string) => {
dispatch(tradeInput.actions.setManualReceiveAddress(address))
dispatch(tradeInput.actions.setManualReceiveAddressIsEditing(false))
dispatch(tradeInput.actions.setIsManualReceiveAddressEditing(false))
},
[dispatch],
)
Expand Down
4 changes: 2 additions & 2 deletions src/components/MultiHopTrade/hooks/useAccountIds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ export const useAccountIds = (): {

const setSellAssetAccountId = useCallback(
(accountId: AccountId | undefined) => {
dispatch(tradeInput.actions.setSellAssetAccountId(accountId))
dispatch(tradeInput.actions.setSellAccountId(accountId))
},
[dispatch],
)

const setBuyAssetAccountId = useCallback(
(accountId: AccountId | undefined) => {
dispatch(tradeInput.actions.setBuyAssetAccountId(accountId))
dispatch(tradeInput.actions.setBuyAccountId(accountId))
},
[dispatch],
)
Expand Down
4 changes: 2 additions & 2 deletions src/context/AppProvider/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {
if (!prevWalletId) return
if (walletId === prevWalletId) return

dispatch(tradeInput.actions.setSellAssetAccountId(undefined))
dispatch(tradeInput.actions.setBuyAssetAccountId(undefined))
dispatch(tradeInput.actions.setSellAccountId(undefined))
dispatch(tradeInput.actions.setBuyAccountId(undefined))
}, [dispatch, prevWalletId, walletId])

const marketDataPollingInterval = 60 * 15 * 1000 // refetch data every 15 minutes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const createTradeInputBaseSelectors = <T extends TradeInputBaseState>(
selectEnabledWalletAccountIds,
(baseSlice, sellAsset, accountIdAssetValues, accountIds) => {
// return the users selection if it exists
if (baseSlice.sellAssetAccountId) return baseSlice.sellAssetAccountId
if (baseSlice.sellAccountId) return baseSlice.sellAccountId

const highestFiatBalanceSellAccountId = getHighestUserCurrencyBalanceAccountByAssetId(
accountIdAssetValues,
Expand Down Expand Up @@ -134,8 +134,8 @@ export const createTradeInputBaseSelectors = <T extends TradeInputBaseState>(
accountMetadata,
) => {
// return the users selection if it exists
if (baseSlice.buyAssetAccountId) {
return baseSlice.buyAssetAccountId
if (baseSlice.buyAccountId) {
return baseSlice.buyAccountId
}

// maybe convert the account id to an account number
Expand Down Expand Up @@ -175,19 +175,19 @@ export const createTradeInputBaseSelectors = <T extends TradeInputBaseState>(
baseSlice => baseSlice.manualReceiveAddress,
)

const selectManualReceiveAddressIsValidating = createSelector(
const selectIsManualReceiveAddressValidating = createSelector(
selectBaseSlice,
baseSlice => baseSlice.manualReceiveAddressIsValidating,
baseSlice => baseSlice.isManualReceiveAddressValidating,
)

const selectManualReceiveAddressIsEditing = createSelector(
const selectIsManualReceiveAddressEditing = createSelector(
selectBaseSlice,
baseSlice => baseSlice.manualReceiveAddressIsEditing,
baseSlice => baseSlice.isManualReceiveAddressEditing,
)

const selectManualReceiveAddressIsValid = createSelector(
const selectIsManualReceiveAddressValid = createSelector(
selectBaseSlice,
baseSlice => baseSlice.manualReceiveAddressIsValid,
baseSlice => baseSlice.isManualReceiveAddressValid,
)

const selectInputSellAmountUsd = createSelector(
Expand Down Expand Up @@ -241,9 +241,9 @@ export const createTradeInputBaseSelectors = <T extends TradeInputBaseState>(
selectBuyAccountId,
selectInputSellAmountCryptoBaseUnit,
selectManualReceiveAddress,
selectManualReceiveAddressIsValidating,
selectManualReceiveAddressIsEditing,
selectManualReceiveAddressIsValid,
selectIsManualReceiveAddressValidating,
selectIsManualReceiveAddressEditing,
selectIsManualReceiveAddressValid,
selectInputSellAmountUsd,
selectInputSellAmountUserCurrency,
selectSellAssetBalanceCryptoBaseUnit,
Expand Down
40 changes: 20 additions & 20 deletions src/state/slices/common/tradeInputBase/createTradeInputBaseSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { bnOrZero } from 'lib/bignumber/bignumber'
export interface TradeInputBaseState {
buyAsset: Asset
sellAsset: Asset
sellAssetAccountId: AccountId | undefined
buyAssetAccountId: AccountId | undefined
sellAccountId: AccountId | undefined
buyAccountId: AccountId | undefined
sellAmountCryptoPrecision: string
isInputtingFiatSellAmount: boolean
manualReceiveAddress: string | undefined
manualReceiveAddressIsValidating: boolean
manualReceiveAddressIsEditing: boolean
manualReceiveAddressIsValid: boolean | undefined
isManualReceiveAddressValidating: boolean
isManualReceiveAddressEditing: boolean
isManualReceiveAddressValid: boolean | undefined
slippagePreferencePercentage: string | undefined
}

Expand Down Expand Up @@ -57,7 +57,7 @@ export function createTradeInputBaseSlice<
}

if (asset.chainId !== state.buyAsset.chainId) {
state.buyAssetAccountId = undefined
state.buyAccountId = undefined
}

state.manualReceiveAddress = undefined
Expand All @@ -74,17 +74,17 @@ export function createTradeInputBaseSlice<
state.sellAmountCryptoPrecision = '0'

if (asset.chainId !== state.sellAsset.chainId) {
state.sellAssetAccountId = undefined
state.sellAccountId = undefined
}

state.manualReceiveAddress = undefined
state.sellAsset = action.payload
},
setSellAssetAccountId: (state, action: PayloadAction<AccountId | undefined>) => {
state.sellAssetAccountId = action.payload
setSellAccountId: (state, action: PayloadAction<AccountId | undefined>) => {
state.sellAccountId = action.payload
},
setBuyAssetAccountId: (state, action: PayloadAction<AccountId | undefined>) => {
state.buyAssetAccountId = action.payload
setBuyAccountId: (state, action: PayloadAction<AccountId | undefined>) => {
state.buyAccountId = action.payload
},
setSellAmountCryptoPrecision: (state, action: PayloadAction<string>) => {
state.sellAmountCryptoPrecision = bnOrZero(action.payload).toString()
Expand All @@ -95,23 +95,23 @@ export function createTradeInputBaseSlice<
state.buyAsset = buyAsset
state.sellAmountCryptoPrecision = '0'

const sellAssetAccountId = state.sellAssetAccountId
state.sellAssetAccountId = state.buyAssetAccountId
state.buyAssetAccountId = sellAssetAccountId
const sellAssetAccountId = state.sellAccountId
state.sellAccountId = state.buyAccountId
state.buyAccountId = sellAssetAccountId

state.manualReceiveAddress = undefined
},
setManualReceiveAddress: (state, action: PayloadAction<string | undefined>) => {
state.manualReceiveAddress = action.payload
},
setManualReceiveAddressIsValidating: (state, action: PayloadAction<boolean>) => {
state.manualReceiveAddressIsValidating = action.payload
setIsManualReceiveAddressValidating: (state, action: PayloadAction<boolean>) => {
state.isManualReceiveAddressValidating = action.payload
},
setManualReceiveAddressIsEditing: (state, action: PayloadAction<boolean>) => {
state.manualReceiveAddressIsEditing = action.payload
setIsManualReceiveAddressEditing: (state, action: PayloadAction<boolean>) => {
state.isManualReceiveAddressEditing = action.payload
},
setManualReceiveAddressIsValid: (state, action: PayloadAction<boolean | undefined>) => {
state.manualReceiveAddressIsValid = action.payload
setIsManualReceiveAddressValid: (state, action: PayloadAction<boolean | undefined>) => {
state.isManualReceiveAddressValid = action.payload
},
setIsInputtingFiatSellAmount: (state, action: PayloadAction<boolean>) => {
state.isInputtingFiatSellAmount = action.payload
Expand Down
10 changes: 5 additions & 5 deletions src/state/slices/limitOrderInputSlice/limitOrderInputSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ export type LimitOrderInputState = { limitPriceBuyAsset: string } & TradeInputBa
const initialState: LimitOrderInputState = {
buyAsset: localAssetData[foxAssetId] ?? defaultAsset,
sellAsset: localAssetData[usdcAssetId] ?? defaultAsset,
sellAssetAccountId: undefined,
buyAssetAccountId: undefined,
sellAccountId: undefined,
buyAccountId: undefined,
sellAmountCryptoPrecision: '0',
isInputtingFiatSellAmount: false,
manualReceiveAddress: undefined,
manualReceiveAddressIsValidating: false,
manualReceiveAddressIsValid: undefined,
manualReceiveAddressIsEditing: false,
isManualReceiveAddressValidating: false,
isManualReceiveAddressValid: undefined,
isManualReceiveAddressEditing: false,
slippagePreferencePercentage: undefined,
limitPriceBuyAsset: '0',
}
Expand Down
6 changes: 3 additions & 3 deletions src/state/slices/limitOrderInputSlice/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export const {
selectBuyAccountId,
selectInputSellAmountCryptoBaseUnit,
selectManualReceiveAddress,
selectManualReceiveAddressIsValidating,
selectManualReceiveAddressIsEditing,
selectManualReceiveAddressIsValid,
selectIsManualReceiveAddressValidating,
selectIsManualReceiveAddressEditing,
selectIsManualReceiveAddressValid,
selectInputSellAmountUsd,
selectInputSellAmountUserCurrency,
selectSellAssetBalanceCryptoBaseUnit,
Expand Down
Loading

0 comments on commit 2b14c3b

Please sign in to comment.