Skip to content

Commit

Permalink
Merge branch 'develop-iota2.0' into feat/stop-generating-txs-out-of-o…
Browse files Browse the repository at this point in the history
…utputs
  • Loading branch information
begonaalvarezd authored Mar 25, 2024
2 parents a850bb8 + 062cb02 commit ac623c5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/desktop/views/dashboard/Sidebar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
...(features?.delegation?.enabled
? [
{
icon: IconEnum.Sync,
icon: IconEnum.Staking,
label: localize('tabs.delegation'),
route: DashboardRoute.Delegation,
onClick: openDelegation,
Expand Down
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

0 comments on commit ac623c5

Please sign in to comment.