Skip to content

Commit

Permalink
fix: don't override network with node info
Browse files Browse the repository at this point in the history
Co-authored-by: Mark Nardi <[email protected]>
  • Loading branch information
nicole-obrien and MarkNerdi committed May 10, 2024
1 parent bedb937 commit db75e43
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
Original file line number Diff line number Diff line change
@@ -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<void> {
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()
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -67,7 +67,7 @@ export async function login(loginOptions?: ILoginOptions): Promise<void> {

// Step 2: get node info to check we have a synced node
incrementLoginProgress()
await checkAndUpdateActiveProfileNetwork()
await checkAndInitializeActiveProfileNetwork()

// Step 3: load accounts
incrementLoginProgress()
Expand Down

0 comments on commit db75e43

Please sign in to comment.