Skip to content

Commit

Permalink
Merge branch 'develop' into 2087----polish-addnodeproposal-pop-up
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuditi authored May 15, 2024
2 parents 26b46b2 + adfe8b3 commit d1ca366
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 44 deletions.
100 changes: 61 additions & 39 deletions packages/desktop/components/popup/popups/SyncAccountsPopup.svelte
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
<script lang="ts">
import { showNotification } from '@auxiliary/notification'
import { Alert, Table } from '@bloomwalletio/ui'
import { sumBalanceForAccounts } from '@core/account'
import { Alert, Indicator, Text, Toggle } from '@bloomwalletio/ui'
import { DEFAULT_SYNC_OPTIONS } from '@core/account/constants'
import { selectedAccountIndex } from '@core/account/stores'
import { generateAndStoreActivitiesForAllAccounts } from '@core/activity/actions'
import { localize } from '@core/i18n'
import { ledgerRaceConditionProtectionWrapper } from '@core/ledger'
import { SupportedStardustNetworkId } from '@core/network/constants'
import { StardustNetworkId } from '@core/network/types'
import { loadNftsForActiveProfile } from '@core/nfts/actions'
import { DEFAULT_ACCOUNT_RECOVERY_CONFIGURATION } from '@core/profile'
import { RecoverAccountsPayload, recoverAccounts } from '@core/profile-manager'
import { checkActiveProfileAuth, getBaseToken, loadAccounts } from '@core/profile/actions'
import { checkActiveProfileAuth, loadAccounts } from '@core/profile/actions'
import { activeAccounts, activeProfile, getActiveProfileId, visibleActiveAccounts } from '@core/profile/stores'
import { formatTokenAmount } from '@core/token'
import { loadTokensForAllAccountBalances } from '@core/token/actions'
import { allAccountTokens } from '@core/token/stores'
import { closePopup } from '@desktop/auxiliary/popup'
import { onDestroy } from 'svelte'
import PopupTemplate from '../PopupTemplate.svelte'
import { SupportedStardustNetworkId } from '@core/network/constants'
import { ledgerRaceConditionProtectionWrapper } from '@core/ledger'
import { StardustNetworkId } from '@core/network/types'
const { network, type } = $activeProfile
const DEFAULT_CONFIG = DEFAULT_ACCOUNT_RECOVERY_CONFIGURATION[type]
let accountStartIndex = 0
let accountGapLimit = DEFAULT_CONFIG.initialAccountRange
let previousAccountGapLimit = 0
let accountGapLimit = Math.max(DEFAULT_CONFIG.initialAccountRange, $activeAccounts.length)
let addressStartIndex = 0
const addressGapLimit = DEFAULT_CONFIG.addressGapLimit
Expand All @@ -36,8 +36,6 @@
let previousAccountsLength = 0
$: totalBalance = sumBalanceForAccounts($visibleActiveAccounts)
const networkSearchMethod: { [key in StardustNetworkId]?: () => Promise<void> } = {
[SupportedStardustNetworkId.Iota]: multiAddressSearch,
[SupportedStardustNetworkId.Shimmer]: singleAddressSearch,
Expand All @@ -61,30 +59,41 @@
let searchCount = 0
let depthSearchCount = 0
let breadthSearchCountSinceLastDepthSearch = 0
let depthSearch = false
let isDepthSearch = false
let isSingleAccountSearch = false
// Please don't modify this algorithm without consulting with the team
async function multiAddressSearch(): Promise<void> {
let recoverAccountsPayload: RecoverAccountsPayload
if (
!depthSearch &&
breadthSearchCountSinceLastDepthSearch &&
breadthSearchCountSinceLastDepthSearch % accountGapLimit === 0
isSingleAccountSearch ||
(!isDepthSearch &&
breadthSearchCountSinceLastDepthSearch &&
breadthSearchCountSinceLastDepthSearch % accountGapLimit === 0)
) {
// Depth search
depthSearch = true
isDepthSearch = true
recoverAccountsPayload = {
accountStartIndex: accountGapLimit,
accountGapLimit: 1,
addressGapLimit: (searchCount - depthSearchCount) * addressGapLimit,
syncOptions: { ...DEFAULT_SYNC_OPTIONS, addressStartIndex: 0 },
accountStartIndex: isSingleAccountSearch ? $selectedAccountIndex : accountGapLimit,
accountGapLimit: 0,
addressGapLimit: isSingleAccountSearch
? addressGapLimit
: (searchCount - depthSearchCount) * addressGapLimit,
syncOptions: {
...DEFAULT_SYNC_OPTIONS,
addressStartIndex: isSingleAccountSearch ? addressStartIndex : 0,
},
}
breadthSearchCountSinceLastDepthSearch = 0
depthSearchCount++
accountGapLimit++
if (isSingleAccountSearch) {
addressStartIndex += addressGapLimit
} else {
accountGapLimit++
}
} else {
// Breadth search
depthSearch = false
isDepthSearch = false
recoverAccountsPayload = {
accountStartIndex,
accountGapLimit,
Expand Down Expand Up @@ -114,7 +123,6 @@
await ledgerRaceConditionProtectionWrapper(_function)
await loadAccounts()
previousAccountsLength = $visibleActiveAccounts.length
previousAccountGapLimit = accountGapLimit
hasUsedWalletFinder = true
} catch (err) {
error = localize(err.error)
Expand Down Expand Up @@ -154,25 +162,39 @@
onClick: onFindBalancesClick,
}}
>
<div class="space-y-5">
<Table
items={[
{
key: localize('popups.walletFinder.accountsSearched'),
value: previousAccountGapLimit.toString() || '-',
},
{
key: localize('popups.walletFinder.accountsFound'),
value: $activeAccounts.length.toString() || '0',
},
{
key: localize('popups.walletFinder.totalWalletBalance'),
value: formatTokenAmount(totalBalance, getBaseToken()),
},
]}
/>
<div class="flex flex-col overflow-hidden gap-5">
{#if network?.id === SupportedStardustNetworkId.Iota}
<div class="flex gap-2">
<Toggle
label={localize('popups.walletFinder.singleAccountSearch')}
bind:checked={isSingleAccountSearch}
/>
<Text>{localize('popups.walletFinder.singleAccountSearch')}</Text>
</div>
{/if}
<account-balance-list class="overflow-y-scroll h-0 flex-1 flex flex-col">
{#each $activeAccounts as account}
{@const baseCoin = $allAccountTokens[account.index]?.[network.id]?.baseCoin}
<div class="w-full flex flex-row items-center justify-between items-center justify-between p-4 gap-3">
<div class="flex flex-row items-center gap-3">
<Indicator color={account.color} />
<Text>{account.name}</Text>
</div>
<Text>{formatTokenAmount(baseCoin?.balance?.total, baseCoin?.metadata)}</Text>
</div>
{/each}
</account-balance-list>
{#if hasUsedWalletFinder}
<Alert variant="info" text={localize('popups.walletFinder.searchAgainHint')} />
{/if}
</div>
</PopupTemplate>

<style lang="postcss">
account-balance-list {
@apply bg-surface-0 dark:bg-surface-0-dark;
@apply border border-solid border-stroke dark:border-stroke-dark;
@apply divide-y divide-solid divide-stroke dark:divide-stroke-dark;
@apply rounded-xl;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
const recoverAccountsPayload: RecoverAccountsPayload = {
accountStartIndex,
accountGapLimit,
addressGapLimit: 1,
addressGapLimit: 0,
syncOptions: { ...DEFAULT_SYNC_OPTIONS, addressStartIndex: 0 },
}
Expand All @@ -72,7 +72,7 @@
depthSearch = true
recoverAccountsPayload = {
accountStartIndex: accountGapLimit,
accountGapLimit: 1,
accountGapLimit: 0,
addressGapLimit: (searchCount - depthSearchCount) * addressGapLimit,
syncOptions: { ...DEFAULT_SYNC_OPTIONS, addressStartIndex: 0 },
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { AccountRecoveryConfiguration } from '../types'
export const DEFAULT_ACCOUNT_RECOVERY_CONFIGURATION: AccountRecoveryConfiguration = {
[ProfileType.Ledger]: {
initialAccountRange: 3,
accountGapLimit: 1,
accountGapLimit: 0,
numberOfRoundsBetweenBreadthSearch: 1,
addressGapLimit: 5,
},
[ProfileType.Software]: {
initialAccountRange: 10,
accountGapLimit: 1,
accountGapLimit: 0,
numberOfRoundsBetweenBreadthSearch: 1,
addressGapLimit: 100,
},
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,8 @@
"accountsSearched": "Accounts searched",
"accountsFound": "Accounts found",
"totalWalletBalance": "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.",
"singleAccountSearch": "Search only current account"
},
"ledgerNotConnected": {
"title": "Connect your Ledger",
Expand Down

0 comments on commit d1ca366

Please sign in to comment.