Skip to content

Commit

Permalink
Read redux rehydration data from react-query cache
Browse files Browse the repository at this point in the history
  • Loading branch information
jinchung committed Oct 13, 2023
1 parent 294d595 commit fe5e96f
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/redux/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ import {
saveLocalPendingTransactions,
saveLocalTransactions,
} from '@/handlers/localstorage/accountLocal';
import { getProviderForNetwork, web3Provider } from '@/handlers/web3';
import {
getCachedProviderForNetwork,
getProviderForNetwork,
isHardHat,
web3Provider,
} from '@/handlers/web3';
import WalletTypes from '@/helpers/walletTypes';
import { Navigation } from '@/navigation';
import { triggerOnSwipeLayout } from '@/navigation/onNavigationStateChange';
Expand All @@ -47,6 +52,8 @@ import {
import { SwapType } from '@rainbow-me/swaps';
import { logger as loggr } from '@/logger';
import { queryClient } from '@/react-query';
import { RainbowAddressAssets } from '@/resources/assets/types';
import { userAssetsQueryKey } from '@/resources/assets/UserAssetsQuery';
import { nftsQueryKey } from '@/resources/nfts';

const BACKUP_SHEET_DELAY_MS = android ? 10000 : 3000;
Expand Down Expand Up @@ -354,7 +361,32 @@ export const dataLoadState = () => async (
>,
getState: AppGetState
) => {
const { accountAddress, network } = getState().settings;
const { accountAddress, nativeCurrency, network } = getState().settings;

const provider = getCachedProviderForNetwork(network);
const providerUrl = provider?.connection?.url;
const connectedToHardhat = isHardHat(providerUrl);

const userAssetsObj:
| RainbowAddressAssets
| undefined = queryClient.getQueryData(
userAssetsQueryKey({
address: accountAddress,
connectedToHardhat,
currency: nativeCurrency,
})
);
if (userAssetsObj) {
dispatch({
payload: userAssetsObj,
type: DATA_LOAD_ACCOUNT_ASSETS_DATA_SUCCESS,
});
} else {
dispatch({
type: DATA_LOAD_ACCOUNT_ASSETS_DATA_FAILURE,
});
}

try {
dispatch({ type: DATA_LOAD_TRANSACTIONS_REQUEST });
const transactions = await getLocalTransactions(accountAddress, network);
Expand Down

0 comments on commit fe5e96f

Please sign in to comment.