@@ -21,6 +21,7 @@ import {
2121 ACCOUNT_DERIVATION_DB_MIGRATION_VERSION ,
2222 AUTO_SWITCH_DEFAULT_RPC_AT_VERSION ,
2323 COINTYPE_COSMOS ,
24+ COINTYPE_SUI ,
2425 FIX_COSMOS_TEMPLATE_DB_MIGRATION_VERSION ,
2526 IMPL_COSMOS ,
2627 INDEX_PLACEHOLDER ,
@@ -75,6 +76,12 @@ const defaultNetworkRpcs: Record<string, string> = {
7576export default class ServiceBootstrap extends ServiceBase {
7677 private fetchFiatTimer : NodeJS . Timeout | null = null ;
7778
79+ @bindThis ( )
80+ async preBootstrap ( ) {
81+ // not use appSelector
82+ await this . removeDeprecatedNetworks ( ) ;
83+ }
84+
7885 @bindThis ( )
7986 bootstrap ( ) {
8087 const {
@@ -373,4 +380,32 @@ export default class ServiceBootstrap extends ServiceBase {
373380 'POST' ,
374381 ) ;
375382 }
383+
384+ // remove deprecated wallet
385+ @backgroundMethod ( )
386+ private async removeDeprecatedNetworks ( ) {
387+ const needRemoveNetwork = [
388+ // version 4.4.0 remove deprecated sui networks
389+ 'sui--8888881' ,
390+ 'sui--8888882' ,
391+ ] ;
392+ const { engine } = this . backgroundApi ;
393+ const networks = await engine . listNetworks ( false ) ;
394+ const deprecatedNetworks = networks . filter ( ( n ) =>
395+ needRemoveNetwork . includes ( n . id ) ,
396+ ) ;
397+
398+ if ( deprecatedNetworks . length ) {
399+ const accounts = await engine . dbApi . getAllAccounts ( ) ;
400+ const needDeleteAccounts = accounts . filter (
401+ ( a ) => a . coinType === COINTYPE_SUI ,
402+ ) ;
403+ for ( const network of deprecatedNetworks ) {
404+ for ( const account of needDeleteAccounts ) {
405+ await engine . removeAccount ( account . id , '' , network . id , true ) ;
406+ }
407+ await engine . deleteNetwork ( network . id ) ;
408+ }
409+ }
410+ }
376411}
0 commit comments