diff --git a/packages/kit-bg/src/services/ServiceApp.ts b/packages/kit-bg/src/services/ServiceApp.ts index de1da7fb14b..e1878a61693 100644 --- a/packages/kit-bg/src/services/ServiceApp.ts +++ b/packages/kit-bg/src/services/ServiceApp.ts @@ -305,6 +305,8 @@ class ServiceApp extends ServiceBase { await this.checkLockStatus(); serviceDiscover.init(); + await serviceBootstrap.preBootstrap(); + const networks = await serviceNetwork.initNetworks(); const wallets = await serviceAccount.initWallets(); const activeNetworkId = serviceNetwork.initCheckingNetwork(networks); diff --git a/packages/kit-bg/src/services/ServiceBootstrap.ts b/packages/kit-bg/src/services/ServiceBootstrap.ts index c3439eddd5d..296150f4ed4 100644 --- a/packages/kit-bg/src/services/ServiceBootstrap.ts +++ b/packages/kit-bg/src/services/ServiceBootstrap.ts @@ -21,6 +21,7 @@ import { ACCOUNT_DERIVATION_DB_MIGRATION_VERSION, AUTO_SWITCH_DEFAULT_RPC_AT_VERSION, COINTYPE_COSMOS, + COINTYPE_SUI, FIX_COSMOS_TEMPLATE_DB_MIGRATION_VERSION, IMPL_COSMOS, INDEX_PLACEHOLDER, @@ -75,6 +76,12 @@ const defaultNetworkRpcs: Record = { export default class ServiceBootstrap extends ServiceBase { private fetchFiatTimer: NodeJS.Timeout | null = null; + @bindThis() + async preBootstrap() { + // not use appSelector + await this.removeDeprecatedNetworks(); + } + @bindThis() bootstrap() { const { @@ -373,4 +380,32 @@ export default class ServiceBootstrap extends ServiceBase { 'POST', ); } + + // remove deprecated wallet + @backgroundMethod() + private async removeDeprecatedNetworks() { + const needRemoveNetwork = [ + // version 4.4.0 remove deprecated sui networks + 'sui--8888881', + 'sui--8888882', + ]; + const { engine } = this.backgroundApi; + const networks = await engine.listNetworks(false); + const deprecatedNetworks = networks.filter((n) => + needRemoveNetwork.includes(n.id), + ); + + if (deprecatedNetworks.length) { + const accounts = await engine.dbApi.getAllAccounts(); + const needDeleteAccounts = accounts.filter( + (a) => a.coinType === COINTYPE_SUI, + ); + for (const network of deprecatedNetworks) { + for (const account of needDeleteAccounts) { + await engine.removeAccount(account.id, '', network.id, true); + } + await engine.deleteNetwork(network.id); + } + } + } }