From db75e438caf0395548907824196402029592e6e2 Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Fri, 10 May 2024 11:43:49 +0100 Subject: [PATCH] fix: don't override network with node info Co-authored-by: Mark Nardi --- .../organisms/NodeConfigurationForm.svelte | 6 +---- .../checkAndInitializeActiveProfileNetwork.ts | 25 +++++++++++++++++++ .../checkAndUpdateActiveProfileNetwork.ts | 24 ------------------ .../profile/actions/active-profile/index.ts | 2 +- .../profile/actions/active-profile/login.ts | 4 +-- 5 files changed, 29 insertions(+), 32 deletions(-) create mode 100644 packages/shared/src/lib/core/profile/actions/active-profile/checkAndInitializeActiveProfileNetwork.ts delete mode 100644 packages/shared/src/lib/core/profile/actions/active-profile/checkAndUpdateActiveProfileNetwork.ts diff --git a/packages/shared/src/components/organisms/NodeConfigurationForm.svelte b/packages/shared/src/components/organisms/NodeConfigurationForm.svelte index 87de8e20f3..403f98577d 100644 --- a/packages/shared/src/components/organisms/NodeConfigurationForm.svelte +++ b/packages/shared/src/components/organisms/NodeConfigurationForm.svelte @@ -69,11 +69,7 @@ return Promise.reject({ type: 'validationError', error: formError }) } - const errorUrlValidity = checkNodeUrlValidity( - currentClientOptions?.nodes, - node.url, - $activeProfile.features.developer - ) + const errorUrlValidity = checkNodeUrlValidity(currentClientOptions?.nodes, node.url, false) if (errorUrlValidity) { formError = localize(errorUrlValidity) ?? '' return Promise.reject({ type: 'validationError', error: formError }) diff --git a/packages/shared/src/lib/core/profile/actions/active-profile/checkAndInitializeActiveProfileNetwork.ts b/packages/shared/src/lib/core/profile/actions/active-profile/checkAndInitializeActiveProfileNetwork.ts new file mode 100644 index 0000000000..c0cd4872c8 --- /dev/null +++ b/packages/shared/src/lib/core/profile/actions/active-profile/checkAndInitializeActiveProfileNetwork.ts @@ -0,0 +1,25 @@ +import { get } from 'svelte/store' +import { localize } from '@core/i18n' +import { getAndUpdateNodeInfo } from '@core/network/actions' +import { activeProfile } from '@core/profile/stores' +import { NetworkNamespace, initializeNetworks } from '@core/network' + +export async function checkAndInitializeActiveProfileNetwork(): Promise { + const $activeProfile = get(activeProfile) + const existingNetwork = $activeProfile?.network + const nodeInfoResponse = await getAndUpdateNodeInfo(true) + if (!nodeInfoResponse) { + throw new Error(localize('error.network.mismatch')) + } + + const networkIdFromNode = `${NetworkNamespace.Stardust}:${nodeInfoResponse?.nodeInfo?.protocol.networkName}` + if (existingNetwork?.id !== networkIdFromNode) { + throw new Error(localize('error.network.mismatch', { networkId: networkIdFromNode })) + } + + if (existingNetwork?.protocol.version !== nodeInfoResponse?.nodeInfo?.protocol.version) { + throw new Error(localize('error.network.version.mismatch', { networkId: networkIdFromNode })) + } + + initializeNetworks() +} diff --git a/packages/shared/src/lib/core/profile/actions/active-profile/checkAndUpdateActiveProfileNetwork.ts b/packages/shared/src/lib/core/profile/actions/active-profile/checkAndUpdateActiveProfileNetwork.ts deleted file mode 100644 index 77d359b917..0000000000 --- a/packages/shared/src/lib/core/profile/actions/active-profile/checkAndUpdateActiveProfileNetwork.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { get } from 'svelte/store' -import { localize } from '@core/i18n' -import { getAndUpdateNodeInfo } from '@core/network/actions' -import { buildPersistedNetworkFromNodeInfoResponse } from '@core/network/utils' -import { activeProfile, updateActiveProfile } from '@core/profile/stores' -import { initializeNetworks } from '@core/network' - -export async function checkAndUpdateActiveProfileNetwork(): Promise { - const $activeProfile = get(activeProfile) - const existingNetwork = $activeProfile?.network - const nodeInfoResponse = await getAndUpdateNodeInfo(true) - if (!nodeInfoResponse) { - return - } - - const network = buildPersistedNetworkFromNodeInfoResponse(nodeInfoResponse, existingNetwork.coinType) - if (existingNetwork?.id === network.id) { - network.chainConfigurations = $activeProfile.network?.chainConfigurations || [] - updateActiveProfile({ network }) - initializeNetworks() - } else { - throw new Error(localize('error.network.mismatch', { networkId: network.id })) - } -} diff --git a/packages/shared/src/lib/core/profile/actions/active-profile/index.ts b/packages/shared/src/lib/core/profile/actions/active-profile/index.ts index 4180bb8264..9751385cc1 100644 --- a/packages/shared/src/lib/core/profile/actions/active-profile/index.ts +++ b/packages/shared/src/lib/core/profile/actions/active-profile/index.ts @@ -1,6 +1,6 @@ export * from './checkActiveProfileAuth' export * from './checkAndRemoveProfilePicture' -export * from './checkAndUpdateActiveProfileNetwork' +export * from './checkAndInitializeActiveProfileNetwork' export * from './getBaseToken' export * from './getNetworkHrp' export * from './loadAccounts' diff --git a/packages/shared/src/lib/core/profile/actions/active-profile/login.ts b/packages/shared/src/lib/core/profile/actions/active-profile/login.ts index 2aae66ebb8..2b017354e0 100644 --- a/packages/shared/src/lib/core/profile/actions/active-profile/login.ts +++ b/packages/shared/src/lib/core/profile/actions/active-profile/login.ts @@ -34,7 +34,7 @@ import { } from '../../stores' import { isLedgerProfile, waitForPreviousManagerToBeDestroyed } from '../../utils' // import { checkAndRemoveProfilePicture } from './checkAndRemoveProfilePicture' -import { checkAndUpdateActiveProfileNetwork } from './checkAndUpdateActiveProfileNetwork' +import { checkAndInitializeActiveProfileNetwork } from './checkAndInitializeActiveProfileNetwork' import { loadAccounts } from './loadAccounts' import { logout } from './logout' import { subscribeToWalletApiEventsForActiveProfile } from './subscribeToWalletApiEventsForActiveProfile' @@ -67,7 +67,7 @@ export async function login(loginOptions?: ILoginOptions): Promise { // Step 2: get node info to check we have a synced node incrementLoginProgress() - await checkAndUpdateActiveProfileNetwork() + await checkAndInitializeActiveProfileNetwork() // Step 3: load accounts incrementLoginProgress()