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: add countdown logic for mana generation in implicit account creation #8222

Merged
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ff44d76
feat: implement logic to allow tx or not based on mana cost for the X…
cpl121 Mar 6, 2024
46aa693
fixes and clean up
marc2332 Mar 7, 2024
357cedd
Merge branch 'develop-iota2.0' into feat/add-buffer-to-show-mana-cost
cpl121 Mar 8, 2024
0c25980
Merge branch 'develop-iota2.0' into feat/add-buffer-to-show-mana-cost
cpl121 Mar 8, 2024
24899df
Merge branch 'develop-iota2.0' into feat/add-buffer-to-show-mana-cost
marc2332 Mar 11, 2024
37dfe97
Merge branch 'develop-iota2.0' into feat/add-buffer-to-show-mana-cost
cpl121 Mar 12, 2024
f327b18
Merge branch 'develop-iota2.0' into feat/add-buffer-to-show-mana-cost
cpl121 Mar 12, 2024
9f959e7
Merge branch 'develop-iota2.0' into feat/add-buffer-to-show-mana-cost
cpl121 Mar 12, 2024
5b3ce04
Merge branches 'feat/add-buffer-to-show-mana-cost' and 'develop-iota2…
cpl121 Mar 12, 2024
719d742
feat: add mana cost to mint, burn, send and implicitTransition
cpl121 Mar 13, 2024
ba4c3dd
feat: improvements in mana box component
cpl121 Mar 14, 2024
c106747
feat: add mana cost to claim activity
cpl121 Mar 14, 2024
331bddd
feat: add mana cost to create delegation
cpl121 Mar 14, 2024
e46319b
feat: add mana cost to claim shimmer
cpl121 Mar 14, 2024
39bd5f9
Merge branch 'develop-iota2.0' into feat/add-buffer-to-show-mana-cost
cpl121 Mar 14, 2024
efb799c
Merge branch 'feat/add-buffer-to-show-mana-cost' into feat/add-mana-c…
cpl121 Mar 14, 2024
f8e1472
fixes
cpl121 Mar 18, 2024
b40de0c
Merge branches 'feat/add-mana-cost-everywhere' and 'feat/add-buffer-t…
cpl121 Mar 18, 2024
5dfbdca
feat: add countdown logic for mana generation in implicit account cre…
cpl121 Mar 19, 2024
9a428ba
Merge branches 'feat/add-mana-cost-everywhere' and 'develop-iota2.0' …
cpl121 Mar 19, 2024
d837904
fix: add conditional chaining
cpl121 Mar 19, 2024
e252c6c
Merge branches 'feat/add-countdown-logic-for-mana-generation' and 'fe…
cpl121 Mar 19, 2024
a0d5fb5
fix: improvements
cpl121 Mar 20, 2024
1e7af29
Merge branches 'feat/add-mana-cost-everywhere' and 'develop-iota2.0' …
cpl121 Mar 20, 2024
cc5effe
Merge branches 'feat/add-countdown-logic-for-mana-generation' and 'fe…
cpl121 Mar 20, 2024
1b99c7b
fix: improvements
cpl121 Mar 20, 2024
0f34d7c
Merge branch 'develop-iota2.0' into feat/add-mana-cost-everywhere
begonaalvarezd Mar 21, 2024
e4000d1
fix: update mana box with new transactionInfo interface
cpl121 Mar 21, 2024
2f4d16f
Merge branch 'develop-iota2.0' of github.com:iotaledger/firefly into …
cpl121 Mar 21, 2024
8feb268
fix: json literal and seconds in fund confirmation view
cpl121 Mar 21, 2024
3f90e21
fix: minor improvements
cpl121 Mar 21, 2024
edd3be2
Merge branches 'feat/add-countdown-logic-for-mana-generation' and 'fe…
cpl121 Mar 21, 2024
706700d
Merge branches 'feat/add-countdown-logic-for-mana-generation' and 'de…
cpl121 Mar 21, 2024
9581836
Merge branch 'develop-iota2.0' into feat/add-countdown-logic-for-mana…
evavirseda Mar 22, 2024
48265fc
Merge branch 'develop-iota2.0' into feat/add-countdown-logic-for-mana…
cpl121 Mar 22, 2024
e0441fb
fix: add missing declaration
begonaalvarezd Mar 25, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,31 @@
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'
import { onDestroy, onMount } from 'svelte'

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,
Expand All @@ -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 {
Expand All @@ -69,28 +72,40 @@
}, 0)
}

// TODO: Replace this with proper time remaining
async function prepareTransaction(outputId: string): Promise<void> {
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(() => {
Expand All @@ -103,10 +118,10 @@
// ----------------------------------------------------------------
</script>

<step-content class="flex flex-col items-center justify-between h-full pt-20">
<div class="flex flex-col h-full justify-between space-y-8 items-center">
<step-content class={`flex flex-col items-center justify-between h-full ${isLowManaGeneration ? 'pt-8' : 'pt-20'}`}>
<div class="flex flex-col h-full justify-between space-y-4 items-center">
<div class="flex flex-col text-center space-y-4 max-w-md">
<div class="flex items-center justify-center mb-7">
<div class={`flex items-center justify-center ${isLowManaGeneration ? 'mb-2' : 'mb-7'}`}>
<img
src="assets/illustrations/implicit-account-creation/step2.svg"
alt={localize('views.implicit-account-creation.steps.step2.title')}
Expand Down Expand Up @@ -140,7 +155,7 @@
</div>
</div>
{#if isLowManaGeneration}
<div class="flex flex-col space-y-4 w-2/3">
<div class="flex flex-col space-y-2 w-2/3">
<TextHint
variant={TextHintVariant.Warning}
text={localize('views.implicit-account-creation.steps.step2.view.walletAddress.description')}
Expand Down
Loading