Skip to content

Commit

Permalink
feat: do not suggest collecting if available funds < basic output min…
Browse files Browse the repository at this point in the history
… storage deposit or there arent enough outputs to consolidate (#7609)

* feat: disable collect button if not available funds or outputs

* fix: update function and rename variables

* fix: update getMinRequiredStorageDeposit function

* feat: add canCollect variable, fix reactivity and update getMinRequiredStorageDeposit fucntion

* fix: improve canCollect condition

* fix: reactivity

---------

Co-authored-by: Begoña Alvarez <[email protected]>
  • Loading branch information
evavirseda and begonaalvarezd authored Oct 30, 2023
1 parent cef043e commit f405fd2
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 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,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'),
Expand All @@ -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)) : ''
Expand Down Expand Up @@ -156,7 +186,7 @@
<Button
onClick={onCollectClick}
classes="w-full"
disabled={$selectedAccountVestingUnclaimedFunds === 0 || hasTransactionInProgress}
disabled={!canCollect}
isBusy={hasTransactionInProgress}
>
{localize('views.vesting.collect')}
Expand Down

0 comments on commit f405fd2

Please sign in to comment.