From f71d61307f4f277fb773b815692a13894766218a Mon Sep 17 00:00:00 2001 From: Artem Burakov Date: Mon, 15 Apr 2024 19:01:09 +0300 Subject: [PATCH] ISSUE-140(SDK v5): gives each new user a Cyprus-1 address for their first account --- background/services/keyring/index.ts | 25 ++++++++++++++++++- .../AccountsNotificationPanelAccounts.tsx | 1 - 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/background/services/keyring/index.ts b/background/services/keyring/index.ts index 34c0ef56..487b67e1 100644 --- a/background/services/keyring/index.ts +++ b/background/services/keyring/index.ts @@ -352,7 +352,30 @@ export default class KeyringService extends BaseService { } this.#keyrings.push(newKeyring) - const [address] = newKeyring.addAddressesSync(1) + //const [address] = newKeyring.addAddressesSync(1) + + // FIXME temp solution for SDK v5 + // create a new address until we find an address for the target shard + let address + let found = false + const DEFAULT_SHARD = "cyprus-1" + while (!found) { + address = newKeyring.addAddressesSync(1)[0] + const shardFromAddress = getShardFromAddress(address) + if (shardFromAddress !== undefined) { + if (shardFromAddress === DEFAULT_SHARD) { + found = true + break + } + } + this.#hiddenAccounts[address] = true // may want to reconsider this + } + if (address === undefined || address === null || address === "") { + throw new Error( + `Could not find address in given shard ${DEFAULT_SHARD}` + ) + } + this.#hiddenAccounts[address] = false this.#keyringMetadata[newKeyring.id] = { source } await this.persistKeyrings() diff --git a/ui/components/AccountsNotificationPanel/AccountsNotificationPanelAccounts.tsx b/ui/components/AccountsNotificationPanel/AccountsNotificationPanelAccounts.tsx index 877d79bf..255a850a 100644 --- a/ui/components/AccountsNotificationPanel/AccountsNotificationPanelAccounts.tsx +++ b/ui/components/AccountsNotificationPanel/AccountsNotificationPanelAccounts.tsx @@ -489,7 +489,6 @@ export default function AccountsNotificationPanelAccounts({ const handleSetShard = (newShard: string) => { // This is for updating user-selected shard for new address - console.log(newShard) shard.current = newShard }