From dc47edb85d8a871374e2d405a2e604b7a6f0ddec Mon Sep 17 00:00:00 2001 From: Mark Nardi Date: Thu, 2 May 2024 14:01:07 +0200 Subject: [PATCH] chore: rename selected chain to selected (#2431) * add network information for evm chains * remove networksettingsdrawer and unify with network informations * cleanup information drawers * rename selected chain to selected * rename `selectedNetwork` to `selectedNetworkForNetworkDrawer` --------- Co-authored-by: Nicole O'Brien --- packages/desktop/components/NetworkCard.svelte | 14 ++++++++++---- .../NetworkConfigRouterView.svelte | 4 ++-- .../views/ConfirmLedgerEvmAddressDrawer.svelte | 4 ++-- .../views/ConnectedNetworksDrawer.svelte | 4 ++-- .../views/NetworkDepositAddressDrawer.svelte | 18 +++++++----------- .../views/NetworkInformationDrawer.svelte | 10 +++++----- .../components/AccountNetworkSummary.svelte | 4 ++-- .../src/lib/core/network/stores/index.ts | 2 +- .../network/stores/selected-chain.store.ts | 12 ------------ ...elected-network-for-network-drawer.store.ts | 12 ++++++++++++ 10 files changed, 43 insertions(+), 41 deletions(-) delete mode 100644 packages/shared/src/lib/core/network/stores/selected-chain.store.ts create mode 100644 packages/shared/src/lib/core/network/stores/selected-network-for-network-drawer.store.ts diff --git a/packages/desktop/components/NetworkCard.svelte b/packages/desktop/components/NetworkCard.svelte index 73d63957e2..dfee38008b 100644 --- a/packages/desktop/components/NetworkCard.svelte +++ b/packages/desktop/components/NetworkCard.svelte @@ -7,7 +7,13 @@ import { localize } from '@core/i18n' import { generateAndStoreEvmAddressForAccounts, pollEvmBalancesForAccount } from '@core/layer-2/actions' import { LedgerAppName } from '@core/ledger' - import { ExplorerEndpoint, Network, NetworkNamespace, getDefaultExplorerUrl, setSelectedChain } from '@core/network' + import { + ExplorerEndpoint, + Network, + NetworkNamespace, + getDefaultExplorerUrl, + setSelectedNetworkForNetworkDrawer, + } from '@core/network' import { ProfileType } from '@core/profile' import { checkActiveProfileAuth } from '@core/profile/actions' import { activeProfile } from '@core/profile/stores' @@ -32,7 +38,7 @@ } function onCardClick(): void { - setSelectedChain(network) + setSelectedNetworkForNetworkDrawer(network) $networkConfigRouter.goTo(NetworkConfigRoute.ChainInformation) } @@ -40,7 +46,7 @@ if (network.namespace === NetworkNamespace.Stardust) { $networkConfigRouter.goTo(NetworkConfigRoute.ChainDepositAddress) } else { - setSelectedChain(network) + setSelectedNetworkForNetworkDrawer(network) $networkConfigRouter.goTo(NetworkConfigRoute.ChainDepositAddress) } } @@ -57,7 +63,7 @@ } try { - setSelectedChain(network) + setSelectedNetworkForNetworkDrawer(network) await generateAndStoreEvmAddressForAccounts( $activeProfile.type, network.coinType, diff --git a/packages/desktop/views/dashboard/drawers/network-config/NetworkConfigRouterView.svelte b/packages/desktop/views/dashboard/drawers/network-config/NetworkConfigRouterView.svelte index b4856bc3cc..b117169e39 100644 --- a/packages/desktop/views/dashboard/drawers/network-config/NetworkConfigRouterView.svelte +++ b/packages/desktop/views/dashboard/drawers/network-config/NetworkConfigRouterView.svelte @@ -11,7 +11,7 @@ EditNetworkDrawer, RemoveNetworkDrawer, } from './views' - import { clearSelectedChain } from '@core/network' + import { clearSelectedNetworkForNetworkDrawer } from '@core/network' import features from '@features/features' import { Platform } from '@core/app' @@ -30,7 +30,7 @@ onDestroy(() => { $networkConfigRouter = null - clearSelectedChain() + clearSelectedNetworkForNetworkDrawer() }) diff --git a/packages/desktop/views/dashboard/drawers/network-config/views/ConfirmLedgerEvmAddressDrawer.svelte b/packages/desktop/views/dashboard/drawers/network-config/views/ConfirmLedgerEvmAddressDrawer.svelte index a302d8b913..d1de07b10f 100644 --- a/packages/desktop/views/dashboard/drawers/network-config/views/ConfirmLedgerEvmAddressDrawer.svelte +++ b/packages/desktop/views/dashboard/drawers/network-config/views/ConfirmLedgerEvmAddressDrawer.svelte @@ -3,13 +3,13 @@ import { DrawerTemplate } from '@components' import { selectedAccount } from '@core/account/stores' import { localize } from '@core/i18n' - import { getEvmNetworks, selectedChain } from '@core/network/stores' + import { getEvmNetworks, selectedNetworkForNetworkDrawer } from '@core/network/stores' import { Router } from '@core/router' import { NetworkConfigRoute, networkConfigRouter } from '../' export let drawerRouter: Router - $: evmNetwork = $selectedChain ?? getEvmNetworks()[0] + $: evmNetwork = $selectedNetworkForNetworkDrawer ?? getEvmNetworks()[0] $: address = evmNetwork ? $selectedAccount?.evmAddresses?.[evmNetwork.coinType] : undefined function onContinueClick(): void { diff --git a/packages/desktop/views/dashboard/drawers/network-config/views/ConnectedNetworksDrawer.svelte b/packages/desktop/views/dashboard/drawers/network-config/views/ConnectedNetworksDrawer.svelte index 65ff726893..26f7e34989 100644 --- a/packages/desktop/views/dashboard/drawers/network-config/views/ConnectedNetworksDrawer.svelte +++ b/packages/desktop/views/dashboard/drawers/network-config/views/ConnectedNetworksDrawer.svelte @@ -1,7 +1,7 @@ diff --git a/packages/desktop/views/dashboard/drawers/network-config/views/NetworkDepositAddressDrawer.svelte b/packages/desktop/views/dashboard/drawers/network-config/views/NetworkDepositAddressDrawer.svelte index 93d14affdc..14a642a516 100644 --- a/packages/desktop/views/dashboard/drawers/network-config/views/NetworkDepositAddressDrawer.svelte +++ b/packages/desktop/views/dashboard/drawers/network-config/views/NetworkDepositAddressDrawer.svelte @@ -2,27 +2,23 @@ import { DrawerTemplate } from '@components' import { selectedAccount } from '@core/account/stores' import { localize } from '@core/i18n' - import { selectedChain } from '@core/network' + import { NetworkId, selectedNetworkForNetworkDrawer } from '@core/network' import { Router } from '@core/router' import { AddressBox } from '@ui' import { NetworkConfigRoute } from '../' + import { IAccountState, getAddressFromAccountForNetwork } from '@core/account' export let drawerRouter: Router - let depositAddress = '' - $: { - if ($selectedChain) { - const coinType = $selectedChain.coinType - depositAddress = $selectedAccount.evmAddresses[coinType] - } else { - depositAddress = $selectedAccount.depositAddress - } - } + $: depositAddress = getAddressFromAccountForNetwork( + $selectedAccount as IAccountState, + $selectedNetworkForNetworkDrawer?.id as NetworkId + ) diff --git a/packages/desktop/views/dashboard/drawers/network-config/views/NetworkInformationDrawer.svelte b/packages/desktop/views/dashboard/drawers/network-config/views/NetworkInformationDrawer.svelte index f9511fac43..a8b558dc0d 100644 --- a/packages/desktop/views/dashboard/drawers/network-config/views/NetworkInformationDrawer.svelte +++ b/packages/desktop/views/dashboard/drawers/network-config/views/NetworkInformationDrawer.svelte @@ -1,5 +1,5 @@ -{#if $selectedChain && $selectedChain.namespace === NetworkNamespace.Evm} - -{:else if $selectedChain && $selectedChain.namespace === NetworkNamespace.Stardust} - +{#if $selectedNetworkForNetworkDrawer && $selectedNetworkForNetworkDrawer.namespace === NetworkNamespace.Evm} + +{:else if $selectedNetworkForNetworkDrawer && $selectedNetworkForNetworkDrawer.namespace === NetworkNamespace.Stardust} + {/if} diff --git a/packages/desktop/views/dashboard/wallet/panes/account-summary/components/AccountNetworkSummary.svelte b/packages/desktop/views/dashboard/wallet/panes/account-summary/components/AccountNetworkSummary.svelte index 9e10f5734b..61eba75da5 100644 --- a/packages/desktop/views/dashboard/wallet/panes/account-summary/components/AccountNetworkSummary.svelte +++ b/packages/desktop/views/dashboard/wallet/panes/account-summary/components/AccountNetworkSummary.svelte @@ -4,7 +4,7 @@ import { formatCurrency, localize } from '@core/i18n' import { generateAndStoreEvmAddressForAccounts, pollEvmBalancesForAccount } from '@core/layer-2/actions' import { LedgerAppName } from '@core/ledger' - import { Network, NetworkNamespace, setSelectedChain } from '@core/network' + import { Network, NetworkNamespace, setSelectedNetworkForNetworkDrawer } from '@core/network' import { MimeType, Nft } from '@core/nfts' import { checkActiveProfileAuth } from '@core/profile/actions' import { activeProfile } from '@core/profile/stores' @@ -91,7 +91,7 @@ await generateAndStoreEvmAddressForAccounts($activeProfile.type, network.coinType, account) pollEvmBalancesForAccount($activeProfile.id, account) if ($activeProfile.type === ProfileType.Ledger) { - setSelectedChain(network) + setSelectedNetworkForNetworkDrawer(network) toggleDashboardDrawer({ id: DashboardDrawerRoute.NetworkConfig, initialSubroute: NetworkConfigRoute.ConfirmLedgerEvmAddress, diff --git a/packages/shared/src/lib/core/network/stores/index.ts b/packages/shared/src/lib/core/network/stores/index.ts index 596d045adf..8300aeaa26 100644 --- a/packages/shared/src/lib/core/network/stores/index.ts +++ b/packages/shared/src/lib/core/network/stores/index.ts @@ -1,3 +1,3 @@ export * from './networks.store' export * from './node-info.store' -export * from './selected-chain.store' +export * from './selected-network-for-network-drawer.store' diff --git a/packages/shared/src/lib/core/network/stores/selected-chain.store.ts b/packages/shared/src/lib/core/network/stores/selected-chain.store.ts deleted file mode 100644 index 629eb1024f..0000000000 --- a/packages/shared/src/lib/core/network/stores/selected-chain.store.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Writable, writable } from 'svelte/store' -import { Network } from '../types' - -export const selectedChain: Writable = writable(undefined) - -export function setSelectedChain(evmNetwork: Network): void { - selectedChain.set(evmNetwork) -} - -export function clearSelectedChain(): void { - selectedChain.set(undefined) -} diff --git a/packages/shared/src/lib/core/network/stores/selected-network-for-network-drawer.store.ts b/packages/shared/src/lib/core/network/stores/selected-network-for-network-drawer.store.ts new file mode 100644 index 0000000000..b4d108f592 --- /dev/null +++ b/packages/shared/src/lib/core/network/stores/selected-network-for-network-drawer.store.ts @@ -0,0 +1,12 @@ +import { Writable, writable } from 'svelte/store' +import { Network } from '../types' + +export const selectedNetworkForNetworkDrawer: Writable = writable(undefined) + +export function setSelectedNetworkForNetworkDrawer(evmNetwork: Network): void { + selectedNetworkForNetworkDrawer.set(evmNetwork) +} + +export function clearSelectedNetworkForNetworkDrawer(): void { + selectedNetworkForNetworkDrawer.set(undefined) +}