Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions apps/main/src/dex/components/PageRouterSwap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ const QuickSwap = ({
const isSubscribed = useRef(false)
const { signerAddress } = curve ?? {}
const { tokensNameMapper } = useTokensNameMapper(chainId)
const tokenList = useStore((state) => state.quickSwap.tokenList[chainId])
const activeKey = useStore((state) => state.quickSwap.activeKey)
const formEstGas = useStore((state) => state.quickSwap.formEstGas[activeKey])
const formStatus = useStore((state) => state.quickSwap.formStatus)
Expand All @@ -84,7 +83,6 @@ const QuickSwap = ({
const fetchStepSwap = useStore((state) => state.quickSwap.fetchStepSwap)
const resetFormErrors = useStore((state) => state.quickSwap.resetFormErrors)
const setFormValues = useStore((state) => state.quickSwap.setFormValues)
const updateTokenList = useStore((state) => state.quickSwap.updateTokenList)
const { data: networks } = useNetworks()
const network = (chainId && networks[chainId]) || null

Expand Down Expand Up @@ -119,15 +117,14 @@ const QuickSwap = ({
.map(([address]) => address)
const { data: usdRatesMapper } = useTokenUsdRates({ chainId, tokenAddresses: userTokens })

const tokens = useMemo(() => {
if (lodash.isEmpty(tokenList) || lodash.isEmpty(tokensMapper)) return []

return tokenList!
.map((address) => tokensMapper[address])
.filter((token) => !!token)
.map(toTokenOption(network?.networkId))
const tokens = useMemo(
() =>
Object.values(tokensMapper ?? {})
.filter((token) => !!token)
.map(toTokenOption(network?.networkId)),
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [tokenList, tokensMapperStr, network?.networkId])
[tokensMapperStr, network?.networkId],
)

const fromToken = tokens.find((x) => x.address.toLocaleLowerCase() == fromAddress)
const toToken = tokens.find((x) => x.address.toLocaleLowerCase() == toAddress)
Expand Down Expand Up @@ -353,11 +350,6 @@ const QuickSwap = ({
// eslint-disable-next-line react-hooks/exhaustive-deps
useEffect(() => fetchData(), [tokensMapperStr, searchedParams.fromAddress, searchedParams.toAddress])

useEffect(() => {
void updateTokenList(config, isReady ? curve : null, tokensMapper)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [config, isReady, tokensMapperStr, curve?.signerAddress])

// re-fetch data
usePageVisibleInterval(fetchData, REFRESH_INTERVAL['15s'])

Expand Down
22 changes: 1 addition & 21 deletions apps/main/src/dex/store/createQuickSwapSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {
import { DEFAULT_FORM_STATUS, DEFAULT_FORM_VALUES } from '@/dex/components/PageRouterSwap/utils'
import curvejsApi from '@/dex/lib/curvejs'
import type { State } from '@/dex/store/useStore'
import { CurveApi, FnStepApproveResponse, FnStepResponse, TokensMapper } from '@/dex/types/main.types'
import { CurveApi, FnStepApproveResponse, FnStepResponse } from '@/dex/types/main.types'
import { sleep } from '@/dex/utils'
import { getMaxAmountMinusGas } from '@/dex/utils/utilsGasPrices'
import { getSlippageImpact, getSwapActionModalType } from '@/dex/utils/utilsSwap'
Expand All @@ -32,7 +32,6 @@ type SliceState = {
formValues: FormValues
isMaxLoading: boolean
routesAndOutput: { [activeKey: string]: RoutesAndOutput }
tokenList: { [chainSignerActiveKey: string]: string[] | undefined }
}

const sliceKey = 'quickSwap'
Expand Down Expand Up @@ -67,7 +66,6 @@ export type QuickSwapSlice = {

// select token list
setPoolListFormValues(hideSmallPools: boolean): void
updateTokenList(config: Config, curve: CurveApi | null, tokensMapper: TokensMapper): Promise<void>

// steps
fetchStepApprove(
Expand Down Expand Up @@ -101,7 +99,6 @@ const DEFAULT_STATE: SliceState = {
formValues: DEFAULT_FORM_VALUES,
isMaxLoading: false,
routesAndOutput: {},
tokenList: {},
}

const createQuickSwapSlice = (set: StoreApi<State>['setState'], get: StoreApi<State>['getState']): QuickSwapSlice => ({
Expand Down Expand Up @@ -355,23 +352,6 @@ const createQuickSwapSlice = (set: StoreApi<State>['setState'], get: StoreApi<St
storedPoolListFormValues.hideSmallPools = hideSmallPools
get().poolList.setStateByKey('formValues', storedPoolListFormValues)
},
updateTokenList: async (config, curve, tokensMapper) => {
const state = get()
const sliceState = state[sliceKey]

if (!curve || Object.keys(tokensMapper).length === 0) return
const { chainId } = curve

const tokens = Object.entries(tokensMapper)
.map(([_, v]) => v)
.filter((token) => !!token)
.map(({ address }) => address)

sliceState.setStateByActiveKey('tokenList', chainId.toString(), tokens)

// Get user balances
await state.userBalances.fetchUserBalancesByTokens(config, curve, tokens)
},

// steps
fetchStepApprove: async (activeKey, config, curve, formValues, searchedParams, globalMaxSlippage) => {
Expand Down