Skip to content

Commit

Permalink
fix: correct count logic for keyring.accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
richardo2016x committed Dec 2, 2024
1 parent 08e448e commit a6b1912
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
4 changes: 2 additions & 2 deletions apps/mobile/src/core/apis/lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export async function shouldAskSetPassword() {

if (!lockInfo.isUseCustomPwd) return true;

return keyringService.getCountOfAccountsInKeyring() === 0;
return (await keyringService.getCountOfAccountsInKeyring()) === 0;
}

export async function resetPasswordOnUI(newPassword: string) {
Expand All @@ -145,7 +145,7 @@ export async function resetPasswordOnUI(newPassword: string) {

try {
const hasAccountsInKeyring =
keyringService.getCountOfAccountsInKeyring() > 0;
(await keyringService.getCountOfAccountsInKeyring()) > 0;

if (hasAccountsInKeyring) {
const lockInfo = await getRabbyLockInfo();
Expand Down
11 changes: 4 additions & 7 deletions packages/service-keyring/src/keyringService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,9 @@ export class KeyringService extends RNEventEmitter {
// );
// }

// TODO: should we refactor it with `.getAllVisibleAccountsArray`?
getCountOfAccountsInKeyring() {
return this.keyrings.reduce((accu, kr) => {
// !!!notice: kr.accounts maybe undefined!!!
return accu + (kr.accounts || []).length;
}, 0);
async getCountOfAccountsInKeyring() {
const accus = await this.getAllTypedVisibleAccounts();
return accus.length;
}

/**
Expand All @@ -173,7 +170,7 @@ export class KeyringService extends RNEventEmitter {
* @param newPassword
*/
async resetPassword(newPassword: string) {
if (this.getCountOfAccountsInKeyring()) {
if (await this.getCountOfAccountsInKeyring()) {
throw new Error("You're trying to overwrite password on existing keyrings.");
}

Expand Down

0 comments on commit a6b1912

Please sign in to comment.