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

Fix refresh persistence bug #5112

Merged
merged 11 commits into from
Oct 13, 2023
5 changes: 1 addition & 4 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ import {
persistOptions,
queryClient,
} from './react-query';
import { additionalDataUpdateL2AssetBalance } from './redux/additionalAssetsData';
import store from './redux/store';
import { uniswapPairsInit } from './redux/uniswap';
import { walletConnectLoadState } from './redux/walletconnect';
Expand Down Expand Up @@ -243,9 +242,7 @@ class OldApp extends Component {
setTimeout(() => {
logger.debug('Reloading balances for network', network);
if (isL2) {
if (tx.internalType === TransactionType.trade) {
store.dispatch(additionalDataUpdateL2AssetBalance(tx));
} else if (tx.internalType !== TransactionType.authorize) {
if (tx.internalType !== TransactionType.authorize) {
// for swaps, we don't want to trigger update balances on unlock txs
queryClient.invalidateQueries({
queryKey: userAssetsQueryKey({
Expand Down
38 changes: 0 additions & 38 deletions src/handlers/localstorage/accountLocal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ import { getAccountLocal, getKey, saveAccountLocal } from './common';
import { ENSRegistrations } from '@/entities';
import { STORAGE_IDS } from '@/model/mmkv';

const accountAssetsDataVersion = '0.2.0';
const assetsVersion = '0.3.0';
const pendingTransactionsVersion = '0.1.0';
const purchaseTransactionsVersion = '0.2.0';
const transactionsVersion = '0.3.0';
const uniqueTokensVersion = '0.2.1';

const ACCOUNT_ASSETS_DATA = 'accountAssetsData';
const ACCOUNT_INFO = 'accountInfo';
const ACCOUNT_EMPTY = 'accountEmpty';
const ASSETS = 'assets';
Expand All @@ -30,7 +28,6 @@ const storage = new MMKV({
});

export const accountLocalKeys = [
ACCOUNT_ASSETS_DATA,
ACCOUNT_INFO,
ASSETS,
ENS_REGISTRATIONS,
Expand Down Expand Up @@ -73,41 +70,6 @@ export const saveAccountEmptyState = (
export const getAssets = (accountAddress: any, network: any) =>
getAccountLocal(ASSETS, accountAddress, network, [], assetsVersion);

/**
* @desc get account assets data
* @param {String} [address]
* @param {String} [network]
* @return {Object}
*/
export const getAccountAssetsData = (accountAddress: any, network: any) =>
getAccountLocal(
ACCOUNT_ASSETS_DATA,
accountAddress,
network,
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type '{}' is not assignable to paramet... Remove this comment to see the full error message
{},
accountAssetsDataVersion
);

/**
* @desc save account assets data
* @param {Object} [accountAssetsData]
* @param {String} [address]
* @param {String} [network]
*/
export const saveAccountAssetsData = (
accountAssetsData: any,
accountAddress: any,
network: any
) =>
saveAccountLocal(
ACCOUNT_ASSETS_DATA,
accountAssetsData,
accountAddress,
network,
accountAssetsDataVersion
);

/**
* @desc get purchase transactions
* @param {String} [address]
Expand Down
22 changes: 3 additions & 19 deletions src/helpers/RainbowContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,10 @@ import {
// @ts-ignore
IS_TESTING,
} from 'react-native-dotenv';
import { getProviderForNetwork, web3SetHttpProvider } from '@/handlers/web3';
import { web3SetHttpProvider } from '@/handlers/web3';
import { logger, RainbowError } from '@/logger';
import networkTypes, { Network } from '@/helpers/networkTypes';
import networkTypes from '@/helpers/networkTypes';
import { explorerInit } from '@/redux/explorer';
import { ethereumUtils } from '@/utils';
import { ETH_ADDRESS } from '@/references';
import store from '@/redux/store';
import { useUpdateAssetOnchainBalance } from '@/hooks';
import { Navigation } from '@/navigation';
import Routes from '@rainbow-me/routes';

Expand Down Expand Up @@ -93,7 +89,6 @@ export default function RainbowContextWrapper({ children }: PropsWithChildren) {
const { isDarkMode, setTheme, colors } = useTheme();

const dispatch = useDispatch();
const updateAssetOnchainBalanceIfNeeded = useUpdateAssetOnchainBalance();

const connectToHardhat = useCallback(async () => {
try {
Expand All @@ -111,18 +106,7 @@ export default function RainbowContextWrapper({ children }: PropsWithChildren) {
}
dispatch(explorerInit());
Navigation.handleAction(Routes.WALLET_SCREEN, {});

const { accountAddress } = store.getState().settings;
const provider = await getProviderForNetwork(Network.mainnet);
const ethAsset = ethereumUtils.getAccountAsset(ETH_ADDRESS);
updateAssetOnchainBalanceIfNeeded(
ethAsset,
accountAddress,
Network.mainnet,
provider,
() => {}
);
}, [dispatch, updateAssetOnchainBalanceIfNeeded]);
}, [dispatch]);

return (
<RainbowContext.Provider value={initialValue}>
Expand Down
1 change: 0 additions & 1 deletion src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ export { default as useTimeout } from './useTimeout';
export { default as useTransactionConfirmation } from './useTransactionConfirmation';
export { default as usePendingTransactions } from './usePendingTransactions';
export { default as useAssetsInWallet } from './useAssetsInWallet';
export { default as useUpdateAssetOnchainBalance } from './useUpdateAssetOnchainBalance';
export { default as useUserAccounts } from './useUserAccounts';
export { default as useUserLists } from './useUserLists';
export { default as useWalletBalances } from './useWalletBalances';
Expand Down
43 changes: 0 additions & 43 deletions src/hooks/useUpdateAssetOnchainBalance.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/raps/actions/crosschainSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import store from '@/redux/store';
import { ethereumUtils } from '@/utils';
import logger from '@/utils/logger';
import { estimateCrosschainSwapGasLimit } from '@/handlers/swap';
import { additionalDataUpdateL2AssetToWatch } from '@/redux/additionalAssetsData';
import { swapMetadataStorage } from './swap';
import { REFERRER } from '@/references';
import { overrideWithFastSpeedIfNeeded } from '../utils';
Expand Down Expand Up @@ -136,17 +135,6 @@ const crosschainSwap = async (

// @ts-ignore
swap = await executeCrosschainSwap(swapParams);
if (swap?.hash) {
dispatch(
additionalDataUpdateL2AssetToWatch({
hash: swap?.hash,
inputCurrency,
network: ethereumUtils.getNetworkFromChainId(Number(chainId)),
outputCurrency,
userAddress: accountAddress,
})
);
}
} catch (e) {
logger.sentry('Error', e);
const fakeError = new Error('Failed to execute swap');
Expand Down
12 changes: 1 addition & 11 deletions src/raps/actions/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { ProtocolType, TransactionStatus, TransactionType } from '@/entities';

import { toHex } from '@/handlers/web3';
import { parseGasParamAmounts } from '@/parsers';
import { additionalDataUpdateL2AssetToWatch } from '@/redux/additionalAssetsData';
import { dataAddNewTransaction } from '@/redux/data';
import store from '@/redux/store';
import { AllowancesCache, ethereumUtils } from '@/utils';
Expand Down Expand Up @@ -144,7 +143,7 @@ const swap = async (
} = parameters as SwapActionParameters;
const { dispatch } = store;
const { accountAddress } = store.getState().settings;
const { inputCurrency, outputCurrency } = store.getState().swap;
const { inputCurrency } = store.getState().swap;
const { gasFeeParamsBySpeed, selectedGasFee } = store.getState().gas;
let gasParams = parseGasParamAmounts(selectedGasFee);

Expand Down Expand Up @@ -190,15 +189,6 @@ const swap = async (

// @ts-ignore
swap = await executeSwap(swapParams);
dispatch(
additionalDataUpdateL2AssetToWatch({
hash: swap?.hash || '',
inputCurrency,
network: ethereumUtils.getNetworkFromChainId(Number(chainId)),
outputCurrency,
userAddress: accountAddress,
})
);

if (permit) {
const walletAddress = await wallet.getAddress();
Expand Down
Loading