diff --git a/src/components/mixins/NetworkFormatterMixin.ts b/src/components/mixins/NetworkFormatterMixin.ts index d1108651b..12e4581ce 100644 --- a/src/components/mixins/NetworkFormatterMixin.ts +++ b/src/components/mixins/NetworkFormatterMixin.ts @@ -7,7 +7,7 @@ import { state, getter } from '@/store/decorators'; @Component export default class NetworkFormatterMixin extends Vue { - @state.web3.networkType networkType!: EvmNetworkType; + @state.web3.networkType networkType!: Nullable; @state.wallet.settings.soraNetwork soraNetwork!: Nullable; @getter.web3.defaultNetworkType defaultNetworkType!: Nullable; diff --git a/src/store/web3/actions.ts b/src/store/web3/actions.ts index 17a7414a4..e7a32a708 100644 --- a/src/store/web3/actions.ts +++ b/src/store/web3/actions.ts @@ -62,7 +62,7 @@ const actions = defineActions({ const { commit } = web3ActionContext(context); let networkType = ''; if (!network) { - networkType = await ethersUtil.getEvmNetworkType(); + networkType = await ethersUtil.fetchEvmNetworkType(); } else { networkType = EvmNetworkTypeName[network]; } diff --git a/src/store/web3/getters.ts b/src/store/web3/getters.ts index 2f4c3ddcd..875b2193d 100644 --- a/src/store/web3/getters.ts +++ b/src/store/web3/getters.ts @@ -27,6 +27,9 @@ const getters = defineGetters()({ }, isValidNetworkType(...args): boolean { const { state, getters } = web3GetterContext(args); + if (!state.networkType) { + return false; + } return state.networkType === getters.defaultNetworkType; }, }); diff --git a/src/store/web3/mutations.ts b/src/store/web3/mutations.ts index 11c21f522..9c14e2dc4 100644 --- a/src/store/web3/mutations.ts +++ b/src/store/web3/mutations.ts @@ -30,7 +30,6 @@ const mutations = defineMutations()({ }, setNetworkType(state, networkType: string): void { state.networkType = networkType; - ethersUtil.storeEvmNetworkType(networkType); }, setSubNetworks(state, subNetworks: Array): void { state.subNetworks = subNetworks; diff --git a/src/store/web3/state.ts b/src/store/web3/state.ts index 51027c25e..81f3eb428 100644 --- a/src/store/web3/state.ts +++ b/src/store/web3/state.ts @@ -1,14 +1,14 @@ import { BridgeNetworks } from '@sora-substrate/util'; import { ZeroStringValue } from '@/consts'; -import ethersUtil from '@/utils/ethers-util'; +import ethersUtil, { EvmNetworkType } from '@/utils/ethers-util'; import type { Web3State } from './types'; export function initialState(): Web3State { return { evmAddress: ethersUtil.getEvmUserAddress(), evmBalance: ZeroStringValue, - networkType: ethersUtil.getEvmNetworkTypeFromStorage(), + networkType: null, subNetworks: [], evmNetwork: BridgeNetworks.ETH_NETWORK_ID, contractAddress: { diff --git a/src/store/web3/types.ts b/src/store/web3/types.ts index e0b6a6916..217c844ae 100644 --- a/src/store/web3/types.ts +++ b/src/store/web3/types.ts @@ -11,7 +11,7 @@ type Contracts = Partial<{ export type Web3State = { evmAddress: string; evmBalance: CodecString; - networkType: string; + networkType: Nullable; subNetworks: Array; evmNetwork: BridgeNetworks; contractAddress: { [key in BridgeNetworks]: Contracts }; diff --git a/src/utils/ethers-util.ts b/src/utils/ethers-util.ts index e0fc829db..1ed8b38d9 100644 --- a/src/utils/ethers-util.ts +++ b/src/utils/ethers-util.ts @@ -303,32 +303,11 @@ function removeEvmUserAddress(): void { storage.remove('evmAddress'); } -function storeEvmNetworkType(network: string): void { - storage.set('evmNetworkType', EvmNetworkTypeName[network] || network); -} - -function getEvmNetworkTypeFromStorage(): string { - // return storage.get('evmNetworkType') || '' TODO: [1.5] return it back after 1.4 release to mainnet - let evmNetworkType = storage.get('evmNetworkType') || ''; - if (evmNetworkType === 'homestead') { - evmNetworkType = 'main'; - } - return evmNetworkType; -} - -function removeEvmNetworkType(): void { - storage.remove('evmNetworkType'); -} - -async function getEvmNetworkType(): Promise { - const networkType = getEvmNetworkTypeFromStorage(); - if (!networkType || networkType === 'undefined') { - const ethersInstance = await getEthersInstance(); - const network = await ethersInstance.getNetwork(); - const networkType = ethers.utils.hexValue(network.chainId); - return EvmNetworkTypeName[networkType]; - } - return networkType; +async function fetchEvmNetworkType(): Promise { + const ethersInstance = await getEthersInstance(); + const network = await ethersInstance.getNetwork(); + const networkType = ethers.utils.hexValue(network.chainId); + return EvmNetworkTypeName[networkType]; } /** @@ -394,10 +373,7 @@ export default { checkAccountIsConnected, storeEvmUserAddress, getEvmUserAddress, - storeEvmNetworkType, - getEvmNetworkType, - getEvmNetworkTypeFromStorage, - removeEvmNetworkType, + fetchEvmNetworkType, getEthersInstance, removeEvmUserAddress, watchEthereum,