Skip to content

Commit

Permalink
feat: improve balance finder by allowing searching on current wallet (#…
Browse files Browse the repository at this point in the history
…7582)

* feat: Increase a bit the search

* feat: add a checkbox to only find on the current wallet

* feat: include checkbox inside of the popup

* fix: do not use hasUsedBalanceFinder to reset the search config

* fix: persist searchInCurrentWallet and shouldInitSearch in popup

* enhancement: improve balance finder UI for single wallet search

---------

Co-authored-by: Begoña Álvarez de la Cruz <[email protected]>
  • Loading branch information
cpl121 and begonaalvarezd authored Oct 19, 2023
1 parent fb2c5bd commit 7b9a529
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 19 deletions.
66 changes: 52 additions & 14 deletions packages/desktop/components/popups/BalanceFinderPopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { Icon as IconEnum } from '@auxiliary/icon'
import { showAppNotification } from '@auxiliary/notification'
import { PopupId, closePopup, openPopup } from '@auxiliary/popup'
import { findBalances, sumBalanceForAccounts, SearchAlgorithmType } from '@core/account'
import { findBalances, sumBalanceForAccounts, SearchAlgorithmType, selectedAccountIndex } from '@core/account'
import { localize } from '@core/i18n'
import { displayNotificationForLedgerProfile, ledgerNanoStatus } from '@core/ledger'
import { NetworkId } from '@core/network'
Expand All @@ -21,7 +21,18 @@
generateAndStoreActivitiesForAllAccounts,
refreshAccountAssetsForActiveProfile,
} from '@core/wallet'
import { Button, FontWeight, KeyValueBox, Text, TextHint, TextType, Icon, Tile, Spinner } from 'shared/components'
import {
Button,
FontWeight,
KeyValueBox,
Text,
TextHint,
TextType,
Icon,
Tile,
Spinner,
Checkbox,
} from 'shared/components'
import { TextHintVariant } from 'shared/components/enums'
import { onDestroy } from 'svelte'
import VirtualList from '@sveltejs/svelte-virtual-list'
Expand All @@ -33,20 +44,29 @@
export let consolidateAccountsOnLoad = false
export let title: string
export let body: string
const { isStrongholdLocked, network } = $activeProfile
const searchAlgorithm: SearchAlgorithmType =
network.id === NetworkId.Iota || NetworkId.IotaAlphanet ? SearchAlgorithmType.IDS : SearchAlgorithmType.BFS
export let searchInCurrentWallet: boolean = false
export let shouldInitSearch: boolean = false
let error = ''
let isBusy = false
const { isStrongholdLocked, network } = $activeProfile
$: isTransferring = $visibleActiveAccounts.some(
(account) => account.hasConsolidatingOutputsTransactionInProgress || account.isTransferring
)
$: visibleWalletList = searchInCurrentWallet
? $visibleActiveAccounts?.filter((account) => account.index === $selectedAccountIndex)
: $visibleActiveAccounts
$: searchForBalancesOnLoad && !$isStrongholdLocked && onFindBalancesClick()
$: consolidateAccountsOnLoad && !$isStrongholdLocked && onConsolidateAccountsClick()
$: totalBalance = sumBalanceForAccounts($visibleActiveAccounts)
$: searchInCurrentWallet, (shouldInitSearch = true)
$: searchAlgorithm = searchInCurrentWallet
? SearchAlgorithmType.DFS
: network.id === NetworkId.Iota || NetworkId.IotaAlphanet
? SearchAlgorithmType.IDS
: SearchAlgorithmType.BFS
// Button click handlers
async function onFindBalancesClick(): Promise<void> {
Expand All @@ -73,9 +93,10 @@
// Actions
async function findProfileBalances(): Promise<void> {
await findBalances(searchAlgorithm, !hasUsedBalanceFinder)
await findBalances(searchAlgorithm, !hasUsedBalanceFinder || shouldInitSearch)
await loadAccounts()
hasUsedBalanceFinder = true
shouldInitSearch = false
}
async function consolidateProfileAccounts(): Promise<void> {
Expand Down Expand Up @@ -127,13 +148,22 @@
hasUsedBalanceFinder,
title,
body,
searchInCurrentWallet,
shouldInitSearch,
},
})
},
onCancelled: function () {
openPopup({
id: PopupId.BalanceFinder,
props: { hasUsedBalanceFinder, title, body, showConsolidation },
props: {
hasUsedBalanceFinder,
title,
body,
showConsolidation,
searchInCurrentWallet,
shouldInitSearch,
},
})
},
},
Expand All @@ -156,7 +186,7 @@
<Text type={TextType.p} color="gray-600" fontSize="15" lineHeight="5">{body}</Text>

<div class="w-full flex-col space-y-2 balance-overview-wrapper">
<VirtualList items={$visibleActiveAccounts} let:item>
<VirtualList items={visibleWalletList} let:item>
<div class="mb-2">
<Tile classes="flex justify-between items-center hover:bg-gray-100 dark:hover:bg-gray-1000">
<div class="flex items-center space-x-2">
Expand All @@ -172,11 +202,19 @@
</Tile>
</div>
</VirtualList>
<KeyValueBox
keyText={localize('popups.balanceFinder.totalAddressBalance')}
valueText={formatTokenAmountBestMatch(totalBalance, getBaseToken())}
/>
{#if !searchInCurrentWallet}
<KeyValueBox
keyText={localize('popups.balanceFinder.totalAddressBalance')}
valueText={formatTokenAmountBestMatch(totalBalance, getBaseToken())}
/>
{/if}
</div>
<Checkbox
label={localize('popups.balanceFinder.currentWallet')}
checked={searchInCurrentWallet}
onClick={() => (searchInCurrentWallet = !searchInCurrentWallet)}
disabled={isBusy}
/>

{#if hasUsedBalanceFinder}
<TextHint
Expand Down Expand Up @@ -231,7 +269,7 @@
overflow-y: scroll;
padding-right: 1.5rem !important;
min-height: 100px;
max-height: 300px;
max-height: 250px;
}
.balance-overview-wrapper :global(svelte-virtual-list-contents) {
margin-right: -1rem !important;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { Button, Text, ButtonSize } from 'shared/components'
import { Button, Text, ButtonSize, TextType } from 'shared/components'
import { localize } from '@core/i18n'
import { openPopup, PopupId } from '@auxiliary/popup'
Expand All @@ -14,8 +14,8 @@
}
</script>

<Text type="h4" classes="mb-3">{localize('views.settings.balanceFinder.title')}</Text>
<Text type="p" secondary classes="mb-5">{localize('views.settings.balanceFinder.description')}</Text>
<Text type={TextType.h4} classes="mb-3">{localize('views.settings.balanceFinder.title')}</Text>
<Text type={TextType.p} secondary classes="mb-5">{localize('views.settings.balanceFinder.description')}</Text>
<div class="flex flex-row items-center">
<Button size={ButtonSize.Medium} inlineStyle="min-width: 156px;" onClick={onBalanceFinderClick}>
{localize('actions.findBalances')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ export const BALANCE_FINDER_ACCOUNT_RECOVERY_CONFIGURATION: AccountRecoveryConfi
initialAccountRange: 3,
accountGapLimit: 1,
numberOfRoundsBetweenBreadthSearch: 1,
addressGapLimit: 20,
addressGapLimit: 30,
},
}
3 changes: 2 additions & 1 deletion packages/shared/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,8 @@
"addressesSearched": "Addresses searched",
"addressesFound": "Addresses found",
"totalAddressBalance": "Total balance",
"searchAgainHint": "Is your balance or number of wallets incorrect? Search again until your full balance is shown."
"searchAgainHint": "Is your balance or number of wallets incorrect? Search again until your full balance is shown.",
"currentWallet": "Search only in the current wallet"
},
"balanceOverview": {
"title": "Balance overview",
Expand Down

0 comments on commit 7b9a529

Please sign in to comment.