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: do not suggest collecting if available funds < basic output min storage deposit or there arent enough outputs to consolidate #7609

Merged
Merged
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 36 additions & 5 deletions packages/desktop/views/dashboard/vesting/Vesting.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -31,8 +35,14 @@
MeatballMenuButton,
TooltipIcon,
} from '@ui'
import { onMount } from 'svelte'

const DEFAULT_EMPTY_VALUE_STRING = '----'
let modal: Modal
let timeUntilNextPayout = DEFAULT_EMPTY_VALUE_STRING
let minRequiredStorageDeposit: number | null
let hasOutputsToConsolidate = false
begonaalvarezd marked this conversation as resolved.
Show resolved Hide resolved

$: hasTransactionInProgress =
$selectedAccount?.isTransferring || $selectedAccount.hasConsolidatingOutputsTransactionInProgress

Expand All @@ -56,10 +66,31 @@
: 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()
})
$: areOutputsReadyForConsolidation()

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)) : ''
Expand Down Expand Up @@ -156,7 +187,7 @@
<Button
onClick={onCollectClick}
classes="w-full"
disabled={$selectedAccountVestingUnclaimedFunds === 0 || hasTransactionInProgress}
disabled={!canCollect}
isBusy={hasTransactionInProgress}
>
{localize('views.vesting.collect')}
Expand Down
Loading