Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User assets migration #6038

Merged
merged 67 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
8ded594
ditching this for later
benisgold Aug 19, 2024
551eb15
done
benisgold Aug 19, 2024
311ecac
change userAssetsStoreCache type
benisgold Aug 20, 2024
8d450ab
Merge branch 'develop' of https://github.com/rainbow-me/rainbow into …
benisgold Aug 20, 2024
84f6f39
mid refactor
benisgold Aug 20, 2024
5eb757b
refactor
benisgold Aug 20, 2024
7b7f338
Merge branch 'develop' of https://github.com/rainbow-me/rainbow into …
benisgold Aug 20, 2024
ea21a34
dont cast to Address
benisgold Aug 22, 2024
963631d
more
benisgold Aug 22, 2024
d262ae0
more
benisgold Aug 22, 2024
469122d
Merge branch 'develop' of https://github.com/rainbow-me/rainbow into …
benisgold Aug 23, 2024
2bf3e6b
Merge branch 'develop' of https://github.com/rainbow-me/rainbow into …
benisgold Aug 23, 2024
4b1a56d
Merge branch '@benisgold/user-assets-refactor' of https://github.com/…
benisgold Aug 23, 2024
22e1fed
remove UserAssetsQuery
benisgold Aug 26, 2024
d9730b3
fix store caching?
benisgold Aug 26, 2024
04e7055
rm address param
benisgold Aug 26, 2024
4be9f3f
Merge branch '@benisgold/user-assets-refactor' of https://github.com/…
benisgold Aug 26, 2024
16d3a1b
merge conflicts
benisgold Aug 26, 2024
2c59494
test cache
benisgold Aug 26, 2024
a4b158c
cleanup
benisgold Aug 26, 2024
5c802b0
fix caching
benisgold Aug 26, 2024
9e3c27f
Merge branch 'develop' of https://github.com/rainbow-me/rainbow into …
benisgold Aug 26, 2024
e603943
Merge branch '@benisgold/user-assets-refactor' of https://github.com/…
benisgold Aug 26, 2024
21918cf
select address
benisgold Aug 27, 2024
34b7da7
Merge branch '@benisgold/user-assets-refactor' of https://github.com/…
benisgold Aug 27, 2024
21a656a
comments
benisgold Aug 27, 2024
65b1b51
Merge branch 'develop' of https://github.com/rainbow-me/rainbow into …
benisgold Aug 27, 2024
1644db1
Merge branch '@benisgold/user-assets-refactor' of https://github.com/…
benisgold Aug 27, 2024
ab65bcc
Merge branch 'develop' of https://github.com/rainbow-me/rainbow into …
benisgold Sep 5, 2024
65951fe
hardhat
benisgold Sep 5, 2024
8a4a1d2
Merge branch 'develop' of https://github.com/rainbow-me/rainbow into …
benisgold Sep 10, 2024
20a73a5
lint
benisgold Sep 10, 2024
774bbad
Merge branch '@benisgold/user-assets-refactor' of https://github.com/…
benisgold Sep 10, 2024
935432c
Merge branch 'develop' of https://github.com/rainbow-me/rainbow into …
benisgold Sep 10, 2024
34b3867
perceived finality
benisgold Sep 10, 2024
4a941f7
address comments
benisgold Sep 10, 2024
c89fb69
Merge branch 'develop' of https://github.com/rainbow-me/rainbow into …
benisgold Sep 16, 2024
89cb191
fixing parser
benisgold Sep 16, 2024
2dd3e4e
lint
benisgold Sep 16, 2024
49b3dfd
Merge branch 'develop' of https://github.com/rainbow-me/rainbow into …
benisgold Sep 16, 2024
3b35feb
comments
benisgold Sep 16, 2024
dd1e301
fix broken assets when switching wallets
benisgold Sep 16, 2024
dc04783
nit
benisgold Sep 16, 2024
3706cfb
Merge branch 'develop' of https://github.com/rainbow-me/rainbow into …
benisgold Sep 16, 2024
93de69f
fix type
benisgold Sep 16, 2024
25beb22
rm unused
benisgold Sep 16, 2024
9e0debe
rm duplicate query invalidation
benisgold Sep 17, 2024
4769829
filter out defi positions from assets queries
benisgold Sep 17, 2024
158ee26
rm duplicate query invalidation
benisgold Sep 17, 2024
c84d2f1
userAssetsCount in store
benisgold Sep 17, 2024
39f7803
rm unused
benisgold Sep 17, 2024
814f75c
fix defi position filtering
benisgold Sep 17, 2024
57b4479
remove userAssetsCount
benisgold Sep 17, 2024
c59c39a
Merge branch 'develop' of https://github.com/rainbow-me/rainbow into …
benisgold Sep 19, 2024
153e842
Merge branch 'develop' of https://github.com/rainbow-me/rainbow into …
benisgold Dec 6, 2024
6e4f95b
cache legacyUserAssets
benisgold Dec 10, 2024
514ac7c
add migration of react query cache data to user assets store to preve…
benisgold Dec 10, 2024
933fd01
fix migration version
benisgold Dec 10, 2024
923142c
replace getUserAssetFromCache usage with userAssetsStore
benisgold Dec 10, 2024
f62cbbf
Merge branch 'develop' of https://github.com/rainbow-me/rainbow into …
benisgold Dec 10, 2024
4bc0fdd
add native asset getter to store + fix claimable native asset
benisgold Dec 10, 2024
9417280
Merge branch 'develop' of https://github.com/rainbow-me/rainbow into …
benisgold Dec 11, 2024
66da19c
memo UserAssetsSync
benisgold Dec 11, 2024
5fa7b01
fix loading state
benisgold Dec 11, 2024
3a341fc
Merge branch 'develop' of https://github.com/rainbow-me/rainbow into …
benisgold Dec 11, 2024
3912ded
Merge branch 'develop' of https://github.com/rainbow-me/rainbow into …
benisgold Dec 12, 2024
8f85eeb
Merge branch 'develop' of https://github.com/rainbow-me/rainbow into …
benisgold Dec 18, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
import { ExtendedAnimatedAssetWithColors } from '@/__swaps__/types/assets';
import { ChainId } from '@/chains/types';
import { ParsedAddressAsset } from '@/entities';
import { useUserNativeNetworkAsset } from '@/resources/assets/useUserAsset';
import { CrosschainQuote, Quote, QuoteError } from '@rainbow-me/swaps';
import { deepEqualWorklet } from '@/worklets/comparisons';
import { debounce } from 'lodash';
Expand All @@ -26,6 +25,9 @@ import { GasSettings } from '../hooks/useCustomGas';
import { useSelectedGas } from '../hooks/useSelectedGas';
import { useSwapEstimatedGasLimit } from '../hooks/useSwapEstimatedGasLimit';
import { useSwapContext } from './swap-provider';
import { useUserAssetsStore } from '@/state/assets/userAssets';
import { getUniqueId } from '@/utils/ethereumUtils';
import { chainsNativeAsset } from '@/chains';

const BUFFER_RATIO = 0.5;

Expand Down Expand Up @@ -143,7 +145,12 @@ export function SyncGasStateToSharedValues() {
const { assetToSell, chainId = initialChainId, quote } = useSyncedSwapQuoteStore();

const gasSettings = useSelectedGas(chainId);
const { data: userNativeNetworkAsset, isLoading: isLoadingNativeNetworkAsset } = useUserNativeNetworkAsset(chainId);

const { userNativeNetworkAsset, isLoadingNativeNetworkAsset } = useUserAssetsStore(state => {
const { address: nativeCurrencyAddress } = chainsNativeAsset[chainId];
const uniqueId = getUniqueId(nativeCurrencyAddress, chainId);
return { userNativeNetworkAsset: state.getLegacyUserAsset(uniqueId), isLoadingNativeNetworkAsset: state.isLoadingUserAssets };
});
const { data: estimatedGasLimit } = useSwapEstimatedGasLimit({ chainId, assetToSell, quote });

const gasFeeRange = useSharedValue<[string, string] | null>(null);
Expand Down
12 changes: 2 additions & 10 deletions src/__swaps__/screens/Swap/providers/swap-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { NavigationSteps, useSwapNavigation } from '@/__swaps__/screens/Swap/hoo
import { useSwapSettings } from '@/__swaps__/screens/Swap/hooks/useSwapSettings';
import { useSwapTextStyles } from '@/__swaps__/screens/Swap/hooks/useSwapTextStyles';
import { SwapWarningType, useSwapWarning } from '@/__swaps__/screens/Swap/hooks/useSwapWarning';
import { userAssetsQueryKey as swapsUserAssetsQueryKey } from '@/__swaps__/screens/Swap/resources/assets/userAssets';
import { userAssetsQueryKey } from '@/__swaps__/screens/Swap/resources/assets/userAssets';
import { AddressOrEth, ExtendedAnimatedAssetWithColors, ParsedSearchAsset } from '@/__swaps__/types/assets';
import { ChainId } from '@/chains/types';
import { SwapAssetType, inputKeys } from '@/__swaps__/types/swap';
Expand All @@ -41,7 +41,6 @@ import Routes from '@/navigation/routesNames';
import { walletExecuteRap } from '@/raps/execute';
import { QuoteTypeMap, RapSwapActionParameters } from '@/raps/references';
import { queryClient } from '@/react-query';
import { userAssetsQueryKey } from '@/resources/assets/UserAssetsQuery';
import { userAssetsStore } from '@/state/assets/userAssets';
import { swapsStore } from '@/state/swaps/swapsStore';
import { haptics } from '@/utils';
Expand Down Expand Up @@ -308,14 +307,7 @@ export const SwapProvider = ({ children }: SwapProviderProps) => {
userAssetsQueryKey({
address: parameters.quote.from,
currency: nativeCurrency,
connectedToHardhat,
})
);
queryClient.invalidateQueries(
swapsUserAssetsQueryKey({
address: parameters.quote.from as Address,
currency: nativeCurrency,
testnetMode: !!connectedToHardhat,
testnetMode: connectedToHardhat,
})
);

Expand Down
28 changes: 15 additions & 13 deletions src/__swaps__/screens/Swap/resources/assets/userAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { fetchUserAssetsByChain } from './userAssetsByChain';
import { fetchHardhatBalancesByChainId } from '@/resources/assets/hardhatAssets';
import { SUPPORTED_CHAIN_IDS } from '@/chains';
import { useConnectedToHardhatStore } from '@/state/connectedToHardhat';
import { staleBalancesStore } from '@/state/staleBalances';
import { IS_TEST } from '@/env';

const addysHttp = new RainbowFetchClient({
baseURL: 'https://addys.p.rainbow.me/v3',
Expand All @@ -27,7 +29,7 @@ const addysHttp = new RainbowFetchClient({

const USER_ASSETS_REFETCH_INTERVAL = 60000;
const USER_ASSETS_TIMEOUT_DURATION = 20000;
export const USER_ASSETS_STALE_INTERVAL = 30000;
const USER_ASSETS_STALE_INTERVAL = 30000;

// ///////////////////////////////////////////////
// Query Types
Expand Down Expand Up @@ -70,7 +72,7 @@ type UserAssetsQueryKey = ReturnType<typeof userAssetsQueryKey>;
// Query Function

export const userAssetsFetchQuery = ({ address, currency, testnetMode }: FetchUserAssetsArgs) => {
queryClient.fetchQuery(userAssetsQueryKey({ address, currency, testnetMode }), userAssetsQueryFunction);
return queryClient.fetchQuery(userAssetsQueryKey({ address, currency, testnetMode }), userAssetsQueryFunction);
};

export const userAssetsSetQueryDefaults = ({ address, currency, staleTime, testnetMode }: SetUserDefaultsArgs) => {
Expand Down Expand Up @@ -109,26 +111,28 @@ async function userAssetsQueryFunction({

return parsedAssetsDict;
}

const cache = queryClient.getQueryCache();
const cachedUserAssets = (cache.find(userAssetsQueryKey({ address, currency, testnetMode }))?.state?.data ||
{}) as ParsedAssetsDictByChain;
try {
const url = `/${SUPPORTED_CHAIN_IDS.join(',')}/${address}/assets`;
staleBalancesStore.getState().clearExpiredData(address);
const staleBalanceParam = staleBalancesStore.getState().getStaleBalancesQueryParam(address);
let url = `/${SUPPORTED_CHAIN_IDS.join(',')}/${address}/assets?currency=${currency.toLowerCase()}`;
if (staleBalanceParam) {
url += staleBalanceParam;
}
const res = await addysHttp.get<AddressAssetsReceivedMessage>(url, {
params: {
currency: currency.toLowerCase(),
},
timeout: USER_ASSETS_TIMEOUT_DURATION,
});
const chainIdsInResponse = res?.data?.meta?.chain_ids || [];
const chainIdsWithErrorsInResponse = res?.data?.meta?.chain_ids_with_errors || [];
const assets = res?.data?.payload?.assets || [];
const assets = res?.data?.payload?.assets?.filter(asset => asset.asset.defi_position === false) || [];
if (address) {
userAssetsQueryFunctionRetryByChain({
address,
chainIds: chainIdsWithErrorsInResponse,
currency,
testnetMode,
});
if (assets.length && chainIdsInResponse.length) {
const parsedAssetsDict = await parseUserAssets({
Expand Down Expand Up @@ -160,17 +164,15 @@ async function userAssetsQueryFunctionRetryByChain({
address,
chainIds,
currency,
testnetMode,
}: {
address: Address | string;
chainIds: ChainId[];
currency: SupportedCurrencyKey;
testnetMode?: boolean;
}) {
try {
const cache = queryClient.getQueryCache();
const cachedUserAssets =
(cache.find(userAssetsQueryKey({ address, currency, testnetMode }))?.state?.data as ParsedAssetsDictByChain) || {};
(cache.find(userAssetsQueryKey({ address, currency, testnetMode: false }))?.state?.data as ParsedAssetsDictByChain) || {};
const retries = [];
for (const chainIdWithError of chainIds) {
retries.push(
Expand All @@ -191,7 +193,7 @@ async function userAssetsQueryFunctionRetryByChain({
cachedUserAssets[values[0].chainId] = parsedAssets;
}
}
queryClient.setQueryData(userAssetsQueryKey({ address, currency, testnetMode }), cachedUserAssets);
queryClient.setQueryData(userAssetsQueryKey({ address, currency, testnetMode: false }), cachedUserAssets);
} catch (e) {
logger.error(new RainbowError('[userAssetsQueryFunctionRetryByChain]: Failed to retry fetching user assets'), {
message: (e as Error)?.message,
Expand Down Expand Up @@ -240,6 +242,6 @@ export function useUserAssets<TSelectResult = UserAssetsResult>(
return useQuery(userAssetsQueryKey({ address, currency, testnetMode: connectedToHardhat }), userAssetsQueryFunction, {
...config,
refetchInterval: USER_ASSETS_REFETCH_INTERVAL,
staleTime: process.env.IS_TESTING === 'true' ? 0 : 1000,
staleTime: IS_TEST ? 0 : USER_ASSETS_STALE_INTERVAL,
});
}
10 changes: 8 additions & 2 deletions src/__swaps__/screens/Swap/resources/assets/userAssetsByChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { RainbowError, logger } from '@/logger';
import { parseUserAssets, userAssetsQueryKey } from './userAssets';
import { RainbowFetchClient } from '@/rainbow-fetch';
import { ADDYS_API_KEY } from 'react-native-dotenv';
import { staleBalancesStore } from '@/state/staleBalances';

const USER_ASSETS_REFETCH_INTERVAL = 60000;

Expand Down Expand Up @@ -66,10 +67,15 @@ export async function userAssetsByChainQueryFunction({
const cachedUserAssets = (cache.find(userAssetsQueryKey({ address, currency }))?.state?.data || {}) as ParsedAssetsDictByChain;
const cachedDataForChain = cachedUserAssets?.[chainId];
try {
const url = `/${chainId}/${address}/assets/?currency=${currency.toLowerCase()}`;
staleBalancesStore.getState().clearExpiredData(address);
const staleBalanceParam = staleBalancesStore.getState().getStaleBalancesQueryParam(address);
let url = `/${chainId}/${address}/assets/?currency=${currency.toLowerCase()}`;
if (staleBalanceParam) {
url += staleBalanceParam;
}
const res = await addysHttp.get<AddressAssetsReceivedMessage>(url);
const chainIdsInResponse = res?.data?.meta?.chain_ids || [];
const assets = res?.data?.payload?.assets || [];
const assets = res?.data?.payload?.assets?.filter(asset => asset.asset.defi_position === false) || [];
if (assets.length && chainIdsInResponse.length) {
const parsedAssetsDict = await parseUserAssets({
assets,
Expand Down
1 change: 1 addition & 0 deletions src/__swaps__/types/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export interface ZerionAsset {
bridgeable: boolean;
networks: { [id in ChainId]?: { bridgeable: boolean } };
};
defi_position?: boolean;
}

// protocols https://github.com/rainbow-me/go-utils-lib/blob/master/pkg/enums/token_type.go#L44
Expand Down
31 changes: 0 additions & 31 deletions src/__swaps__/utils/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,37 +246,6 @@ export function parseUserAssetBalances({
};
}

export function parseParsedUserAsset({
parsedAsset,
currency,
quantity,
}: {
parsedAsset: ParsedUserAsset;
currency: SupportedCurrencyKey;
quantity: string;
}): ParsedUserAsset {
const amount = convertRawAmountToDecimalFormat(quantity, parsedAsset?.decimals);
return {
...parsedAsset,
balance: {
amount,
display: convertAmountToBalanceDisplay(amount, {
decimals: parsedAsset?.decimals,
symbol: parsedAsset?.symbol,
}),
},
native: {
...parsedAsset.native,
balance: getNativeAssetBalance({
currency,
decimals: parsedAsset?.decimals,
priceUnit: parsedAsset?.price?.value || 0,
value: amount,
}),
},
};
}

export const parseSearchAsset = ({
assetWithPrice,
searchAsset,
Expand Down
4 changes: 2 additions & 2 deletions src/components/asset-list/AssetListHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import { StickyHeader } from './RecyclerAssetList2/core/StickyHeaders';
import { useAccountProfile, useDimensions } from '@/hooks';
import { useNavigation } from '@/navigation';
import Routes from '@/navigation/routesNames';
import { useUserAssetCount } from '@/resources/assets/useUserAssetCount';
import styled from '@/styled-thing';
import { fonts, position } from '@/styles';
import { useTheme } from '@/theme';
import * as lang from '@/languages';
import { useUserAssetsStore } from '@/state/assets/userAssets';

export const AssetListHeaderHeight = ListHeaderHeight;

Expand Down Expand Up @@ -104,7 +104,7 @@ const AssetListHeader = ({ contextMenuOptions, isCoinListEdited, title, totalVal
const { width: deviceWidth } = useDimensions();
const { accountName } = useAccountProfile();
const { navigate } = useNavigation();
const { isLoading: isLoadingUserAssets } = useUserAssetCount();
const { isLoadingUserAssets } = useUserAssetsStore(state => state.isLoadingUserAssets);

const onChangeWallet = useCallback(() => {
navigate(Routes.CHANGE_WALLET_SHEET);
Expand Down
4 changes: 2 additions & 2 deletions src/components/list/NoResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { neverRerender } from '@/utils';
import { Inset, Stack, Text } from '@/design-system';
import { useTheme } from '@/theme';
import { logger } from '@/logger';
import { useUserAssetCount } from '@/resources/assets/useUserAssetCount';
import { useUserAssetsStore } from '@/state/assets/userAssets';

export enum NoResultsType {
Discover = 'discover',
Expand All @@ -14,7 +14,7 @@ export enum NoResultsType {

export const NoResults = ({ onL2, type }: { onL2?: boolean; type: NoResultsType }) => {
const { colors } = useTheme();
const { data: assetCount } = useUserAssetCount();
const assetCount = useUserAssetsStore(state => state.userAssetsCount);

let title;
let description;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { selectorFilterByUserChains, selectUserAssetsList } from '@/__swaps__/screens/Swap/resources/_selectors/assets';
import { userAssetsFetchQuery } from '@/__swaps__/screens/Swap/resources/assets/userAssets';
import store from '@/redux/store';
import { fetchUserAssets } from '@/resources/assets/UserAssetsQuery';
import { useConnectedToHardhatStore } from '@/state/connectedToHardhat';

export const hasNonZeroTotalBalance = async (): Promise<boolean> => {
const { accountAddress, nativeCurrency } = store.getState().settings;

const assets = await fetchUserAssets({
const userAssetsDictByChain = await userAssetsFetchQuery({
address: accountAddress,
currency: nativeCurrency,
connectedToHardhat: false,
testnetMode: useConnectedToHardhatStore.getState().connectedToHardhat,
});

if (!assets || Object.keys(assets).length === 0) return false;
const assets = selectorFilterByUserChains({ data: userAssetsDictByChain, selector: selectUserAssetsList });

return Object.values(assets).some(asset => Number(asset.balance?.amount) > 0);
if (!assets?.length) return false;

return assets.some(asset => Number(asset.balance?.amount) > 0);
};
2 changes: 1 addition & 1 deletion src/entities/tokens.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EthereumAddress } from '.';
import { Chain } from '@wagmi/chains';
import { Network, ChainId } from '@/chains/types';
import { ChainId } from '@/chains/types';
import { TokenColors } from '@/graphql/__generated__/metadata';

export interface ZerionAssetPrice {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/buildWalletSections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ const withBriefBalanceSection = (
type: 'PROFILE_NAME_ROW_SPACE_AFTER',
uid: 'profile-name-space-after',
},
...(!hasTokens && !isLoadingUserAssets && !isLoadingBalance
...(!hasTokens && !isLoadingBalance
? []
: [
{
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useAccountAsset.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { NativeCurrencyKey } from '@/entities';
import useAccountSettings from './useAccountSettings';
import { parseAssetNative } from '@/parsers';
import { useUserAsset } from '@/resources/assets/useUserAsset';
import { useUserAssetsStore } from '@/state/assets/userAssets';

// this is meant to be used for assets contained in the current wallet
export default function useAccountAsset(uniqueId: string, nativeCurrency: NativeCurrencyKey | undefined = undefined) {
const { data: accountAsset } = useUserAsset(uniqueId);
const accountAsset = useUserAssetsStore(state => state.getLegacyUserAsset(uniqueId));

// this is temporary for FastBalanceCoinRow to make a tiny bit faster
// we pass nativeCurrency only in that case
Expand Down
6 changes: 2 additions & 4 deletions src/hooks/useRefreshAccountData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import useAccountSettings from './useAccountSettings';
import { PROFILES, useExperimentalFlag } from '@/config';
import { logger, RainbowError } from '@/logger';
import { queryClient } from '@/react-query';
import { userAssetsQueryKey } from '@/resources/assets/UserAssetsQuery';
import { userAssetsQueryKey as swapsUserAssetsQueryKey } from '@/__swaps__/screens/Swap/resources/assets/userAssets';
import { userAssetsQueryKey } from '@/__swaps__/screens/Swap/resources/assets/userAssets';
import { nftsQueryKey } from '@/resources/nfts';
import { positionsQueryKey } from '@/resources/defi/PositionsQuery';
import useNftSort from './useNFTsSortBy';
Expand Down Expand Up @@ -38,9 +37,8 @@ export default function useRefreshAccountData() {
queryClient.invalidateQueries(positionsQueryKey({ address: accountAddress as Address, currency: nativeCurrency }));
queryClient.invalidateQueries(claimablesQueryKey({ address: accountAddress, currency: nativeCurrency }));
queryClient.invalidateQueries(addysSummaryQueryKey({ addresses: allAddresses, currency: nativeCurrency }));
queryClient.invalidateQueries(userAssetsQueryKey({ address: accountAddress, currency: nativeCurrency, connectedToHardhat }));
queryClient.invalidateQueries(
swapsUserAssetsQueryKey({ address: accountAddress as Address, currency: nativeCurrency, testnetMode: !!connectedToHardhat })
userAssetsQueryKey({ address: accountAddress, currency: nativeCurrency, testnetMode: connectedToHardhat })
);

try {
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useSwappableUserAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import { SwappableAsset } from '@/entities';
import { walletFilter } from '@/handlers/tokenSearch';
import { useCoinListEditOptions } from '@/hooks';
import { ETH_ADDRESS } from '@/references';
import { useSortedUserAssets } from '@/resources/assets/useSortedUserAssets';
import { EthereumAddress, ETH_ADDRESS as ETH_ADDRESS_AGGREGATORS } from '@rainbow-me/swaps';
import { useCallback, useEffect, useMemo, useRef } from 'react';
import { useUserAssetsStore } from '@/state/assets/userAssets';
import { ChainId } from '@/chains/types';
import { supportedSwapChainIds } from '@/chains';

type SwappableAddresses = Record<ChainId, EthereumAddress[]>;

export const useSwappableUserAssets = (params: { outputCurrency: SwappableAsset }) => {
const { outputCurrency } = params;
const { data: sortedAssets } = useSortedUserAssets();
const sortedAssets = useUserAssetsStore(state => state.legacyUserAssets);
const assetsInWallet = sortedAssets as SwappableAsset[];
const { hiddenCoinsObj } = useCoinListEditOptions();

Expand Down
Loading
Loading