From 6ce258dcc20914d29c6dadc32a9ca6593a079132 Mon Sep 17 00:00:00 2001 From: Jan Marcano Date: Tue, 12 Jul 2022 13:59:20 -0300 Subject: [PATCH] Prevent repeated names on Accounts --- .../background/messaging/internalMethods.ts | 5 ++++- packages/ui/src/components/AccountPreview.ts | 19 ++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/extension/src/background/messaging/internalMethods.ts b/packages/extension/src/background/messaging/internalMethods.ts index aec2d6da..4033bd65 100644 --- a/packages/extension/src/background/messaging/internalMethods.ts +++ b/packages/extension/src/background/messaging/internalMethods.ts @@ -373,7 +373,10 @@ export class InternalMethods { if (existingAccounts) { for (let i = 0; i < existingAccounts.length; i++) { if (existingAccounts[i].address === targetAddress) { - throw new Error(`Account already exists in ${ledger} wallet.`); + throw new Error(`An account with this address already exists in your ${ledger} wallet.`); + } + if (existingAccounts[i].name === name) { + throw new Error(`An account named '${name}' already exists in your ${ledger} wallet.`); } } } diff --git a/packages/ui/src/components/AccountPreview.ts b/packages/ui/src/components/AccountPreview.ts index f1fc97ae..1078ee5b 100644 --- a/packages/ui/src/components/AccountPreview.ts +++ b/packages/ui/src/components/AccountPreview.ts @@ -41,18 +41,27 @@ const AccountPreview: FunctionalComponent = (props: any) => {
${account.isRef && html``}
${account.name}
- ${results && results.assets && html` ${results.assets.length} ASAs
`} - ${results && html` ${numFormat(results.amount / 1e6, 6)} Algos `} + ${results && results.assets && html`${results.assets.length} ASAs
`} + ${results && html`${numFormat(results.amount / 1e6, 6)} Algos`} ${results === null && error && html`${error}`} - ${results === null && !error && html``} + ${results === null && + !error && + html` +
+ +
+ `}