From dee92ada4534454ce2e600668b6ad9977c541330 Mon Sep 17 00:00:00 2001 From: Mateusz Jasiuk Date: Tue, 31 Dec 2024 15:13:06 +0100 Subject: [PATCH 1/2] feat: ledger shielded accounts --- apps/extension/src/App/Accounts/ParentAccounts.tsx | 7 ++----- apps/extension/src/Setup/Setup.tsx | 4 ++-- apps/extension/src/Setup/query.ts | 2 +- apps/extension/src/background/keyring/handler.ts | 2 +- apps/extension/src/background/keyring/keyring.ts | 8 ++++---- apps/namadillo/src/App/Ibc/IbcTransfer.tsx | 1 + apps/namadillo/src/App/NamadaTransfer/NamadaTransfer.tsx | 2 +- packages/sdk/src/ledger.ts | 6 +++--- packages/sdk/src/sdk.ts | 2 +- 9 files changed, 16 insertions(+), 18 deletions(-) diff --git a/apps/extension/src/App/Accounts/ParentAccounts.tsx b/apps/extension/src/App/Accounts/ParentAccounts.tsx index 25a1d130bd..f1b1251f99 100644 --- a/apps/extension/src/App/Accounts/ParentAccounts.tsx +++ b/apps/extension/src/App/Accounts/ParentAccounts.tsx @@ -8,7 +8,7 @@ import { KeyListItem, Stack, } from "@namada/components"; -import { AccountType, DerivedAccount } from "@namada/types"; +import { DerivedAccount } from "@namada/types"; import { ParentAccountsFooter } from "App/Accounts/ParentAccountsFooter"; import { PageHeader } from "App/Common"; import routes from "App/routes"; @@ -27,14 +27,11 @@ export const ParentAccounts = (): JSX.Element => { accounts: allAccounts, changeActiveAccountId, } = useContext(AccountContext); - // We check which accounts need to be re-imported const accounts = allAccounts .filter((account) => account.parentId) .map((account) => { - const outdated = - account.type !== AccountType.Ledger && - typeof account.pseudoExtendedKey === "undefined"; + const outdated = typeof account.pseudoExtendedKey === "undefined"; const parent = parentAccounts.find((pa) => pa.id === account.parentId); invariant(parent, `Parent account not found for account ${account.id}`); diff --git a/apps/extension/src/Setup/Setup.tsx b/apps/extension/src/Setup/Setup.tsx index 28ea9a07ba..5825ed9b23 100644 --- a/apps/extension/src/Setup/Setup.tsx +++ b/apps/extension/src/Setup/Setup.tsx @@ -110,8 +110,8 @@ export const Setup: React.FC = () => { const prettyAccountSecret = accountSecret.t === "Mnemonic" ? "mnemonic" - : accountSecret.t === "PrivateKey" ? "private key" - : assertNever(accountSecret); + : accountSecret.t === "PrivateKey" ? "private key" + : assertNever(accountSecret); setCompletionStatusInfo(`Encrypting and storing ${prettyAccountSecret}.`); // Create parent account diff --git a/apps/extension/src/Setup/query.ts b/apps/extension/src/Setup/query.ts index f7afe1e89d..d16cac2274 100644 --- a/apps/extension/src/Setup/query.ts +++ b/apps/extension/src/Setup/query.ts @@ -13,7 +13,7 @@ import { DeriveAccountDetails, LedgerAccountDetails } from "./types"; // Wrap account management calls with extension requester instance export class AccountManager { - constructor(private readonly requester: ExtensionRequester) {} + constructor(private readonly requester: ExtensionRequester) { } /** * Set password for the extension diff --git a/apps/extension/src/background/keyring/handler.ts b/apps/extension/src/background/keyring/handler.ts index e447d5f949..b4088cc0f6 100644 --- a/apps/extension/src/background/keyring/handler.ts +++ b/apps/extension/src/background/keyring/handler.ts @@ -195,7 +195,7 @@ const handleQueryAccountsMsg: ( const output = query && query.accountId ? await service.queryAccountsByParentId(query.accountId) - : await service.queryAccounts(); + : await service.queryAccounts(); return output; }; diff --git a/apps/extension/src/background/keyring/keyring.ts b/apps/extension/src/background/keyring/keyring.ts index ef73b1178a..8488b16c62 100644 --- a/apps/extension/src/background/keyring/keyring.ts +++ b/apps/extension/src/background/keyring/keyring.ts @@ -63,7 +63,7 @@ export class KeyRing { protected readonly sdkService: SdkService, protected readonly utilityStore: KVStore, protected readonly localStorage: LocalStorage - ) {} + ) { } public get status(): KeyRingStatus { return this._status; @@ -463,7 +463,7 @@ export class KeyRing { const deriveFn = ( type === AccountType.PrivateKey ? this.deriveTransparentAccount - : this.deriveShieldedAccount).bind(this); + : this.deriveShieldedAccount).bind(this); const { secret } = await this.getParentSecret(parentId); const info = deriveFn(secret, derivationPath, parentAccount); @@ -746,13 +746,13 @@ export class KeyRing { const key = disposableKey ? disposableKey.privateKey - : await this.getSigningKey(signer); + : await this.getSigningKey(signer); // If disposable key is provided, use it to map real address to spending key const spendingKeys = disposableKey ? [await this.getSpendingKey(disposableKey.realAddress)] - : []; + : []; const { signing } = this.sdkService.getSdk(); diff --git a/apps/namadillo/src/App/Ibc/IbcTransfer.tsx b/apps/namadillo/src/App/Ibc/IbcTransfer.tsx index 435831ae49..b9ef1fe4e6 100644 --- a/apps/namadillo/src/App/Ibc/IbcTransfer.tsx +++ b/apps/namadillo/src/App/Ibc/IbcTransfer.tsx @@ -56,6 +56,7 @@ export const IbcTransfer = (): JSX.Element => { walletAddress: sourceAddress, }) ); + console.log("userAssets", userAssets); // Local State const [shielded, setShielded] = useState(true); diff --git a/apps/namadillo/src/App/NamadaTransfer/NamadaTransfer.tsx b/apps/namadillo/src/App/NamadaTransfer/NamadaTransfer.tsx index ddabc87297..7b62c4aa13 100644 --- a/apps/namadillo/src/App/NamadaTransfer/NamadaTransfer.tsx +++ b/apps/namadillo/src/App/NamadaTransfer/NamadaTransfer.tsx @@ -67,7 +67,7 @@ export const NamadaTransfer: React.FC = () => { const account = defaultAccounts.data?.find((account) => shielded ? account.type === AccountType.ShieldedKeys - : account.type !== AccountType.ShieldedKeys + : account.type !== AccountType.ShieldedKeys ); const sourceAddress = account?.address; const selectedAssetAddress = searchParams.get(params.asset) || undefined; diff --git a/packages/sdk/src/ledger.ts b/packages/sdk/src/ledger.ts index f39281bb42..0b13fb1fb3 100644 --- a/packages/sdk/src/ledger.ts +++ b/packages/sdk/src/ledger.ts @@ -58,7 +58,7 @@ export class Ledger { /** * @param namadaApp - Inititalized NamadaApp class from Zondax package */ - private constructor(public readonly namadaApp: NamadaApp) {} + private constructor(public readonly namadaApp: NamadaApp) { } /** * Initialize and return Ledger class instance with initialized Transport @@ -255,7 +255,7 @@ export class Ledger { * Check if Zip32 is supported by the installed app's version. * Throws error if app is not initialized * @async - * @retuns boolean + * @returns boolean */ public async isZip32Supported(): Promise { const { @@ -277,7 +277,7 @@ export class Ledger { } = await this.status(); throw new Error( `This method requires Zip32 and is unsupported in ${appVersion}! ` + - `Please update to at least ${LEDGER_MIN_VERSION_ZIP32}!` + `Please update to at least ${LEDGER_MIN_VERSION_ZIP32}!` ); } } diff --git a/packages/sdk/src/sdk.ts b/packages/sdk/src/sdk.ts index fc61a9089b..2330bee793 100644 --- a/packages/sdk/src/sdk.ts +++ b/packages/sdk/src/sdk.ts @@ -29,7 +29,7 @@ export class Sdk { public readonly cryptoMemory: WebAssembly.Memory, public readonly url: string, public readonly nativeToken: string - ) {} + ) { } /** * Re-initialize wasm instances and return this instance From 4cb060aea44b40855ce3a05267a745f249f57e61 Mon Sep 17 00:00:00 2001 From: Mateusz Jasiuk Date: Tue, 21 Jan 2025 12:27:04 +0100 Subject: [PATCH 2/2] fix: prettier fmt --- apps/extension/src/Setup/Setup.tsx | 4 ++-- apps/extension/src/Setup/query.ts | 2 +- apps/extension/src/background/keyring/handler.ts | 2 +- apps/extension/src/background/keyring/keyring.ts | 8 ++++---- apps/namadillo/src/App/Ibc/IbcTransfer.tsx | 1 - apps/namadillo/src/App/NamadaTransfer/NamadaTransfer.tsx | 2 +- packages/sdk/src/ledger.ts | 4 ++-- packages/sdk/src/sdk.ts | 2 +- 8 files changed, 12 insertions(+), 13 deletions(-) diff --git a/apps/extension/src/Setup/Setup.tsx b/apps/extension/src/Setup/Setup.tsx index 5825ed9b23..28ea9a07ba 100644 --- a/apps/extension/src/Setup/Setup.tsx +++ b/apps/extension/src/Setup/Setup.tsx @@ -110,8 +110,8 @@ export const Setup: React.FC = () => { const prettyAccountSecret = accountSecret.t === "Mnemonic" ? "mnemonic" - : accountSecret.t === "PrivateKey" ? "private key" - : assertNever(accountSecret); + : accountSecret.t === "PrivateKey" ? "private key" + : assertNever(accountSecret); setCompletionStatusInfo(`Encrypting and storing ${prettyAccountSecret}.`); // Create parent account diff --git a/apps/extension/src/Setup/query.ts b/apps/extension/src/Setup/query.ts index d16cac2274..f7afe1e89d 100644 --- a/apps/extension/src/Setup/query.ts +++ b/apps/extension/src/Setup/query.ts @@ -13,7 +13,7 @@ import { DeriveAccountDetails, LedgerAccountDetails } from "./types"; // Wrap account management calls with extension requester instance export class AccountManager { - constructor(private readonly requester: ExtensionRequester) { } + constructor(private readonly requester: ExtensionRequester) {} /** * Set password for the extension diff --git a/apps/extension/src/background/keyring/handler.ts b/apps/extension/src/background/keyring/handler.ts index b4088cc0f6..e447d5f949 100644 --- a/apps/extension/src/background/keyring/handler.ts +++ b/apps/extension/src/background/keyring/handler.ts @@ -195,7 +195,7 @@ const handleQueryAccountsMsg: ( const output = query && query.accountId ? await service.queryAccountsByParentId(query.accountId) - : await service.queryAccounts(); + : await service.queryAccounts(); return output; }; diff --git a/apps/extension/src/background/keyring/keyring.ts b/apps/extension/src/background/keyring/keyring.ts index 8488b16c62..ef73b1178a 100644 --- a/apps/extension/src/background/keyring/keyring.ts +++ b/apps/extension/src/background/keyring/keyring.ts @@ -63,7 +63,7 @@ export class KeyRing { protected readonly sdkService: SdkService, protected readonly utilityStore: KVStore, protected readonly localStorage: LocalStorage - ) { } + ) {} public get status(): KeyRingStatus { return this._status; @@ -463,7 +463,7 @@ export class KeyRing { const deriveFn = ( type === AccountType.PrivateKey ? this.deriveTransparentAccount - : this.deriveShieldedAccount).bind(this); + : this.deriveShieldedAccount).bind(this); const { secret } = await this.getParentSecret(parentId); const info = deriveFn(secret, derivationPath, parentAccount); @@ -746,13 +746,13 @@ export class KeyRing { const key = disposableKey ? disposableKey.privateKey - : await this.getSigningKey(signer); + : await this.getSigningKey(signer); // If disposable key is provided, use it to map real address to spending key const spendingKeys = disposableKey ? [await this.getSpendingKey(disposableKey.realAddress)] - : []; + : []; const { signing } = this.sdkService.getSdk(); diff --git a/apps/namadillo/src/App/Ibc/IbcTransfer.tsx b/apps/namadillo/src/App/Ibc/IbcTransfer.tsx index b9ef1fe4e6..435831ae49 100644 --- a/apps/namadillo/src/App/Ibc/IbcTransfer.tsx +++ b/apps/namadillo/src/App/Ibc/IbcTransfer.tsx @@ -56,7 +56,6 @@ export const IbcTransfer = (): JSX.Element => { walletAddress: sourceAddress, }) ); - console.log("userAssets", userAssets); // Local State const [shielded, setShielded] = useState(true); diff --git a/apps/namadillo/src/App/NamadaTransfer/NamadaTransfer.tsx b/apps/namadillo/src/App/NamadaTransfer/NamadaTransfer.tsx index 7b62c4aa13..ddabc87297 100644 --- a/apps/namadillo/src/App/NamadaTransfer/NamadaTransfer.tsx +++ b/apps/namadillo/src/App/NamadaTransfer/NamadaTransfer.tsx @@ -67,7 +67,7 @@ export const NamadaTransfer: React.FC = () => { const account = defaultAccounts.data?.find((account) => shielded ? account.type === AccountType.ShieldedKeys - : account.type !== AccountType.ShieldedKeys + : account.type !== AccountType.ShieldedKeys ); const sourceAddress = account?.address; const selectedAssetAddress = searchParams.get(params.asset) || undefined; diff --git a/packages/sdk/src/ledger.ts b/packages/sdk/src/ledger.ts index 0b13fb1fb3..cf3c9b484e 100644 --- a/packages/sdk/src/ledger.ts +++ b/packages/sdk/src/ledger.ts @@ -58,7 +58,7 @@ export class Ledger { /** * @param namadaApp - Inititalized NamadaApp class from Zondax package */ - private constructor(public readonly namadaApp: NamadaApp) { } + private constructor(public readonly namadaApp: NamadaApp) {} /** * Initialize and return Ledger class instance with initialized Transport @@ -277,7 +277,7 @@ export class Ledger { } = await this.status(); throw new Error( `This method requires Zip32 and is unsupported in ${appVersion}! ` + - `Please update to at least ${LEDGER_MIN_VERSION_ZIP32}!` + `Please update to at least ${LEDGER_MIN_VERSION_ZIP32}!` ); } } diff --git a/packages/sdk/src/sdk.ts b/packages/sdk/src/sdk.ts index 2330bee793..fc61a9089b 100644 --- a/packages/sdk/src/sdk.ts +++ b/packages/sdk/src/sdk.ts @@ -29,7 +29,7 @@ export class Sdk { public readonly cryptoMemory: WebAssembly.Memory, public readonly url: string, public readonly nativeToken: string - ) { } + ) {} /** * Re-initialize wasm instances and return this instance