Skip to content

Commit 739d987

Browse files
chore: improve error handling & add alphanet
1 parent ae1f838 commit 739d987

File tree

2 files changed

+46
-81
lines changed

2 files changed

+46
-81
lines changed

Diff for: packages/desktop/components/modals/AccountActionsMenu.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
<Modal bind:this={modal} {...$$restProps}>
7373
<account-actions-menu class="flex flex-col">
7474
<MenuItem icon={Icon.Doc} title={localize('actions.viewBalanceBreakdown')} onClick={onViewBalanceClick} />
75-
{#if $activeProfile?.network?.id === NetworkId.Iota}
75+
{#if $activeProfile?.network?.id === NetworkId.Iota || $activeProfile?.network?.id === NetworkId.IotaAlphanet}
7676
<MenuItem
7777
icon={Icon.Timer}
7878
title={localize('actions.viewAddressHistory')}

Diff for: packages/desktop/components/popups/AddressHistoryPopup.svelte

+45-80
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<script lang="ts">
2-
import { onMount } from 'svelte'
3-
import { getProfileManager } from '@core/profile-manager/stores'
4-
import { checkActiveProfileAuth, getActiveProfile, updateAccountPersistedDataOnActiveProfile } from '@core/profile'
5-
import { fetchWithTimeout } from '@core/nfts'
6-
import { CHRONICLE_URLS, CHRONICLE_ADDRESS_HISTORY_ROUTE } from '@core/network/constants/chronicle-urls.constant'
7-
import { getSelectedAccount } from '@core/account'
8-
import { Button, Error, FontWeight, KeyValueBox, Text, TextType, Spinner } from 'shared/components'
9-
import VirtualList from '@sveltejs/svelte-virtual-list'
10-
import { AccountAddress } from '@iota/sdk/out/types'
11-
import { closePopup } from '@auxiliary/popup/actions/closePopup'
2+
import { getSelectedAccount, selectedAccount } from '@core/account'
3+
import { handleError } from '@core/error/handlers/handleError'
124
import { localize } from '@core/i18n'
5+
import { CHRONICLE_ADDRESS_HISTORY_ROUTE, CHRONICLE_URLS } from '@core/network/constants/chronicle-urls.constant'
6+
import { fetchWithTimeout } from '@core/nfts'
7+
import { checkActiveProfileAuth, getActiveProfile, updateAccountPersistedDataOnActiveProfile } from '@core/profile'
8+
import { getProfileManager } from '@core/profile-manager/stores'
139
import { truncateString } from '@core/utils'
10+
import { AccountAddress } from '@iota/sdk/out/types'
11+
import VirtualList from '@sveltejs/svelte-virtual-list'
12+
import { Button, FontWeight, KeyValueBox, Spinner, Text, TextType } from 'shared/components'
13+
import { onMount } from 'svelte'
1414
1515
interface AddressHistory {
1616
address: string
@@ -24,37 +24,26 @@
2424
]
2525
}
2626
27-
const account = getSelectedAccount()
28-
const accountIndex = account.index
29-
const network = getActiveProfile().network.id
27+
const activeProfile = getActiveProfile()
3028
const ADDRESS_GAP_LIMIT = 20
3129
32-
let error: string = ''
30+
$: accountIndex = $selectedAccount?.index
31+
$: network = activeProfile?.network?.id
32+
$: knownAddresses = $selectedAccount?.knownAddresses
33+
3334
let searchURL: string
34-
let knownAddresses: AccountAddress[] | undefined = undefined
3535
let searchAddressStartIndex = 0
3636
let currentSearchGap = 0
3737
let isBusy = false
3838
3939
onMount(() => {
4040
knownAddresses = getSelectedAccount().knownAddresses
41-
if (knownAddresses === undefined) {
42-
getSelectedAccount()
43-
?.addresses()
44-
.then((_addressList) => {
45-
knownAddresses = _addressList ?? []
46-
updateAccountPersistedDataOnActiveProfile(accountIndex, { knownAddresses })
47-
})
48-
.catch((err) => {
49-
console.error(err)
50-
})
51-
}
5241
5342
if (CHRONICLE_URLS[network] && CHRONICLE_URLS[network].length > 0) {
5443
const chronicleRoot = CHRONICLE_URLS[network][0]
5544
searchURL = `${chronicleRoot}${CHRONICLE_ADDRESS_HISTORY_ROUTE}`
5645
} else {
57-
error = localize('popups.addressHistory.errorNoChronicle')
46+
throw new Error(localize('popups.addressHistory.errorNoChronicle'))
5847
}
5948
})
6049
@@ -64,14 +53,12 @@
6453
const addressHistory: AddressHistory = await response.json()
6554
return addressHistory?.items?.length > 0
6655
} catch (err) {
67-
console.error(err)
68-
error = localize('popups.addressHistory.errorFailedFetch')
56+
throw new Error(localize('popups.addressHistory.errorFailedFetch'))
6957
}
7058
}
7159
7260
async function generateNextUnknownAddress(): Promise<[string, number]> {
7361
let nextUnknownAddress: string
74-
7562
try {
7663
do {
7764
nextUnknownAddress = await getProfileManager().generateEd25519Address(
@@ -82,63 +69,47 @@
8269
searchAddressStartIndex++
8370
} while (knownAddresses.map((accountAddress) => accountAddress.address).includes(nextUnknownAddress))
8471
} catch (err) {
85-
console.error(err)
86-
error = localize('popups.addressHistory.errorFailedGenerate')
72+
throw new Error(localize('popups.addressHistory.errorFailedGenerate'))
8773
}
8874
8975
return [nextUnknownAddress, searchAddressStartIndex - 1]
9076
}
9177
9278
async function search(): Promise<void> {
9379
currentSearchGap = 0
94-
const isUnlocked = await unlock
95-
96-
if (isUnlocked && !error) {
97-
isBusy = true
98-
while (currentSearchGap < ADDRESS_GAP_LIMIT) {
99-
const [nextAddressToCheck, addressIndex] = await generateNextUnknownAddress()
100-
if (!nextAddressToCheck) {
101-
isBusy = false
102-
break
103-
}
80+
while (currentSearchGap < ADDRESS_GAP_LIMIT) {
81+
const [nextAddressToCheck, addressIndex] = await generateNextUnknownAddress()
82+
if (!nextAddressToCheck) {
83+
isBusy = false
84+
break
85+
}
10486
105-
const hasHistory = await isAddressWithHistory(nextAddressToCheck)
106-
if (error) {
107-
isBusy = false
108-
break
87+
const hasHistory = await isAddressWithHistory(nextAddressToCheck)
88+
if (hasHistory) {
89+
const accountAddress: AccountAddress = {
90+
address: nextAddressToCheck,
91+
keyIndex: addressIndex,
92+
internal: false,
93+
used: true,
10994
}
11095
111-
if (hasHistory) {
112-
const accountAddress: AccountAddress = {
113-
address: nextAddressToCheck,
114-
keyIndex: addressIndex,
115-
internal: false,
116-
used: true,
117-
}
118-
119-
knownAddresses.push(accountAddress)
120-
} else {
121-
currentSearchGap++
122-
}
96+
knownAddresses.push(accountAddress)
97+
} else {
98+
currentSearchGap++
12399
}
124-
125-
updateAccountPersistedDataOnActiveProfile(accountIndex, { knownAddresses })
126-
isBusy = false
127100
}
101+
updateAccountPersistedDataOnActiveProfile(accountIndex, { knownAddresses })
128102
}
129103
130-
const unlock = new Promise<boolean>((resolve) => {
131-
const onSuccess: () => Promise<void> = () => {
132-
resolve(true)
133-
return Promise.resolve()
104+
async function handleSearchClick(): Promise<void> {
105+
isBusy = true
106+
try {
107+
await checkActiveProfileAuth(search, { stronghold: true, ledger: true })
108+
} catch (err) {
109+
handleError(err)
110+
} finally {
111+
isBusy = false
134112
}
135-
const onCancel: () => void = () => resolve(false)
136-
const config = { stronghold: true, ledger: true }
137-
checkActiveProfileAuth(onSuccess, config, onCancel)
138-
})
139-
140-
function onCancelClick(): void {
141-
closePopup()
142113
}
143114
</script>
144115

@@ -177,18 +148,12 @@
177148
<Spinner />
178149
</div>
179150
{/if}
180-
{#if error}
181-
<Error {error} />
182-
{/if}
183151
</div>
184152
<div class="flex flex-row flex-nowrap w-full space-x-4 mt-6">
185-
<Button classes="w-full" outline onClick={onCancelClick} disabled={isBusy}>
186-
{localize('actions.cancel')}
187-
</Button>
188153
<Button
189154
classes="w-full"
190-
onClick={search}
191-
disabled={isBusy || !!error}
155+
onClick={handleSearchClick}
156+
disabled={isBusy}
192157
{isBusy}
193158
busyMessage={localize('actions.searching')}
194159
>

0 commit comments

Comments
 (0)