Skip to content

Commit

Permalink
[Issue-3926] feat: add api to check if has any account need to be mig…
Browse files Browse the repository at this point in the history
…rated
  • Loading branch information
bluezdot committed Dec 23, 2024
1 parent aef90bd commit 5f4d333
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -271,6 +274,14 @@ export class AccountContext {

/* Inject */

/* Migration */

public hasAnyAccountForMigration (): ResponseHasAnyAccountForMigration {
return this.migrationHandler.hasAnyAccountForMigration(this.accounts);
}

/* Migration */

/* Others */

public removeNoneHardwareGenesisHash () {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
};
}
}

0 comments on commit 5f4d333

Please sign in to comment.