Skip to content

Commit

Permalink
fix: show popup if ledger disconnected (#2253)
Browse files Browse the repository at this point in the history
* fix: show ledger connect pop-up if disconnected

* chore: type improvements

* chore: use async variant

* chore: revert unused code

* chore: remove redundant code

* fix: prop name

* chore: rename onContinue to onSuccess

---------

Co-authored-by: Nicole O'Brien <[email protected]>
  • Loading branch information
Tuditi and nicole-obrien authored Apr 5, 2024
1 parent 9bf9f9c commit e6b6acb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import PopupTemplate from '../PopupTemplate.svelte'
export let ledgerAppName: LedgerAppName
export let onContinue: () => void
export let onSuccess: () => void
$: isDisconnected = $ledgerConnectionState === LedgerConnectionState.Disconnected
$: isLocked = $ledgerConnectionState === LedgerConnectionState.Locked
Expand Down Expand Up @@ -53,7 +53,7 @@
function continueFlow(): void {
closeProfileAuthPopup()
onContinue?.()
onSuccess?.()
}
function onCancelClick(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { Animation, Illustration } from '@ui'
import { completeOnboardingProcess, isOnboardingLedgerProfile, onboardingProfile } from '@contexts/onboarding'
import { localize } from '@core/i18n'
import { LedgerAppName, checkOrConnectLedger } from '@core/ledger'
import { LedgerAppName, checkOrConnectLedgerAsync } from '@core/ledger'
import { profiles } from '@core/profile/stores'
import { OnboardingLayout } from '@views/components'
import SuccessSvg from '@views/onboarding/components/SuccessSvg.svelte'
Expand All @@ -22,16 +22,11 @@
$: appName =
$onboardingProfile?.network?.id === SupportedNetworkId.Iota ? LedgerAppName.Iota : LedgerAppName.Shimmer
function onContinueClick(): void {
if ($isOnboardingLedgerProfile) {
checkOrConnectLedger(_continue, false, appName)
} else {
void _continue()
}
}
async function _continue(): Promise<void> {
async function onContinueClick(): Promise<void> {
try {
if ($isOnboardingLedgerProfile) {
await checkOrConnectLedgerAsync(appName)
}
await completeOnboardingProcess()
void login({ isFromOnboardingFlow: true })
$onboardingRouter.next()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
import { IAccount } from '@core/account'
import { DEFAULT_SYNC_OPTIONS } from '@core/account/constants'
import { localize } from '@core/i18n'
import { LedgerAppName, checkOrConnectLedger, ledgerRaceConditionProtectionWrapper } from '@core/ledger'
import { LedgerAppName, checkOrConnectLedgerAsync, ledgerRaceConditionProtectionWrapper } from '@core/ledger'
import { StardustNetworkId, SupportedNetworkId } from '@core/network'
import { ProfileType } from '@core/profile'
import { RecoverAccountsPayload, createAccount, recoverAccounts } from '@core/profile-manager'
import { DEFAULT_ACCOUNT_RECOVERY_CONFIGURATION } from '@core/profile/constants'
import { checkOrUnlockStronghold } from '@core/stronghold/actions'
import { formatTokenAmountBestMatch } from '@core/token'
import { OnboardingLayout } from '@views/components'
import { onDestroy, onMount } from 'svelte'
Expand All @@ -20,9 +19,9 @@
total: string
}
const { network, type } = $onboardingProfile
const { network, type } = $onboardingProfile ?? {}
const DEFAULT_CONFIG = DEFAULT_ACCOUNT_RECOVERY_CONFIGURATION[type]
const DEFAULT_CONFIG = DEFAULT_ACCOUNT_RECOVERY_CONFIGURATION[type as ProfileType]
let accountStartIndex = 0
let accountGapLimit = DEFAULT_CONFIG.initialAccountRange
Expand Down Expand Up @@ -101,7 +100,7 @@
try {
error = ''
isBusy = true
const _function = networkSearchMethod[network.id] ?? singleAddressSearch
const _function = networkSearchMethod[network?.id] ?? singleAddressSearch
await ledgerRaceConditionProtectionWrapper(_function)
} catch (err) {
error = localize(err.error)
Expand All @@ -120,31 +119,24 @@
const alias = account.getMetadata()?.alias
const balance = await account.getBalance()
const baseToken = network.baseToken
const baseToken = network?.baseToken
const baseCoinBalance = balance?.baseCoin?.total ?? BigInt(0)
const total = formatTokenAmountBestMatch(baseCoinBalance, baseToken)
return { alias, total }
}
function checkOnboardingProfileAuth(callback: () => Promise<unknown>): Promise<unknown> {
if (type === ProfileType.Software) {
return checkOrUnlockStronghold(callback)
} else {
return checkOrConnectLedger(
callback,
false,
network.id === SupportedNetworkId.Iota ? LedgerAppName.Iota : LedgerAppName.Shimmer
)
}
}
function onContinueClick(): void {
$restoreProfileRouter.next()
}
async function onFindBalancesClick(): Promise<void> {
await checkOnboardingProfileAuth(async () => await findBalances())
if (type === ProfileType.Ledger) {
await checkOrConnectLedgerAsync(
network?.id === SupportedNetworkId.Iota ? LedgerAppName.Iota : LedgerAppName.Shimmer
)
}
await findBalances()
}
onMount(async () => {
Expand Down

0 comments on commit e6b6acb

Please sign in to comment.