Skip to content

Commit

Permalink
fix: reactivity issue after user gets enough mana to cover the block …
Browse files Browse the repository at this point in the history
…cost (#8529)

* fix: reactivity issue after user gets enough mana to cover the block cost

* fix: linter
  • Loading branch information
cpl121 authored May 20, 2024
1 parent 5104d5e commit 943ab67
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 14 deletions.
12 changes: 11 additions & 1 deletion packages/desktop/components/ManaBox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
export let transactionInfo: ITransactionInfoToCalculateManaCost
export let hasEnoughMana: boolean
export let refreshTransactionInfo: () => Promise<void> = () => Promise.resolve()
export let showCountdown: boolean = true
export let outputId: string | undefined = undefined
Expand Down Expand Up @@ -57,6 +58,11 @@
secondsRemainingCountdownInterval = setInterval(() => {
secondsRemaining -= 1
if (secondsRemaining <= 0) {
refreshTransactionInfo()
.then(() => {
calculateManaCost()
})
.catch((err) => console.error(err))
clearInterval(secondsRemainingCountdownInterval)
}
}, MILLISECONDS_PER_SECOND)
Expand Down Expand Up @@ -92,7 +98,11 @@
refreshManaCountdownInterval = setInterval(() => {
secondsToRefreshManaCost -= 1
if (secondsToRefreshManaCost <= 0) {
calculateManaCost()
refreshTransactionInfo()
.then(() => {
calculateManaCost()
})
.catch((err) => console.error(err))
secondsToRefreshManaCost = NUMBER_OF_EXTRA_SLOTS_MANA * DEFAULT_SECONDS_PER_SLOT
}
}, MILLISECONDS_PER_SECOND)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
</activity-details>
{#if !isTimelocked && isActivityIncomingAndUnclaimed}
<div class="flex flex-col space-y-4">
<ManaBox {transactionInfo} bind:hasEnoughMana />
<ManaBox {transactionInfo} bind:hasEnoughMana refreshTransactionInfo={prepareClaimOutput} />
{#if hasMainAccountNegativeBIC}
<TextHint variant={TextHintVariant.Danger} text={localize('popups.transaction.negativeBIC')} />
{/if}
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/components/popups/AllotManaPopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
<Text error>{error}</Text>
{/if}
{#if displayManaBox}
<ManaBox {transactionInfo} bind:hasEnoughMana />
<ManaBox {transactionInfo} bind:hasEnoughMana refreshTransactionInfo={preparedOutput} />
{/if}
</div>
<popup-buttons class="flex flex-row flex-nowrap w-full space-x-4">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<KeyValueBox keyText={localize('popups.nativeToken.property.assetId')} valueText={asset.id} isCopyable />
<KeyValueBox keyText={localize('general.amount')} valueText={formattedAmount} />
<TextHint variant={TextHintVariant.Warning} text={localize('actions.confirmTokenBurn.hint')} />
<ManaBox {transactionInfo} bind:hasEnoughMana />
<ManaBox {transactionInfo} bind:hasEnoughMana refreshTransactionInfo={prepareBurnFoundryTransaction} />
{#if hasMainAccountNegativeBIC}
<TextHint variant={TextHintVariant.Danger} text={localize('popups.transaction.negativeBIC')} />
{/if}
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/components/popups/BurnNftPopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
</Text>
<div class="space-y-4">
<Text fontSize="14" classes="text-left break-words">{localize('actions.confirmNftBurn.description')}</Text>
<ManaBox {transactionInfo} bind:hasEnoughMana />
<ManaBox {transactionInfo} bind:hasEnoughMana refreshTransactionInfo={prepareBurnNftTransaction} />
<TextHint variant={TextHintVariant.Warning} text={localize('actions.confirmNftBurn.hint')} />
</div>
<popup-buttons class="flex flex-row flex-nowrap w-full space-x-4">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
keyText={localize('popups.claimDelegationRewards.rewards')}
valueText={formatTokenAmountBestMatch(Math.round(rewards), DEFAULT_MANA)}
/>
<ManaBox {transactionInfo} bind:hasEnoughMana />
<ManaBox {transactionInfo} bind:hasEnoughMana refreshTransactionInfo={prepareBurnDelegationOutput} />
{#if hasMainAccountNegativeBIC}
<TextHint variant={TextHintVariant.Danger} text={localize('popups.transaction.negativeBIC')} />
{/if}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<div class="space-y-4">
<TextHint variant={TextHintVariant.Info} text={localize('popups.minimizeStorageDeposit.description')} />
{#if displayManaBox}
<ManaBox {transactionInfo} bind:hasEnoughMana />
<ManaBox {transactionInfo} bind:hasEnoughMana refreshTransactionInfo={prepareConsolidateTransaction} />
{/if}
{#if hasMainAccountNegativeBIC}
<TextHint variant={TextHintVariant.Danger} text={localize('popups.transaction.negativeBIC')} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
<Text error>{addressError}</Text>
{/if}
{#if displayManaBox}
<ManaBox {transactionInfo} bind:hasEnoughMana />
<ManaBox {transactionInfo} bind:hasEnoughMana refreshTransactionInfo={updateTransactionInfo} />
{/if}
{#if hasMainAccountNegativeBIC}
<TextHint variant={TextHintVariant.Danger} text={localize('popups.transaction.negativeBIC')} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
isCopyable={value.isCopyable}
/>
{/each}
<ManaBox {transactionInfo} bind:hasEnoughMana />
<ManaBox {transactionInfo} bind:hasEnoughMana refreshTransactionInfo={prepareFoundryOutput} />
</details-list>
{/if}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
isPreText
/>
{/if}
<ManaBox {transactionInfo} bind:hasEnoughMana />
<ManaBox {transactionInfo} bind:hasEnoughMana refreshTransactionInfo={prepareNftOutput} />
</activity-details>
</nft-details>
{#if hasMainAccountNegativeBIC}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@
/>
</KeyValueBox>
{/if}
<ManaBox {transactionInfo} bind:hasEnoughMana />
<ManaBox {transactionInfo} bind:hasEnoughMana refreshTransactionInfo={rebuildTransactionOutput} />
{/if}
</div>
{#if surplus}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@
keyText={localize('views.implicit-account-creation.steps.step2.view.generatedMana')}
valueText={formattedManaBalance}
/>
<ManaBox {transactionInfo} bind:hasEnoughMana showCountdown={!$selectedWallet.isTransferring} />
<ManaBox
{transactionInfo}
bind:hasEnoughMana
showCountdown={!$selectedWallet.isTransferring}
refreshTransactionInfo={() => prepareTransaction(selectedOutput?.outputId)}
/>
</div>
<PasswordInput
bind:error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,13 @@
keyText={localize('views.implicit-account-creation.steps.step2.view.generatedMana')}
valueText={formattedManaBalance}
/>
<ManaBox {transactionInfo} bind:hasEnoughMana showCountdown={true} {outputId} />
<ManaBox
{transactionInfo}
bind:hasEnoughMana
showCountdown={true}
{outputId}
refreshTransactionInfo={() => prepareTransaction(selectedOutput.outputId)}
/>
</div>
{/if}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@
{localize(`actions.${hasTriedClaimingRewards ? 'rerunClaimProcess' : 'claimRewards'}`)}
</Button>
{/if}
<ManaBox {transactionInfo} bind:hasEnoughMana />
<ManaBox {transactionInfo} bind:hasEnoughMana refreshTransactionInfo={prepareClaimOutput} />
{#if hasMainAccountNegativeBIC}
<TextHint variant={TextHintVariant.Danger} text={localize('popups.transaction.negativeBIC')} />
{/if}
Expand Down

0 comments on commit 943ab67

Please sign in to comment.