diff --git a/packages/desktop/views/dashboard/wallet/views/implicit-account-creation-multistep/FundConfirmationView.svelte b/packages/desktop/views/dashboard/wallet/views/implicit-account-creation-multistep/FundConfirmationView.svelte index 80060420e82..46aea713181 100644 --- a/packages/desktop/views/dashboard/wallet/views/implicit-account-creation-multistep/FundConfirmationView.svelte +++ b/packages/desktop/views/dashboard/wallet/views/implicit-account-creation-multistep/FundConfirmationView.svelte @@ -6,11 +6,9 @@ ITransactionInfoToCalculateManaCost, getManaBalance, getPassiveManaForOutput, - nodeInfoProtocolParameters, 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' @@ -30,27 +28,23 @@ export let outputId: string | undefined const LOW_MANA_GENERATION_SECONDS = 10 * SECONDS_PER_MINUTE - const minCommittableAge = $nodeInfoProtocolParameters?.minCommittableAge - const transactionInfo: ITransactionInfoToCalculateManaCost = {} let walletAddress: string = '' + const transactionInfo: ITransactionInfoToCalculateManaCost = {} let hasEnoughMana = false - let isCongestionNotFound: boolean | null = null let isLowManaGeneration = false - - let seconds: number = 10 - let countdownInterval: NodeJS.Timeout - $: timeRemaining = `${getBestTimeDuration(seconds * MILLISECONDS_PER_SECOND)} remaining` + let isCongestionNotFound: boolean | null = null $: baseCoin = $selectedWalletAssets?.[$activeProfile?.network?.id]?.baseCoin + $: selectedOutput = getSelectedOutput($selectedWallet, outputId) let totalAvailableMana: number - $: $selectedWallet, (totalAvailableMana = getTotalAvailableMana()) + $: $selectedWallet, (totalAvailableMana = getTotalAvailableMana()), prepareTransaction(selectedOutput?.outputId) - let formattedSelectedOutputBlance: string + let formattedSelectedOutputBalance: string $: selectedOutput, - (formattedSelectedOutputBlance = baseCoin + (formattedSelectedOutputBalance = baseCoin ? formatTokenAmountBestMatch(Number(selectedOutput?.output.amount), baseCoin.metadata) : '-') $: formattedWalletBalance = @@ -88,64 +82,66 @@ }, 0) } - async function prepareImplicitAccountWithRetry(outputId: string): Promise { + async function prepareTransaction(outputId: string): Promise { + if (!outputId) return try { - await $selectedWallet.prepareImplicitAccountTransition(outputId).then((prepareTx) => { - transactionInfo.preparedTransaction = prepareTx - isCongestionNotFound = false - seconds = 0 - $implicitAccountCreationRouter.next() - }) + transactionInfo.preparedTransaction = await $selectedWallet?.prepareImplicitAccountTransition(outputId) + isCongestionNotFound = false + seconds = 0 // If we don't get an error, it's because we can follow on to the next step } catch (error) { - // Handle "congestion not found" error and retry - if (error.message.includes('congestion was not found')) { + if (error.message?.includes('congestion was not found')) { isCongestionNotFound = true - await retryWithTimeout(minCommittableAge) - // Retry implicit account creation after timeout - await attemptImplicitAccountCreation() - } else if (error.message?.includes('slots remaining until enough mana')) { + await $selectedWallet + ?.prepareImplicitAccountTransition(outputId) + .then(() => { + isCongestionNotFound = false + }) + .catch((error) => { + console.error(error) + }) + } + 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 - isCongestionNotFound = false - - // Start countdown after successful preparation - countdownInterval = setInterval(() => { - seconds -= 1 - if (seconds <= 0) { - $implicitAccountCreationRouter.next() - } - }, MILLISECONDS_PER_SECOND) } } } + // ---------------------------------------------------------------- + let seconds: number = 10 + let countdownInterval: NodeJS.Timeout + let timeRemaining: string - async function retryWithTimeout(timeout: number): Promise { - return new Promise((resolve) => { - setTimeout(resolve, timeout) - }) - } - - async function attemptImplicitAccountCreation(): Promise { - try { - /* eslint-disable @typescript-eslint/no-misused-promises */ - await prepareImplicitAccountWithRetry(selectedOutput.outputId) - } catch (error) { - setTimeout(attemptImplicitAccountCreation, minCommittableAge) + $: timeRemaining = `${getBestTimeDuration(seconds * MILLISECONDS_PER_SECOND)} remaining` + $: { + async () => { + await prepareTransaction(selectedOutput.outputId) } } - - onMount(async () => { + onMount(() => { $selectedWallet?.address().then((address) => (walletAddress = address)) - await attemptImplicitAccountCreation() + if (seconds === 0) onTimeout() + countdownInterval = setInterval(() => { + seconds -= 1 + if (seconds <= 0) { + clearInterval(countdownInterval) + onTimeout() + } + }, MILLISECONDS_PER_SECOND) }) + onDestroy(() => { clearInterval(countdownInterval) }) + + const onTimeout = (): void => { + // $implicitAccountCreationRouter.next() + } + // ---------------------------------------------------------------- - +
@@ -154,6 +150,14 @@ alt={localize('views.implicit-account-creation.steps.step2.title')} />
+ {localize('views.implicit-account-creation.steps.step2.view.subtitle')} {#if isCongestionNotFound}
@@ -162,35 +166,27 @@
{:else} - {localize('views.implicit-account-creation.steps.step2.view.subtitle')} {timeRemaining} {/if} {localize('views.implicit-account-creation.steps.step2.view.title')} - {formattedSelectedOutputBlance} + {formattedSelectedOutputBalance} -
- - {#if !isCongestionNotFound} + {#if isLowManaGeneration} +
+ - {/if} -
+
+ {/if}
{#if isLowManaGeneration}