Skip to content

Commit

Permalink
fix: Fix bugs when changing network (#471)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinoosss authored Apr 9, 2024
1 parent 1ecd847 commit a0645e4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions packages/adena-extension/src/hooks/use-network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useEvent } from './use-event';
import { fetchHealth } from '@common/utils/fetch-utils';

import { NetworkMetainfo } from '@types';
import { CommonState, NetworkState, WalletState } from '@states';
import { BalanceState, CommonState, NetworkState, WalletState } from '@states';

interface NetworkResponse {
networks: NetworkMetainfo[];
Expand Down Expand Up @@ -46,6 +46,9 @@ export const useNetwork = (): NetworkResponse => {
const [failedNetwork, setFailedNetwork] = useRecoilState(CommonState.failedNetwork);
const [, setState] = useRecoilState(WalletState.state);
const resetNetworkConnection = useResetRecoilState(CommonState.failedNetwork);
const resetAccountTokenBalances = useResetRecoilState(BalanceState.accountTokenBalances);
const resetAccountNativeBalances = useResetRecoilState(BalanceState.accountNativeBalances);
const resetCurrentTokenBalances = useResetRecoilState(BalanceState.currentTokenBalances);

const addNetwork = useCallback(
async (name: string, rpcUrl: string, chainId: string) => {
Expand Down Expand Up @@ -78,8 +81,11 @@ export const useNetwork = (): NetworkResponse => {
setCurrentNetwork(null);
return false;
}
setState('LOADING');
resetCurrentTokenBalances();
resetAccountTokenBalances();
resetAccountNativeBalances();
resetNetworkConnection();
setState('LOADING');
const network = networkMetainfos.find((network) => network.id === id) ?? networkMetainfos[0];
await chainService.updateCurrentNetworkId(id);
await changeNetworkOfProvider(network);
Expand Down
2 changes: 1 addition & 1 deletion packages/adena-extension/src/router/popup/loading-main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import mixins from '@styles/mixins';

const Wrapper = styled.main`
${mixins.flex({ justify: 'stretch' })};
position: absolute;
position: fixed;
width: 100%;
height: 100%;
padding: 78px 24px;
Expand Down

0 comments on commit a0645e4

Please sign in to comment.