Skip to content

Commit

Permalink
chore: remove old sui (#2858)
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteZhang1024 authored Apr 19, 2023
1 parent 4c04882 commit 07f6c9d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/kit-bg/src/services/ServiceApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
35 changes: 35 additions & 0 deletions packages/kit-bg/src/services/ServiceBootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -75,6 +76,12 @@ const defaultNetworkRpcs: Record<string, string> = {
export default class ServiceBootstrap extends ServiceBase {
private fetchFiatTimer: NodeJS.Timeout | null = null;

@bindThis()
async preBootstrap() {
// not use appSelector
await this.removeDeprecatedNetworks();
}

@bindThis()
bootstrap() {
const {
Expand Down Expand Up @@ -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);
}
}
}
}

0 comments on commit 07f6c9d

Please sign in to comment.