diff --git a/packages/desktop/views/dashboard/Dashboard.svelte b/packages/desktop/views/dashboard/Dashboard.svelte index 0e0e1904e4e..8baad4eef5e 100644 --- a/packages/desktop/views/dashboard/Dashboard.svelte +++ b/packages/desktop/views/dashboard/Dashboard.svelte @@ -18,7 +18,6 @@ import { onDestroy, onMount } from 'svelte' import Sidebar from './Sidebar.svelte' import TopNavigation from './TopNavigation.svelte' - import { addNftsToDownloadQueue, downloadingNftId, @@ -28,12 +27,11 @@ resetNftDownloadQueue, selectedWalletNfts, } from '@core/nfts' - import { selectedWalletId } from '@core/wallet' + import { clearBalanceSyncPoll, selectedWalletId, syncBalancePoll } from '@core/wallet' import { get } from 'svelte/store' import features from '@features/features' - import { isAwareOfMetricSystemDrop } from '@contexts/dashboard/stores' + import { isAwareOfMetricSystemDrop, showBalanceOverviewPopup } from '@contexts/dashboard/stores' import { openPopup, PopupId } from '@auxiliary/popup' - import { showBalanceOverviewPopup } from '@contexts/dashboard/stores' const tabs = { wallet: Wallet, @@ -83,6 +81,7 @@ } onMount(() => { + syncBalancePoll($selectedWalletId, true) Platform.onEvent('menu-logout', () => { void logout() }) @@ -126,6 +125,7 @@ }) onDestroy(() => { + clearBalanceSyncPoll() Platform.DeepLinkManager.clearDeepLinkRequest() Platform.removeListenersForEvent('deep-link-params') diff --git a/packages/desktop/views/dashboard/Sidebar.svelte b/packages/desktop/views/dashboard/Sidebar.svelte index c0c91e01d0d..d84e17efd4b 100644 --- a/packages/desktop/views/dashboard/Sidebar.svelte +++ b/packages/desktop/views/dashboard/Sidebar.svelte @@ -76,7 +76,7 @@ ...(features?.delegation?.enabled ? [ { - icon: IconEnum.Sync, + icon: IconEnum.Staking, label: localize('tabs.delegation'), route: DashboardRoute.Delegation, onClick: openDelegation, diff --git a/packages/desktop/views/dashboard/wallet/views/implicit-account-creation-multistep/FundConfirmationView.svelte b/packages/desktop/views/dashboard/wallet/views/implicit-account-creation-multistep/FundConfirmationView.svelte index 90ce524ff0a..eb924a53b79 100644 --- a/packages/desktop/views/dashboard/wallet/views/implicit-account-creation-multistep/FundConfirmationView.svelte +++ b/packages/desktop/views/dashboard/wallet/views/implicit-account-creation-multistep/FundConfirmationView.svelte @@ -6,9 +6,11 @@ ITransactionInfoToCalculateManaCost, getManaBalance, getPassiveManaForOutput, + DEFAULT_SECONDS_PER_SLOT, } from '@core/network' import { activeProfile } from '@core/profile' import { implicitAccountCreationRouter } from '@core/router' + import { MILLISECONDS_PER_SECOND, SECONDS_PER_MINUTE, getBestTimeDuration } from '@core/utils' import { IWalletState, formatTokenAmountBestMatch, selectedWallet, selectedWalletAssets } from '@core/wallet' import { OutputData } from '@iota/sdk/out/types' import { Button, FontWeight, KeyValueBox, Text, TextType, TextHint, TextHintVariant, CopyableBox } from '@ui' @@ -16,18 +18,19 @@ export let outputId: string | undefined - // TODO: update when mana generation is available - const isLowManaGeneration = false + const LOW_MANA_GENERATION_SECONDS = 10 * SECONDS_PER_MINUTE + let walletAddress: string = '' const transactionInfo: ITransactionInfoToCalculateManaCost = {} let hasEnoughMana = false + let isLowManaGeneration = false $: baseCoin = $selectedWalletAssets?.[$activeProfile?.network?.id]?.baseCoin $: selectedOutput = getSelectedOutput($selectedWallet, outputId) let totalAvailableMana: number - $: $selectedWallet, seconds, (totalAvailableMana = getTotalAvailableMana()) + $: $selectedWallet, (totalAvailableMana = getTotalAvailableMana()), prepareTransaction(selectedOutput?.outputId) let formattedSelectedOutputBlance: string $: selectedOutput, @@ -53,14 +56,14 @@ function getTotalAvailableMana(): number { return ( getManaBalance($selectedWallet?.balances?.mana?.available) + - $selectedWallet?.balances.totalWalletBic - - getImplicitAccountsMana($selectedWallet?.implicitAccountOutputs, [outputId]) + ($selectedWallet?.balances.totalWalletBic ?? 0) - + getImplicitAccountsMana($selectedWallet?.implicitAccountOutputs, outputId ? [outputId] : []) ) } - function getImplicitAccountsMana(implicitAccountOutputs: OutputData[], excludeIds: string[] | undefined): number { + function getImplicitAccountsMana(implicitAccountOutputs: OutputData[], excludeIds: string[]): number { return implicitAccountOutputs?.reduce((acc: number, outputData: OutputData) => { - if (excludeIds && excludeIds.includes(outputData.outputId)) { + if (excludeIds.length > 1 && !excludeIds.includes(outputData.outputId)) { const totalMana = getPassiveManaForOutput(outputData) return totalMana ? acc + totalMana : acc } else { @@ -69,28 +72,40 @@ }, 0) } - // TODO: Replace this with proper time remaining + async function prepareTransaction(outputId: string): Promise { + if (!outputId) return + try { + transactionInfo.preparedTransaction = await $selectedWallet?.prepareImplicitAccountTransition(outputId) + seconds = 0 // If we don't get an error, it's because we can follow on to the next step + } catch (error) { + console.error(error.message) + if (error.message?.includes('slots remaining until enough mana')) { + transactionInfo.preparedTransactionError = error.message + const slotsRemaining = Number(error.message?.split(' ').reverse()[0].replace('`', '')) + seconds = slotsRemaining * DEFAULT_SECONDS_PER_SLOT + isLowManaGeneration = seconds >= LOW_MANA_GENERATION_SECONDS + } + } + } + // ---------------------------------------------------------------- let seconds: number = 10 let countdownInterval: NodeJS.Timeout let timeRemaining: string - $: timeRemaining = `${seconds}s remaining` + $: timeRemaining = `${getBestTimeDuration(seconds * MILLISECONDS_PER_SECOND)} remaining` onMount(async () => { - walletAddress = await $selectedWallet?.address() - $selectedWallet - .prepareImplicitAccountTransition(selectedOutput.outputId) - .then((prepareTx) => (transactionInfo.preparedTransaction = prepareTx)) - .catch((error) => (transactionInfo.preparedTransactionError = error)) + $selectedWallet?.address().then((address) => (walletAddress = address)) + await prepareTransaction(selectedOutput.outputId) + if (seconds === 0) onTimeout() countdownInterval = setInterval(() => { seconds -= 1 - if (seconds <= 0) { clearInterval(countdownInterval) onTimeout() } - }, 1000) + }, MILLISECONDS_PER_SECOND) }) onDestroy(() => { @@ -103,10 +118,10 @@ // ---------------------------------------------------------------- - -
+ +
-
+
{localize('views.implicit-account-creation.steps.step2.title')}
{#if isLowManaGeneration} -
+
{ + await syncBalance(walletId, syncCongestion) + balanceSyncInterval = window.setInterval(() => { + void syncBalance(walletId, syncCongestion) + }, DEFAULT_SECONDS_PER_SLOT * MILLISECONDS_PER_SECOND) +} + +export function clearBalanceSyncPoll(): void { + clearInterval(balanceSyncInterval) +} diff --git a/packages/shared/lib/core/wallet/actions/index.ts b/packages/shared/lib/core/wallet/actions/index.ts index 5ab7d2a4953..5f215a387b3 100644 --- a/packages/shared/lib/core/wallet/actions/index.ts +++ b/packages/shared/lib/core/wallet/actions/index.ts @@ -32,6 +32,7 @@ export * from './setStrongholdPasswordClearInterval' export * from './startBackgroundSync' export * from './getParticipationOverview' export * from './syncBalance' +export * from './SyncBalancePoll' export * from './syncVotingPower' export * from './tryCreateAdditionalWallet' export * from './getClient' diff --git a/packages/shared/lib/core/wallet/utils/outputs/preprocessOutgoingTransaction.ts b/packages/shared/lib/core/wallet/utils/outputs/preprocessOutgoingTransaction.ts index b49ab348049..86b555726a9 100644 --- a/packages/shared/lib/core/wallet/utils/outputs/preprocessOutgoingTransaction.ts +++ b/packages/shared/lib/core/wallet/utils/outputs/preprocessOutgoingTransaction.ts @@ -31,7 +31,6 @@ export async function preprocessOutgoingTransaction( time: new Date(Number(transaction.timestamp)), inclusionState: transaction.inclusionState, wrappedInputs: inputs, - utxoInputs, } }