diff --git a/packages/extension-base/src/koni/background/handlers/Extension.ts b/packages/extension-base/src/koni/background/handlers/Extension.ts index fbbe14f874..d653e101b5 100644 --- a/packages/extension-base/src/koni/background/handlers/Extension.ts +++ b/packages/extension-base/src/koni/background/handlers/Extension.ts @@ -3977,11 +3977,7 @@ export default class KoniExtension { } private hasAnyAccountForMigration (): ResponseHasAnyAccountForMigration { - // todo: - - return { - hasAnyAccountForMigration: true - }; + return this.#koniState.keyringService.context.hasAnyAccountForMigration(); } private updateMigrationAcknowledgedStatus (request: RequestUpdateMigrationAcknowledgedStatus) { diff --git a/packages/extension-base/src/services/keyring-service/context/account-context.ts b/packages/extension-base/src/services/keyring-service/context/account-context.ts index ff997e5df1..bd1e74e6b9 100644 --- a/packages/extension-base/src/services/keyring-service/context/account-context.ts +++ b/packages/extension-base/src/services/keyring-service/context/account-context.ts @@ -1,9 +1,10 @@ // Copyright 2019-2022 @subwallet/extension-base // SPDX-License-Identifier: Apache-2.0 -import { AccountExternalError, RequestAccountCreateExternalV2, RequestAccountCreateHardwareMultiple, RequestAccountCreateHardwareV2, RequestAccountCreateWithSecretKey, RequestAccountExportPrivateKey, RequestChangeMasterPassword, RequestMigratePassword, ResponseAccountCreateWithSecretKey, ResponseAccountExportPrivateKey, ResponseChangeMasterPassword, ResponseMigratePassword } from '@subwallet/extension-base/background/KoniTypes'; +import { AccountExternalError, RequestAccountCreateExternalV2, RequestAccountCreateHardwareMultiple, RequestAccountCreateHardwareV2, RequestAccountCreateWithSecretKey, RequestAccountExportPrivateKey, RequestChangeMasterPassword, RequestMigratePassword, ResponseAccountCreateWithSecretKey, ResponseAccountExportPrivateKey, ResponseChangeMasterPassword, ResponseHasAnyAccountForMigration, ResponseMigratePassword } from '@subwallet/extension-base/background/KoniTypes'; import KoniState from '@subwallet/extension-base/koni/background/handlers/State'; import { KeyringService } from '@subwallet/extension-base/services/keyring-service'; +import { AccountMigrationHandler } from '@subwallet/extension-base/services/keyring-service/context/handlers/Migration'; import { AccountProxyMap, CurrentAccountInfo, RequestAccountBatchExportV2, RequestAccountCreateSuriV2, RequestAccountNameValidate, RequestAccountProxyEdit, RequestAccountProxyForget, RequestBatchJsonGetAccountInfo, RequestBatchRestoreV2, RequestChangeTonWalletContractVersion, RequestCheckPublicAndSecretKey, RequestDeriveCreateMultiple, RequestDeriveCreateV3, RequestDeriveValidateV2, RequestExportAccountProxyMnemonic, RequestGetAllTonWalletContractVersion, RequestGetDeriveAccounts, RequestGetDeriveSuggestion, RequestJsonGetAccountInfo, RequestJsonRestoreV2, RequestMnemonicCreateV2, RequestMnemonicValidateV2, RequestPrivateKeyValidateV2, ResponseAccountBatchExportV2, ResponseAccountCreateSuriV2, ResponseAccountNameValidate, ResponseBatchJsonGetAccountInfo, ResponseCheckPublicAndSecretKey, ResponseDeriveValidateV2, ResponseExportAccountProxyMnemonic, ResponseGetAllTonWalletContractVersion, ResponseGetDeriveAccounts, ResponseGetDeriveSuggestion, ResponseJsonGetAccountInfo, ResponseMnemonicCreateV2, ResponseMnemonicValidateV2, ResponsePrivateKeyValidateV2 } from '@subwallet/extension-base/types'; import { InjectedAccountWithMeta } from '@subwallet/extension-inject/types'; import { SubjectInfo } from '@subwallet/ui-keyring/observable/types'; @@ -20,6 +21,7 @@ export class AccountContext { private readonly ledgerHandler: AccountLedgerHandler; private readonly modifyHandler: AccountModifyHandler; private readonly secretHandler: AccountSecretHandler; + private readonly migrationHandler: AccountMigrationHandler; constructor (private readonly koniState: KoniState, private readonly parentService: KeyringService) { this.state = new AccountState(this.koniState); @@ -30,6 +32,7 @@ export class AccountContext { this.ledgerHandler = new AccountLedgerHandler(this.parentService, this.state); this.modifyHandler = new AccountModifyHandler(this.parentService, this.state); this.secretHandler = new AccountSecretHandler(this.parentService, this.state); + this.migrationHandler = new AccountMigrationHandler(this.parentService, this.state); } // TODO: Merge to value @@ -271,6 +274,14 @@ export class AccountContext { /* Inject */ + /* Migration */ + + public hasAnyAccountForMigration (): ResponseHasAnyAccountForMigration { + return this.migrationHandler.hasAnyAccountForMigration(this.accounts); + } + + /* Migration */ + /* Others */ public removeNoneHardwareGenesisHash () { diff --git a/packages/extension-base/src/services/keyring-service/context/handlers/Migration.ts b/packages/extension-base/src/services/keyring-service/context/handlers/Migration.ts new file mode 100644 index 0000000000..9a278e701e --- /dev/null +++ b/packages/extension-base/src/services/keyring-service/context/handlers/Migration.ts @@ -0,0 +1,24 @@ +// Copyright 2019-2022 @subwallet/extension-base +// SPDX-License-Identifier: Apache-2.0 + +import { ResponseHasAnyAccountForMigration } from '@subwallet/extension-base/background/KoniTypes'; +import { AccountBaseHandler } from '@subwallet/extension-base/services/keyring-service/context/handlers/Base'; +import { AccountProxyMap } from '@subwallet/extension-base/types'; + +export class AccountMigrationHandler extends AccountBaseHandler { + public hasAnyAccountForMigration (accountProxyMap: AccountProxyMap): ResponseHasAnyAccountForMigration { + const accountProxies = Object.values(accountProxyMap); + + for (const account of accountProxies) { + if (account.isNeedMigrateUnifiedAccount) { + return { + hasAnyAccountForMigration: true + }; + } + } + + return { + hasAnyAccountForMigration: false + }; + } +}