diff --git a/packages/desktop/views/dashboard/vesting/Vesting.svelte b/packages/desktop/views/dashboard/vesting/Vesting.svelte index 8784f129177..c63bcdf71f8 100644 --- a/packages/desktop/views/dashboard/vesting/Vesting.svelte +++ b/packages/desktop/views/dashboard/vesting/Vesting.svelte @@ -17,7 +17,11 @@ import { getMarketAmountFromAssetValue } from '@core/market/utils' import { activeProfile } from '@core/profile' import { getBestTimeDuration } from '@core/utils' - import { formatTokenAmountBestMatch, selectedAccountAssets } from '@core/wallet' + import { + formatTokenAmountBestMatch, + getRequiredStorageDepositForMinimalBasicOutput, + selectedAccountAssets, + } from '@core/wallet' import { Button, FontWeight, @@ -31,12 +35,18 @@ MeatballMenuButton, TooltipIcon, } from '@ui' + import { onMount } from 'svelte' const DEFAULT_EMPTY_VALUE_STRING = '----' - $: hasTransactionInProgress = - $selectedAccount?.isTransferring || $selectedAccount.hasConsolidatingOutputsTransactionInProgress + let modal: Modal + let timeUntilNextPayout = DEFAULT_EMPTY_VALUE_STRING + let minRequiredStorageDeposit: number | null + let hasOutputsToConsolidate = false $: ({ baseCoin } = $selectedAccountAssets[$activeProfile?.network?.id]) + $: hasTransactionInProgress = + $selectedAccount?.isTransferring || $selectedAccount.hasConsolidatingOutputsTransactionInProgress + $: $selectedAccount, areOutputsReadyForConsolidation() $: vestingOverview = [ { title: localize('views.vesting.overview.unlocked'), @@ -56,10 +66,30 @@ : undefined, }, ] - - let modal: Modal - let timeUntilNextPayout = DEFAULT_EMPTY_VALUE_STRING $: $selectedAccountVestingPayouts, (timeUntilNextPayout = getTimeUntilNextPayout()) + $: canCollect = + $selectedAccountVestingUnclaimedFunds > 0 && + !hasTransactionInProgress && + minRequiredStorageDeposit !== null && + $selectedAccount?.balances?.baseCoin?.available > minRequiredStorageDeposit && + hasOutputsToConsolidate + + onMount(() => { + getMinRequiredStorageDeposit() + }) + + function areOutputsReadyForConsolidation(): void { + $selectedAccount + .prepareConsolidateOutputs({ force: false, outputThreshold: 2 }) + .then(() => (hasOutputsToConsolidate = true)) + .catch(() => (hasOutputsToConsolidate = false)) + } + + function getMinRequiredStorageDeposit() { + getRequiredStorageDepositForMinimalBasicOutput() + .then((deposit) => (minRequiredStorageDeposit = deposit)) + .catch(() => (minRequiredStorageDeposit = null)) + } function getFiatAmount(amount: number): string { return baseCoin ? formatCurrency(getMarketAmountFromAssetValue(amount, baseCoin)) : '' @@ -156,7 +186,7 @@