Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: duplicated db fetch #6426

Merged
merged 1 commit into from
Jun 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
isSecp256k1Point,
isSecp256k1PrivateKey,
} from '@masknet/shared-base'
import { INTERNAL_getPasswordRequired } from '../../plugins/Wallet/services/wallet/password'

delegatePluginBackup(backupAllPlugins)
delegatePluginRestore(async function (backup) {
Expand Down Expand Up @@ -71,12 +72,13 @@ delegateWalletBackup(async function () {
return wallet.flat()
})
delegateWalletRestore(async function (backup) {
const password = await INTERNAL_getPasswordRequired()
for (const wallet of backup) {
try {
const name = wallet.name

if (wallet.privateKey.some)
await recoverWalletFromPrivateKey(name, await JWKToKey(wallet.privateKey.val, 'private'))
await recoverWalletFromPrivateKey(name, await JWKToKey(wallet.privateKey.val, 'private'), password)
else if (wallet.mnemonic.some) {
// fix a backup bug of pre-v2.2.2 versions
const accounts = await getDerivableAccounts(wallet.mnemonic.val.words, 1, 5)
Expand All @@ -85,6 +87,7 @@ delegateWalletRestore(async function (backup) {
name,
wallet.mnemonic.val.words,
index > -1 ? `${HD_PATH_WITHOUT_INDEX_ETHEREUM}/${index}` : wallet.mnemonic.val.path,
password,
)
}
} catch (error) {
Expand Down
7 changes: 4 additions & 3 deletions packages/mask/src/plugins/Wallet/services/wallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,9 @@ export async function recoverWalletFromMnemonic(
name: string,
mnemonic: string,
derivationPath = `${HD_PATH_WITHOUT_INDEX_ETHEREUM}/0`,
initialPassword?: string,
) {
const password_ = await password.INTERNAL_getPasswordRequired()
const password_ = initialPassword ?? (await password.INTERNAL_getPasswordRequired())
const imported = await Mask.importMnemonic({
mnemonic,
password: password_,
Expand Down Expand Up @@ -325,8 +326,8 @@ export async function recoverWalletFromMnemonic(
}
}

export async function recoverWalletFromPrivateKey(name: string, privateKey: string) {
const password_ = await password.INTERNAL_getPasswordRequired()
export async function recoverWalletFromPrivateKey(name: string, privateKey: string, initialPassword_?: string) {
const password_ = initialPassword_ ?? (await password.INTERNAL_getPasswordRequired())
const imported = await Mask.importPrivateKey({
coin: api.Coin.Ethereum,
name,
Expand Down