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()