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: add new iota testnet and iota testnet evm #2471

Merged
merged 16 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
54 changes: 51 additions & 3 deletions packages/desktop/features/onboarding.features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const onboardingFeaturesForShimmer: IOnboardingFeaturesForNetwork = {
},
}

const onboardingFeaturesForTestnet: IOnboardingFeaturesForNetwork = {
const onboardingFeaturesForIotaTestnet: IOnboardingFeaturesForNetwork = {
enabled: true,
newProfile: {
enabled: true,
Expand Down Expand Up @@ -124,7 +124,41 @@ const onboardingFeaturesForTestnet: IOnboardingFeaturesForNetwork = {
},
claimRewards: {
enabled: true,
hidden: false,
hidden: true,
recoveryPhrase: {
enabled: true,
},
strongholdBackup: {
enabled: true,
},
ledgerBackup: {
enabled: true,
},
},
defaultIscChains: {
enabled: true,
},
defaultEvmChains: {
enabled: true,
},
}

const onboardingFeaturesForTestnet: IOnboardingFeaturesForNetwork = {
enabled: true,
newProfile: {
enabled: true,
softwareProfile: {
enabled: true,
skipVerification: {
enabled: false,
},
},
ledgerProfile: {
enabled: true,
},
},
restoreProfile: {
enabled: true,
recoveryPhrase: {
enabled: true,
},
Expand All @@ -135,6 +169,19 @@ const onboardingFeaturesForTestnet: IOnboardingFeaturesForNetwork = {
enabled: true,
},
},
claimRewards: {
enabled: true,
hidden: false,
recoveryPhrase: {
enabled: false,
},
strongholdBackup: {
enabled: false,
},
ledgerBackup: {
enabled: false,
},
},
defaultIscChains: {
enabled: true,
},
Expand Down Expand Up @@ -183,7 +230,7 @@ const onboardingFeaturesForCustom: IOnboardingFeaturesForNetwork = {
},
},
defaultIscChains: {
enabled: false,
enabled: true,
},
defaultEvmChains: {
enabled: false,
Expand All @@ -194,6 +241,7 @@ const onboardingFeatures: OnboardingFeatures = {
enabled: true,
iota: onboardingFeaturesForIota,
shimmer: onboardingFeaturesForShimmer,
iotaTestnet: onboardingFeaturesForIotaTestnet,
testnet: onboardingFeaturesForTestnet,
custom: onboardingFeaturesForCustom,
importFromThirdParty: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import features from '@features/features'
import { NetworkSetupRoute } from './network-setup-route.enum'
import { networkSetupRoute } from './network-setup-router'
import { ChooseNetworkView, CustomNetworkView } from './views'
import { ChooseNetworkView, CustomNetworkView, TestnetSelectionView } from './views'

$: if (features.analytics.onboardingRoute.enabled && $networkSetupRoute) {
Platform.trackEvent('network-setup-route', { route: $networkSetupRoute })
Expand All @@ -12,6 +12,8 @@

{#if $networkSetupRoute === NetworkSetupRoute.ChooseNetwork}
<ChooseNetworkView />
{:else if $networkSetupRoute === NetworkSetupRoute.TestnetSelection}
<TestnetSelectionView />
{:else if $networkSetupRoute === NetworkSetupRoute.CustomNetwork}
<CustomNetworkView />
{/if}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export enum NetworkSetupRoute {
ChooseNetwork = 'chooseNetwork',
TestnetSelection = 'testnetSelection',
CustomNetwork = 'customNetwork',
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,26 @@ export class NetworkSetupRouter extends Subrouter<NetworkSetupRoute> {
super(NetworkSetupRoute.ChooseNetwork, networkSetupRoute, parentRouter)
}

next(): void {
next(params?: { type: 'testnet' | 'custom' }): void {
const _onboardingProfile = get(onboardingProfile)
const currentRoute = get(this.routeStore)
switch (currentRoute) {
case NetworkSetupRoute.ChooseNetwork: {
const network = _onboardingProfile?.network
if (network) {
if (params?.type === 'testnet') {
networkSetupRoute.set(NetworkSetupRoute.TestnetSelection)
return
} else if (network) {
this.parentRouter?.next()
return
} else {
this.setNext(NetworkSetupRoute.CustomNetwork)
break
networkSetupRoute.set(NetworkSetupRoute.CustomNetwork)
return
}
}
case NetworkSetupRoute.TestnetSelection:
this.parentRouter?.next()
return
case NetworkSetupRoute.CustomNetwork:
this.parentRouter?.next()
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,26 @@
}

function onContinueClick(): void {
if (selectedNetworkType !== OnboardingNetworkType.Custom) {
const networkName = getNetworkNameFromOnboardingNetworkType(selectedNetworkType)
const networkId: StardustNetworkId = `${NetworkNamespace.Stardust}:${networkName}`
const network = getDefaultStardustNetwork(networkId)
const clientOptions = getDefaultClientOptions(networkId)
updateOnboardingProfile({ network, clientOptions })
switch (selectedNetworkType) {
case OnboardingNetworkType.Iota:
case OnboardingNetworkType.Shimmer:
{
const networkName = getNetworkNameFromOnboardingNetworkType(selectedNetworkType)
const networkId: StardustNetworkId = `${NetworkNamespace.Stardust}:${networkName}`
const network = getDefaultStardustNetwork(networkId)
const clientOptions = getDefaultClientOptions(networkId)
updateOnboardingProfile({ network, clientOptions })
$networkSetupRouter.next()
}
break
case OnboardingNetworkType.IotaTestnet:
case OnboardingNetworkType.Testnet:
$networkSetupRouter.next({ type: 'testnet' })
break
case OnboardingNetworkType.Custom:
$networkSetupRouter.next({ type: 'custom' })
break
}
$networkSetupRouter.next()
}

function getNetworkNameFromOnboardingNetworkType(
Expand All @@ -55,6 +67,8 @@
return StardustNetworkName.Iota
case OnboardingNetworkType.Shimmer:
return StardustNetworkName.Shimmer
case OnboardingNetworkType.IotaTestnet:
return StardustNetworkName.IotaTestnet
case OnboardingNetworkType.Testnet:
return StardustNetworkName.Testnet
case OnboardingNetworkType.Custom:
Expand Down Expand Up @@ -96,8 +110,8 @@
)}
icon={IconName.Iota}
iconSize="md"
iconColor="#ffffff"
backgroundColor="#000000"
iconColor="iota"
backgroundColor="iota-background"
hidden={features?.onboarding?.[OnboardingNetworkType.Iota]?.hidden}
disabled={!features?.onboarding?.[OnboardingNetworkType.Iota]?.enabled}
onClick={() => onNetworkClick(OnboardingNetworkType.Iota)}
Expand All @@ -112,8 +126,8 @@
)}
icon={IconName.Shimmer}
iconSize="md"
iconColor="blue-900"
backgroundColor="shimmer"
iconColor="shimmer"
backgroundColor="shimmer-background"
hidden={features?.onboarding?.[OnboardingNetworkType.Shimmer]?.hidden}
disabled={!features?.onboarding?.[OnboardingNetworkType.Shimmer]?.enabled}
onClick={() => onNetworkClick(OnboardingNetworkType.Shimmer)}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<script lang="ts">
import { IconName } from '@bloomwalletio/ui'
import {
OnboardingNetworkType,
initialiseOnboardingProfile,
onboardingProfile,
updateOnboardingProfile,
} from '@contexts/onboarding'
import { localize } from '@core/i18n'
import {
NetworkNamespace,
StardustNetworkId,
StardustNetworkName,
getDefaultClientOptions,
getDefaultStardustNetwork,
} from '@core/network'
import features from '@features/features'
import { OnboardingLayout } from '@views/components'
import { onMount } from 'svelte'
import { ButtonTile } from '../../../../components'
import { networkSetupRouter } from '../network-setup-router'

let selectedNetworkType: OnboardingNetworkType = OnboardingNetworkType.IotaTestnet
function onNetworkClick(networkType: OnboardingNetworkType): void {
if (selectedNetworkType === networkType) {
onContinueClick()
} else {
selectedNetworkType = networkType
}
}

function onContinueClick(): void {
const networkName = getNetworkNameFromOnboardingNetworkType(selectedNetworkType)
const networkId: StardustNetworkId = `${NetworkNamespace.Stardust}:${networkName}`
const network = getDefaultStardustNetwork(networkId)
const clientOptions = getDefaultClientOptions(networkId)
updateOnboardingProfile({ network, clientOptions })
$networkSetupRouter.next()
}

function getNetworkNameFromOnboardingNetworkType(
networkType: OnboardingNetworkType
): StardustNetworkName | undefined {
switch (networkType) {
case OnboardingNetworkType.IotaTestnet:
return StardustNetworkName.IotaTestnet
case OnboardingNetworkType.Testnet:
return StardustNetworkName.Testnet
}
}

function onBackClick(): void {
$networkSetupRouter.previous()
}

onMount(async () => {
// Clean up if user has navigated back to this view
updateOnboardingProfile({ network: undefined, clientOptions: undefined })
// If coming from this view with no profiles, initialise a new profile
if (!$onboardingProfile?.id) {
await initialiseOnboardingProfile()
}
})
</script>

<OnboardingLayout
title={localize('views.onboarding.networkSetup.testnetSelection.title')}
continueButton={{
onClick: onContinueClick,
disabled: !selectedNetworkType,
}}
backButton={{
text: localize('actions.back'),
onClick: onBackClick,
}}
>
<div slot="content" class="flex flex-col space-y-3">
<ButtonTile
primaryText={localize(
`views.onboarding.networkSetup.testnetSelection.${OnboardingNetworkType.IotaTestnet}.primary`
)}
secondaryText={localize(
`views.onboarding.networkSetup.testnetSelection.${OnboardingNetworkType.IotaTestnet}.secondary`
)}
icon={IconName.Iota}
iconSize="md"
iconColor="text-secondary"
backgroundColor="iota-background"
hidden={features?.onboarding?.[OnboardingNetworkType.IotaTestnet]?.hidden}
disabled={!features?.onboarding?.[OnboardingNetworkType.IotaTestnet]?.enabled}
onClick={() => onNetworkClick(OnboardingNetworkType.IotaTestnet)}
selected={selectedNetworkType === OnboardingNetworkType.IotaTestnet}
/>
<ButtonTile
primaryText={localize(
`views.onboarding.networkSetup.testnetSelection.${OnboardingNetworkType.Testnet}.primary`
)}
secondaryText={localize(
`views.onboarding.networkSetup.testnetSelection.${OnboardingNetworkType.Testnet}.secondary`
)}
icon={IconName.Shimmer}
iconSize="md"
iconColor="text-secondary"
backgroundColor="shimmer-background"
hidden={features?.onboarding?.[OnboardingNetworkType.Testnet]?.hidden}
disabled={!features?.onboarding?.[OnboardingNetworkType.Testnet]?.enabled}
onClick={() => onNetworkClick(OnboardingNetworkType.Testnet)}
selected={selectedNetworkType === OnboardingNetworkType.Testnet}
/>
</div>
</OnboardingLayout>
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { default as ChooseNetworkView } from './ChooseNetworkView.svelte'
export { default as CustomNetworkView } from './CustomNetworkView.svelte'
export { default as TestnetSelectionView } from './TestnetSelectionView.svelte'
12 changes: 8 additions & 4 deletions packages/shared/src/components/avatars/NetworkAvatar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,23 @@
const AVATAR_BACKGROUND_COLOR: { [id in NetworkId]?: string } = {
[SupportedNetworkId.Iota]: 'iota-background',
[SupportedNetworkId.Shimmer]: 'shimmer-background',
[SupportedNetworkId.Testnet]: 'shimmer-background',
[SupportedNetworkId.Testnet]: 'text-secondary',
[SupportedNetworkId.IotaTestnet]: 'text-secondary',
[SupportedNetworkId.IotaEvm]: 'iota-evm-background',
[SupportedNetworkId.ShimmerEvm]: 'shimmer-evm-background',
[SupportedNetworkId.TestnetEvm]: 'shimmer-evm-background',
[SupportedNetworkId.IotaTestnetEvm]: 'iota-evm-background/90',
[SupportedNetworkId.TestnetEvm]: 'shimmer-evm-background/90',
}

const AVATAR_TEXT_COLOR: { [id in NetworkId]?: string } = {
[SupportedNetworkId.Iota]: 'iota',
[SupportedNetworkId.Shimmer]: 'shimmer',
[SupportedNetworkId.Testnet]: 'shimmer',
[SupportedNetworkId.IotaTestnet]: '#FFFFFF',
[SupportedNetworkId.Testnet]: '#FFFFFF',
[SupportedNetworkId.IotaEvm]: 'iota-evm',
[SupportedNetworkId.ShimmerEvm]: 'shimmer-evm',
[SupportedNetworkId.TestnetEvm]: 'shimmer-evm',
[SupportedNetworkId.IotaTestnetEvm]: '#FFFFFF',
[SupportedNetworkId.TestnetEvm]: '#FFFFFF',
}

let anchor: HTMLElement
Expand Down
Loading
Loading