Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove hardcoded base token dependencies from the app #8160

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/desktop/components/popups/NodeInfoPopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import { onMount } from 'svelte'
import { Button, Checkbox, CopyableBox, Spinner, Text } from 'shared/components'
import { formatNumber, localize } from '@core/i18n'
import { INode, INodeInfo } from '@core/network'
import { INode } from '@core/network'
import { INodeInfo } from '@iota/sdk/out/types'
import { closePopup } from '@auxiliary/popup'
import { showAppNotification } from '@auxiliary/notification'
import { resolveObjectPath, setClipboard } from '@core/utils'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@

async function shouldMigrate(): Promise<boolean> {
try {
await restoreBackup(importFilePath, '', $onboardingProfile.network.protocol.bech32Hrp)
await restoreBackup(importFilePath, '', $onboardingProfile.network.bech32Hrp)
} catch (err) {
const isMigrationRequired = CLIENT_ERROR_REGEXES[ClientError.MigrationRequired].test(err?.error)
return isMigrationRequired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import { onDestroy, onMount } from 'svelte'
import { restoreProfileRouter } from '../restore-profile-router'
import { AnimationEnum } from '@auxiliary/animation'
import { getBaseToken } from '@core/profile'

$: shimmerClaimingAccounts = $onboardingProfile?.shimmerClaimingAccounts ?? []

Expand Down Expand Up @@ -199,10 +200,7 @@
{#if shimmerClaimingAccounts && shimmerClaimingAccounts?.length > 0}
<div class="flex-auto overflow-y-auto h-1 space-y-3 w-full scrollable-y">
{#each shimmerClaimingAccounts as shimmerClaimingAccount}
<ShimmerClaimingAccountTile
{shimmerClaimingAccount}
baseToken={$onboardingProfile?.network?.baseToken}
/>
<ShimmerClaimingAccountTile {shimmerClaimingAccount} baseToken={getBaseToken()} />
{/each}
</div>
{/if}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import { showAppNotification } from '@auxiliary/notification'
import { IAccount } from '@core/account'
import { localize } from '@core/i18n'
import { updateLedgerNanoStatus } from '@core/ledger'
import { AccountRecoveryProfileConfiguration, ProfileType, UnableToFindProfileTypeError } from '@core/profile'
import {
AccountRecoveryProfileConfiguration,
ProfileType,
UnableToFindProfileTypeError,
getBaseToken,
} from '@core/profile'
import { RecoverAccountsPayload, recoverAccounts } from '@core/profile-manager'
import { zip } from '@core/utils'
import { formatTokenAmountBestMatch } from '@core/wallet/utils'
import { get } from 'svelte/store'
import { SHIMMER_CLAIMING_ACCOUNT_RECOVERY_CONFIGURATION, SHIMMER_CLAIMING_ACCOUNT_SYNC_OPTIONS } from '../constants'
import { getSortedRenamedBoundAccounts, prepareShimmerClaimingAccount } from '../helpers'
import {
getOnboardingBaseToken,
onboardingProfile,
shimmerClaimingProfileManager,
updateShimmerClaimingAccount,
} from '../stores'
import { onboardingProfile, shimmerClaimingProfileManager, updateShimmerClaimingAccount } from '../stores'
import { sumTotalUnclaimedRewards } from '../utils'

const DEPTH_SEARCH_ACCOUNT_START_INDEX = 0
Expand Down Expand Up @@ -161,7 +161,7 @@ export function setTotalUnclaimedShimmerRewards(_totalUnclaimedShimmerRewards: n

function showRewardsFoundNotification(updatedTotalUnclaimedShimmerRewards: number): void {
const foundRewardsAmount = updatedTotalUnclaimedShimmerRewards - totalUnclaimedShimmerRewards
const foundRewardsAmountFormatted = formatTokenAmountBestMatch(foundRewardsAmount, getOnboardingBaseToken())
const foundRewardsAmountFormatted = formatTokenAmountBestMatch(foundRewardsAmount, getBaseToken())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break because there is no Node Info loaded in the onboarding, it's only loaded once you log in.

showAppNotification({
type: 'success',
alert: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { onboardingProfile } from '../stores'
export async function restoreBackupFromStrongholdFile(strongholdPassword: string): Promise<void> {
const { id, importFilePath, clientOptions, network } = get(onboardingProfile)
try {
await restoreBackup(importFilePath, strongholdPassword, network.protocol.bech32Hrp)
await restoreBackup(importFilePath, strongholdPassword, network.bech32Hrp)
} catch (err) {
const storageDirectory = await getStorageDirectoryOfProfile(id)
await restoreBackupByCopyingFile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import { getAccount, profileManager } from '@core/profile-manager'

import { MissingShimmerClaimingProfileManagerError } from '../errors'
import { prepareShimmerClaimingAccount } from '../helpers'
import { getOnboardingBaseToken, shimmerClaimingProfileManager, updateShimmerClaimingAccount } from '../stores'
import { shimmerClaimingProfileManager, updateShimmerClaimingAccount } from '../stores'
import { setTotalUnclaimedShimmerRewards } from '@contexts/onboarding'
import { formatTokenAmountBestMatch } from '@core/wallet/utils'
import { showAppNotification } from '@auxiliary/notification'
import { getBaseToken } from '@core/profile'

export async function syncShimmerClaimingAccount(account: IAccount): Promise<void> {
const _shimmerClaimingProfileManager = get(shimmerClaimingProfileManager)
Expand All @@ -28,7 +29,7 @@ export async function syncShimmerClaimingAccount(account: IAccount): Promise<voi

if (syncedShimmerClaimingAccount?.unclaimedRewards > 0) {
const foundRewardsAmount = syncedShimmerClaimingAccount?.unclaimedRewards
const foundRewardsAmountFormatted = formatTokenAmountBestMatch(foundRewardsAmount, getOnboardingBaseToken())
const foundRewardsAmountFormatted = formatTokenAmountBestMatch(foundRewardsAmount, getBaseToken())

showAppNotification({
type: 'success',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { derived, get, Readable, writable } from 'svelte/store'
import { isLedgerProfile } from '@core/profile'

import { IOnboardingProfile, IShimmerClaimingAccount } from '../interfaces'
import { IBaseToken } from '@core/wallet/interfaces'
import { IPersistedNetwork } from '@core/network'

export const onboardingProfile = writable<Partial<IOnboardingProfile>>(null)
Expand Down Expand Up @@ -36,7 +35,3 @@ export function updateShimmerClaimingAccount(shimmerClaimingAccount: IShimmerCla
)
updateOnboardingProfile({ shimmerClaimingAccounts })
}

export function getOnboardingBaseToken(): IBaseToken {
return get(onboardingProfile)?.network?.baseToken
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { COIN_TYPE, DEFAULT_BASE_TOKEN } from '../constants'
import { NetworkId, TokenSupply } from '../enums'
import { COIN_TYPE } from '../constants'
import { NetworkId } from '../enums'
import { IStardustNetworkMetadata } from '../interfaces'
import { NetworkMetadata } from '../types'

Expand All @@ -8,76 +8,24 @@ export const DEFAULT_NETWORK_METADATA: Readonly<{ [key in NetworkId]?: NetworkMe
id: NetworkId.Shimmer,
name: 'Shimmer',
coinType: COIN_TYPE[NetworkId.Shimmer],
protocol: {
version: 2,
networkName: 'shimmer',
bech32Hrp: 'smr',
minPowScore: 1500,
belowMaxDepth: 15,
rentStructure: {
vByteCost: 100,
vByteFactorData: 1,
vByteFactorKey: 10,
},
tokenSupply: TokenSupply.Shimmer,
},
baseToken: DEFAULT_BASE_TOKEN[NetworkId.Shimmer],
bech32Hrp: 'smr',
},
[NetworkId.Testnet]: <IStardustNetworkMetadata>{
id: NetworkId.Testnet,
name: 'Testnet',
coinType: COIN_TYPE[NetworkId.Testnet],
protocol: {
version: 2,
networkName: 'testnet',
bech32Hrp: 'rms',
minPowScore: 1500,
belowMaxDepth: 15,
rentStructure: {
vByteCost: 100,
vByteFactorData: 1,
vByteFactorKey: 10,
},
tokenSupply: TokenSupply.Testnet,
},
baseToken: DEFAULT_BASE_TOKEN[NetworkId.Testnet],
bech32Hrp: 'rms',
},
[NetworkId.Iota]: <IStardustNetworkMetadata>{
id: NetworkId.Iota,
name: 'IOTA',
coinType: COIN_TYPE[NetworkId.Iota],
protocol: {
version: 2,
networkName: 'iota',
bech32Hrp: 'iota',
minPowScore: 1500,
belowMaxDepth: 15,
rentStructure: {
vByteCost: 250,
vByteFactorData: 1,
vByteFactorKey: 10,
},
tokenSupply: TokenSupply.Iota,
},
baseToken: DEFAULT_BASE_TOKEN[NetworkId.Iota],
bech32Hrp: 'iota',
},
[NetworkId.IotaAlphanet]: <IStardustNetworkMetadata>{
id: NetworkId.IotaAlphanet,
name: 'IOTA Alphanet',
coinType: COIN_TYPE[NetworkId.IotaAlphanet],
protocol: {
version: 2,
networkName: 'iota-alphanet-2',
bech32Hrp: 'atoi',
minPowScore: 1500,
belowMaxDepth: 15,
rentStructure: {
vByteCost: 250,
vByteFactorData: 1,
vByteFactorKey: 10,
},
tokenSupply: TokenSupply.Iota,
},
baseToken: DEFAULT_BASE_TOKEN[NetworkId.IotaAlphanet],
bech32Hrp: 'atoi',
},
}
1 change: 0 additions & 1 deletion packages/shared/lib/core/network/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './coin-type.constant'
export * from './default-base-token.constant'
export * from './default-chain-configurations.constant'
export * from './default-max-parallel-api-requests'
export * from './default-network-metadata.constant'
Expand Down
1 change: 0 additions & 1 deletion packages/shared/lib/core/network/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ export * from './network-status.interface'
export * from './node-info-response.interface'
export * from './node.interface'
export * from './persisted-network.interface'
export * from './protocol.interface'
export * from './rent-structure.interface'
export * from './stardust-network-metadata.interface'
11 changes: 0 additions & 11 deletions packages/shared/lib/core/network/interfaces/protocol.interface.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { IBaseToken } from '@core/wallet'
import { NetworkId } from '../enums'
import { IProtocol } from './protocol.interface'

/**
* Holds relevant data
Expand All @@ -11,6 +9,5 @@ export interface IStardustNetworkMetadata {
id: NetworkId
name: string
coinType: number
protocol: IProtocol
baseToken: IBaseToken
bech32Hrp: string
}
6 changes: 5 additions & 1 deletion packages/shared/lib/core/network/stores/node-info.store.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { INodeInfo } from '@iota/sdk/out/types'
import { writable } from 'svelte/store'
import { writable, derived } from 'svelte/store'

export const nodeInfo = writable<INodeInfo | undefined>(undefined)

export function setNodeInfo(newNodeInfo: INodeInfo | undefined): void {
return nodeInfo.set(newNodeInfo)
}

export const nodeInfoBaseToken = derived(nodeInfo, ($nodeInfo) => $nodeInfo?.baseToken)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of this store? You don't seem to be reading it from any svelte file so all the reactivity features it comes with are effectively not used at all, thus it seems more appropiate to me to just read the nodeInfo store


export const nodeInfoProtocol = derived(nodeInfo, ($nodeInfo) => $nodeInfo?.protocol)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not used

Suggested change
export const nodeInfoProtocol = derived(nodeInfo, ($nodeInfo) => $nodeInfo?.protocol)

Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { TokenStandard } from '@core/wallet/enums'
import { COIN_TYPE, DEFAULT_NETWORK_METADATA } from '../constants'
import { NetworkId } from '../enums'
import { INodeInfoResponse, IPersistedNetwork } from '../interfaces'
import { getNetworkIdFromNetworkName } from './getNetworkIdFromNetworkName'

Expand All @@ -10,14 +8,14 @@ export function buildPersistedNetworkFromNodeInfoResponse(
): IPersistedNetwork {
const networkName = nodeInfoResponse?.nodeInfo?.protocol.networkName
const networkId = getNetworkIdFromNetworkName(networkName)
const name = networkId === NetworkId.Custom ? networkName : DEFAULT_NETWORK_METADATA[networkId]?.name
const bech32Hrp = nodeInfoResponse?.nodeInfo?.protocol.bech32Hrp ?? DEFAULT_NETWORK_METADATA?.[networkId]?.bech32Hrp
const name = networkName ?? DEFAULT_NETWORK_METADATA?.[networkId]?.name
const _coinType = coinType ?? COIN_TYPE[networkId] ?? 1
return {
id: networkId,
name: name ?? 'Unknown Network',
coinType: _coinType,
protocol: nodeInfoResponse?.nodeInfo?.protocol,
baseToken: { standard: TokenStandard.BaseToken, ...nodeInfoResponse?.nodeInfo?.baseToken },
bech32Hrp: bech32Hrp ?? 'Unknown Network',
chains: [],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you add 'Unknown Network' as fallback value here now? This will likely break it as well and it doesn't make sense to use a human-readable phrase for this either

}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { activeProfile } from '@core/profile/stores'
import { IBaseToken } from '@core/wallet'
import { IBaseToken, TokenStandard } from '@core/wallet'
import { nodeInfoBaseToken } from '@core/network'
import { get } from 'svelte/store'

export function getBaseToken(): IBaseToken {
const $activeProfile = get(activeProfile)
return $activeProfile?.network?.baseToken
const $nodeInfoBaseToken = get(nodeInfoBaseToken)

return {
standard: TokenStandard.BaseToken,
...$nodeInfoBaseToken,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { get } from 'svelte/store'

export function getNetworkHrp(): string {
const $activeProfile = get(activeProfile)
return $activeProfile.network.protocol.bech32Hrp
return $activeProfile.network.bech32Hrp
}
Loading
Loading