forked from trent_larson/crowd-funder-for-time-pwa
fix(types): improve account type safety and metadata handling
- Change retrieveAllAccountsMetadata to return Account[] instead of AccountEncrypted[] to better reflect its purpose of returning non-sensitive metadata - Update ImportDerivedAccountView to use Account type and group by derivation path - Update retrieveAllFullyDecryptedAccounts to use AccountEncrypted type for encrypted data - Fix import path for Account type in ImportDerivedAccountView This change improves type safety by making it explicit which functions handle encrypted data vs metadata, and ensures consistent handling of account data across the application. The metadata functions now correctly strip sensitive fields while functions that need encrypted data maintain access to those fields.
This commit is contained in:
@@ -83,7 +83,7 @@ import { MASTER_SETTINGS_KEY } from "../db/tables/settings";
|
||||
import * as databaseUtil from "../db/databaseUtil";
|
||||
import { retrieveAllAccountsMetadata } from "../libs/util";
|
||||
import { logger } from "../utils/logger";
|
||||
import { AccountEncrypted } from "@/db/tables/accounts";
|
||||
import { Account } from "../db/tables/accounts";
|
||||
import { PlatformServiceFactory } from "@/services/PlatformServiceFactory";
|
||||
import { USE_DEXIE_DB } from "@/constants/app";
|
||||
@Component({
|
||||
@@ -98,18 +98,20 @@ export default class ImportAccountView extends Vue {
|
||||
selectedArrayFirstDid = "";
|
||||
|
||||
async mounted() {
|
||||
const accounts: AccountEncrypted[] = await retrieveAllAccountsMetadata();
|
||||
const accounts: Account[] = await retrieveAllAccountsMetadata();
|
||||
const seedDids: Record<string, Array<string>> = {};
|
||||
accounts.forEach((account) => {
|
||||
const mnemonicMaybeEncrypted =
|
||||
account.mnemonic || account.mnemonicEncrBase64;
|
||||
if (mnemonicMaybeEncrypted) {
|
||||
const prevDids: Array<string> = seedDids[mnemonicMaybeEncrypted] || [];
|
||||
seedDids[mnemonicMaybeEncrypted] = prevDids.concat([account.did]);
|
||||
// Since we're only getting metadata, we can't check mnemonic
|
||||
// Instead, we'll group by derivation path
|
||||
if (account.derivationPath) {
|
||||
const prevDids: Array<string> = seedDids[account.derivationPath] || [];
|
||||
seedDids[account.derivationPath] = prevDids.concat([account.did]);
|
||||
}
|
||||
});
|
||||
this.didArrays = Object.values(seedDids);
|
||||
this.selectedArrayFirstDid = this.didArrays[0][0];
|
||||
if (this.didArrays.length > 0) {
|
||||
this.selectedArrayFirstDid = this.didArrays[0][0];
|
||||
}
|
||||
}
|
||||
|
||||
public onCancelClick() {
|
||||
@@ -133,13 +135,13 @@ export default class ImportAccountView extends Vue {
|
||||
);
|
||||
let allMatchingAccounts = databaseUtil.mapQueryResultToValues(
|
||||
queryResult,
|
||||
) as unknown as AccountEncrypted[];
|
||||
) as unknown as Account[];
|
||||
if (USE_DEXIE_DB) {
|
||||
const accountsDB = await accountsDBPromise; // let's match derived accounts differently so we don't need the private info
|
||||
allMatchingAccounts = (await accountsDB.accounts
|
||||
.where("did")
|
||||
.anyOf(...selectedArray)
|
||||
.toArray()) as AccountEncrypted[];
|
||||
.toArray()) as Account[];
|
||||
}
|
||||
const accountWithMaxDeriv = allMatchingAccounts[0];
|
||||
allMatchingAccounts.slice(1).forEach((account) => {
|
||||
|
||||
Reference in New Issue
Block a user