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: improve balance finder #7582

Merged
merged 10 commits into from
Oct 19, 2023
36 changes: 30 additions & 6 deletions packages/desktop/components/popups/BalanceFinderPopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -34,19 +45,25 @@
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

let error = ''
let isBusy = false
let searchInCurrentWallet: boolean = false
let shouldInitSearch: boolean = false
begonaalvarezd marked this conversation as resolved.
Show resolved Hide resolved

const { isStrongholdLocked, network } = $activeProfile

$: isTransferring = $visibleActiveAccounts.some(
(account) => account.hasConsolidatingOutputsTransactionInProgress || account.isTransferring
)
$: 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 +90,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 @@ -177,6 +195,12 @@
valueText={formatTokenAmountBestMatch(totalBalance, getBaseToken())}
/>
</div>
<Checkbox
label={localize('popups.balanceFinder.currentWallet')}
checked={searchInCurrentWallet}
onClick={() => (searchInCurrentWallet = !searchInCurrentWallet)}
disabled={isBusy}
/>

{#if hasUsedBalanceFinder}
<TextHint
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
Loading