From 61e304429d21e024569e12ec5f25cd1e773ae815 Mon Sep 17 00:00:00 2001 From: evavirseda Date: Fri, 22 Mar 2024 17:50:09 +0100 Subject: [PATCH 1/6] feat: change icon (#8250) --- packages/desktop/views/dashboard/Sidebar.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/desktop/views/dashboard/Sidebar.svelte b/packages/desktop/views/dashboard/Sidebar.svelte index c0c91e01d0d..d84e17efd4b 100644 --- a/packages/desktop/views/dashboard/Sidebar.svelte +++ b/packages/desktop/views/dashboard/Sidebar.svelte @@ -76,7 +76,7 @@ ...(features?.delegation?.enabled ? [ { - icon: IconEnum.Sync, + icon: IconEnum.Staking, label: localize('tabs.delegation'), route: DashboardRoute.Delegation, onClick: openDelegation, From dbb3dd514c3fd153e442c2451436b96d35f50413 Mon Sep 17 00:00:00 2001 From: cpl121 <100352899+cpl121@users.noreply.github.com> Date: Mon, 25 Mar 2024 17:35:18 +0100 Subject: [PATCH 2/6] feat: add countdown logic for mana generation in implicit account creation (#8222) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: implement logic to allow tx or not based on mana cost for the X slots * fixes and clean up * feat: add mana cost to mint, burn, send and implicitTransition * feat: improvements in mana box component * feat: add mana cost to claim activity * feat: add mana cost to create delegation * feat: add mana cost to claim shimmer * fixes * feat: add countdown logic for mana generation in implicit account creation WIP * fix: add conditional chaining * fix: improvements * fix: improvements * fix: update mana box with new transactionInfo interface * fix: json literal and seconds in fund confirmation view * fix: minor improvements * fix: add missing declaration --------- Co-authored-by: marc2332 Co-authored-by: Begoña Álvarez de la Cruz Co-authored-by: evavirseda --- .../FundConfirmationView.svelte | 55 ++++++++++++------- 1 file changed, 35 insertions(+), 20 deletions(-) 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 90ce524ff0a..eb924a53b79 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,9 +6,11 @@ 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' @@ -16,18 +18,19 @@ 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, @@ -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 { @@ -69,28 +72,40 @@ }, 0) } - // TODO: Replace this with proper time remaining + async function prepareTransaction(outputId: string): Promise { + 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(() => { @@ -103,10 +118,10 @@ // ---------------------------------------------------------------- - -
+ +
-
+
{localize('views.implicit-account-creation.steps.step2.title')}
{#if isLowManaGeneration} -
+
Date: Mon, 25 Mar 2024 17:40:43 +0100 Subject: [PATCH 3/6] feat: Sync SDK types (#8247) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: cpl121 <100352899+cpl121@users.noreply.github.com> Co-authored-by: Begoña Álvarez de la Cruz --- .../TransactionActivityTileContent.svelte | 2 +- .../utils/outputs/preprocessGroupedOutputs.ts | 35 +++++++------------ .../outputs/preprocessOutgoingTransaction.ts | 9 +++-- 3 files changed, 17 insertions(+), 29 deletions(-) diff --git a/packages/shared/components/tiles/tileContents/TransactionActivityTileContent.svelte b/packages/shared/components/tiles/tileContents/TransactionActivityTileContent.svelte index 7620eb1adbe..2f449f81011 100644 --- a/packages/shared/components/tiles/tileContents/TransactionActivityTileContent.svelte +++ b/packages/shared/components/tiles/tileContents/TransactionActivityTileContent.svelte @@ -21,7 +21,7 @@ activity.direction === ActivityDirection.SelfTransaction ? localize('general.internalTransaction') : localize(isIncoming ? 'general.fromAddress' : 'general.toAddress', { - values: { account: getSubjectLocaleFromActivity(activity) }, + values: { address: getSubjectLocaleFromActivity(activity) }, }) $: amount = getFormattedAmountFromActivity(activity) diff --git a/packages/shared/lib/core/wallet/utils/outputs/preprocessGroupedOutputs.ts b/packages/shared/lib/core/wallet/utils/outputs/preprocessGroupedOutputs.ts index 343218bd9ae..c25b510fbf3 100644 --- a/packages/shared/lib/core/wallet/utils/outputs/preprocessGroupedOutputs.ts +++ b/packages/shared/lib/core/wallet/utils/outputs/preprocessGroupedOutputs.ts @@ -1,10 +1,9 @@ -import { CommonOutput, OutputData, OutputResponse, UTXOInput } from '@iota/sdk/out/types' +import { CommonOutput, OutputData, OutputWithMetadata, UTXOInput } from '@iota/sdk/out/types' import { IWalletState } from '@core/wallet/interfaces' import { InclusionState, ActivityDirection } from '../../enums' import { IProcessedTransaction, IWrappedOutput } from '../../interfaces' import { getRecipientAddressFromOutput } from './getRecipientAddressFromOutput' import { getSenderAddressFromInputs } from '../transactions' -import { getOutputIdFromTransactionIdAndIndex } from './getOutputIdFromTransactionIdAndIndex' import { getUnixTimestampFromNodeInfoAndSlotIndex, nodeInfoProtocolParameters } from '@core/network' import { get } from 'svelte/store' import { MILLISECONDS_PER_SECOND } from '@core/utils' @@ -12,14 +11,11 @@ import { MILLISECONDS_PER_SECOND } from '@core/utils' // TODO(2.0) Fix all usages export function preprocessGroupedOutputs( outputDatas: OutputData[], - transactionInputs: OutputResponse[], + transactionInputs: OutputWithMetadata[], wallet: IWalletState ): IProcessedTransaction { const transactionMetadata = outputDatas[0]?.metadata - const wrappedInputs = convertTransactionOutputResponsesToWrappedOutputs( - transactionMetadata?.included.transactionId, - transactionInputs - ) + const wrappedInputs = convertTransactionOutputResponsesToWrappedOutputs(transactionInputs) const utxoInputs = getUtxoInputsFromWrappedInputs(wrappedInputs) const direction = getDirectionForOutputs(outputDatas, wrappedInputs, wallet.depositAddress) const wrappedOutputs = outputDatas.map((outputData) => ({ @@ -75,25 +71,18 @@ function getDirectionForOutputs( } } -function convertTransactionOutputResponsesToWrappedOutputs( - transactionId: string, - outputResponses: OutputResponse[] -): IWrappedOutput[] { - return outputResponses.map((outputResponse) => - convertTransactionOutputResponseToWrappedOutput(transactionId, outputResponse) - ) +function convertTransactionOutputResponsesToWrappedOutputs(outputResponses: OutputWithMetadata[]): IWrappedOutput[] { + return outputResponses.map((outputResponse) => convertTransactionOutputResponseToWrappedOutput(outputResponse)) } -function convertTransactionOutputResponseToWrappedOutput( - transactionId: string, - outputResponse: OutputResponse -): IWrappedOutput { - const outputId = getOutputIdFromTransactionIdAndIndex(transactionId, outputResponse.metadata.outputIndex) - return { outputId, output: outputResponse.output, metadata: outputResponse.metadata } +function convertTransactionOutputResponseToWrappedOutput(outputResponse: OutputWithMetadata): IWrappedOutput { + return { + outputId: outputResponse.metadata.outputId, + output: outputResponse.output, + metadata: outputResponse.metadata, + } } function getUtxoInputsFromWrappedInputs(wrappedInputs: IWrappedOutput[]): UTXOInput[] { - return ( - wrappedInputs?.map((input) => new UTXOInput(input.metadata?.transactionId, input.metadata?.outputIndex)) ?? [] - ) + return wrappedInputs?.map((input) => UTXOInput.fromOutputId(input.outputId)) ?? [] } diff --git a/packages/shared/lib/core/wallet/utils/outputs/preprocessOutgoingTransaction.ts b/packages/shared/lib/core/wallet/utils/outputs/preprocessOutgoingTransaction.ts index c0a17230174..ee2f605550a 100644 --- a/packages/shared/lib/core/wallet/utils/outputs/preprocessOutgoingTransaction.ts +++ b/packages/shared/lib/core/wallet/utils/outputs/preprocessOutgoingTransaction.ts @@ -15,11 +15,11 @@ export async function preprocessOutgoingTransaction( const outputs = convertTransactionsOutputTypesToWrappedOutputs(transactionId, regularTransactionEssence.outputs) const direction = getDirectionFromOutgoingTransaction(outputs, wallet.depositAddress) - const utxoInputs = regularTransactionEssence.inputs.map((i) => i as UTXOInput) const inputIds = await Promise.all( - utxoInputs.map((input) => { - const transactionId = input.transactionId - const transactionOutputIndex = input.transactionOutputIndex + regularTransactionEssence.inputs.map((input) => { + const _input = input as UTXOInput + const transactionId = _input.transactionId + const transactionOutputIndex = _input.transactionOutputIndex return computeOutputId(transactionId, transactionOutputIndex) }) ) @@ -33,7 +33,6 @@ export async function preprocessOutgoingTransaction( time: new Date(Number(transaction.timestamp)), inclusionState: transaction.inclusionState, wrappedInputs: inputs, - utxoInputs, } } From 1391a491f35883bb78fe6c3930ec7f241f4aad67 Mon Sep 17 00:00:00 2001 From: Marc Espin Date: Mon, 25 Mar 2024 17:43:43 +0100 Subject: [PATCH 4/6] feat: Stop generating txs out of outputs (#8248) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Sync SDK types * feat: stop generating txs out of outputs --------- Co-authored-by: cpl121 <100352899+cpl121@users.noreply.github.com> Co-authored-by: Begoña Álvarez de la Cruz --- .../actions/activities/generateAndStoreActivitiesForWallet.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/shared/lib/core/wallet/actions/activities/generateAndStoreActivitiesForWallet.ts b/packages/shared/lib/core/wallet/actions/activities/generateAndStoreActivitiesForWallet.ts index 8e8cb8c2fb8..181d241a91a 100644 --- a/packages/shared/lib/core/wallet/actions/activities/generateAndStoreActivitiesForWallet.ts +++ b/packages/shared/lib/core/wallet/actions/activities/generateAndStoreActivitiesForWallet.ts @@ -2,7 +2,6 @@ import { IWalletState } from '@core/wallet/interfaces' import { setOutgoingAsyncActivitiesToClaimed } from '../setOutgoingAsyncActivitiesToClaimed' import { preprocessTransactionsForWallet } from './preprocessTransactionsForWallet' -import { preprocessOutputsForWallet } from './preprocessOutputsForWallet' import { linkTransactionsWithClaimingTransactions } from './linkTransactionsWithClaimingTransactions' import { hideActivitiesForFoundries } from './hideActivitiesForFoundries' import { generateActivitiesFromProcessedTransactions } from './generateActivitiesFromProcessedTransactions' @@ -13,7 +12,7 @@ export async function generateAndStoreActivitiesForWallet(wallet: IWalletState): // Step 1: process wallet transactions and outputs into processed transactions const processedTransactions = [ ...(await preprocessTransactionsForWallet(wallet)), - ...(await preprocessOutputsForWallet(wallet)), + // ...(await preprocessOutputsForWallet(wallet)), ] // Step 2: link transactions with corresponding claiming transactions From 6607c7573854986f0bac3fb73d966500b757564d Mon Sep 17 00:00:00 2001 From: evavirseda Date: Mon, 25 Mar 2024 17:48:48 +0100 Subject: [PATCH 5/6] feat: add syncBalance poll (#8256) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Begoña Álvarez de la Cruz --- .../desktop/views/dashboard/Dashboard.svelte | 8 ++++---- .../lib/core/wallet/actions/SyncBalancePoll.ts | 16 ++++++++++++++++ packages/shared/lib/core/wallet/actions/index.ts | 1 + 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 packages/shared/lib/core/wallet/actions/SyncBalancePoll.ts diff --git a/packages/desktop/views/dashboard/Dashboard.svelte b/packages/desktop/views/dashboard/Dashboard.svelte index 0e0e1904e4e..8baad4eef5e 100644 --- a/packages/desktop/views/dashboard/Dashboard.svelte +++ b/packages/desktop/views/dashboard/Dashboard.svelte @@ -18,7 +18,6 @@ import { onDestroy, onMount } from 'svelte' import Sidebar from './Sidebar.svelte' import TopNavigation from './TopNavigation.svelte' - import { addNftsToDownloadQueue, downloadingNftId, @@ -28,12 +27,11 @@ resetNftDownloadQueue, selectedWalletNfts, } from '@core/nfts' - import { selectedWalletId } from '@core/wallet' + import { clearBalanceSyncPoll, selectedWalletId, syncBalancePoll } from '@core/wallet' import { get } from 'svelte/store' import features from '@features/features' - import { isAwareOfMetricSystemDrop } from '@contexts/dashboard/stores' + import { isAwareOfMetricSystemDrop, showBalanceOverviewPopup } from '@contexts/dashboard/stores' import { openPopup, PopupId } from '@auxiliary/popup' - import { showBalanceOverviewPopup } from '@contexts/dashboard/stores' const tabs = { wallet: Wallet, @@ -83,6 +81,7 @@ } onMount(() => { + syncBalancePoll($selectedWalletId, true) Platform.onEvent('menu-logout', () => { void logout() }) @@ -126,6 +125,7 @@ }) onDestroy(() => { + clearBalanceSyncPoll() Platform.DeepLinkManager.clearDeepLinkRequest() Platform.removeListenersForEvent('deep-link-params') diff --git a/packages/shared/lib/core/wallet/actions/SyncBalancePoll.ts b/packages/shared/lib/core/wallet/actions/SyncBalancePoll.ts new file mode 100644 index 00000000000..570844feb9f --- /dev/null +++ b/packages/shared/lib/core/wallet/actions/SyncBalancePoll.ts @@ -0,0 +1,16 @@ +import { DEFAULT_SECONDS_PER_SLOT } from '../../network' +import { MILLISECONDS_PER_SECOND } from '../../utils' +import { syncBalance } from './syncBalance' + +let balanceSyncInterval: number + +export async function syncBalancePoll(walletId: string, syncCongestion: boolean): Promise { + await syncBalance(walletId, syncCongestion) + balanceSyncInterval = window.setInterval(() => { + void syncBalance(walletId, syncCongestion) + }, DEFAULT_SECONDS_PER_SLOT * MILLISECONDS_PER_SECOND) +} + +export function clearBalanceSyncPoll(): void { + clearInterval(balanceSyncInterval) +} diff --git a/packages/shared/lib/core/wallet/actions/index.ts b/packages/shared/lib/core/wallet/actions/index.ts index 5ab7d2a4953..5f215a387b3 100644 --- a/packages/shared/lib/core/wallet/actions/index.ts +++ b/packages/shared/lib/core/wallet/actions/index.ts @@ -32,6 +32,7 @@ export * from './setStrongholdPasswordClearInterval' export * from './startBackgroundSync' export * from './getParticipationOverview' export * from './syncBalance' +export * from './SyncBalancePoll' export * from './syncVotingPower' export * from './tryCreateAdditionalWallet' export * from './getClient' From d805b5a9e3ddd1479e3212e8668950780b447b42 Mon Sep 17 00:00:00 2001 From: cpl121 <100352899+cpl121@users.noreply.github.com> Date: Mon, 25 Mar 2024 18:07:45 +0100 Subject: [PATCH 6/6] feat: update Mint native Token (#8130) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: update dev tools to network upgrade: Mint NFT * fix: imports * fix: test * feat: update Mint native Token * fix: rename DEFAULT_NFT_FEATURE_ENTRY_KEY * fix: disable tests * refactor: rename DEFAULT_METADATA_FEATURE_ENTRY_KEY constant * fix: error to build native tokens * fis: imports * fix: update temp interface * fix: errors * fix: undo votingPower in buildWalletState * fix: remove DEFAULT_NFT_FEATURE_ENTRY_KEY reference --------- Co-authored-by: Begoña Álvarez de la Cruz --- .../MintNativeTokenConfirmationPopup.svelte | 10 +++---- .../popups/MintNativeTokenFormPopup.svelte | 26 +++++++++---------- .../features/developer-tools.features.ts | 2 +- .../components/inputs/AccountInput.svelte | 6 ++--- .../components/inputs/OptionalInput.svelte | 2 +- .../default-nft-feature-entry-key.constant.ts | 1 - .../shared/lib/core/nfts/constants/index.ts | 1 - .../nfts/tests/buildNftFromNftOutput.test.ts | 4 +-- .../shared/lib/core/wallet/actions/mintNft.ts | 10 +++---- .../actions/prepareCreateNativeToken.ts | 7 +++-- .../lib/core/wallet/actions/prepareMintNft.ts | 16 ++++-------- ...ult-metadata-feature-entry-key.constant.ts | 1 + .../shared/lib/core/wallet/constants/index.ts | 1 + .../mint-token-details.interface.ts | 2 +- .../wallet/utils/buildFoundryOutputData.ts | 20 +++++++------- .../core/wallet/utils/buildNftOutputData.ts | 6 ++--- .../helper/getMetadataFromOutput.ts | 4 +-- .../utils/getMetadataFromFoundryOutput.ts | 7 ++--- .../utils/outputs/getMetadataFromNftOutput.ts | 4 +-- .../getSerialNumberFromAccountAddress.ts | 5 +--- 20 files changed, 63 insertions(+), 72 deletions(-) delete mode 100644 packages/shared/lib/core/nfts/constants/default-nft-feature-entry-key.constant.ts create mode 100644 packages/shared/lib/core/wallet/constants/default-metadata-feature-entry-key.constant.ts diff --git a/packages/desktop/components/popups/MintNativeTokenConfirmationPopup.svelte b/packages/desktop/components/popups/MintNativeTokenConfirmationPopup.svelte index 0b639b85376..bb45f8e126c 100644 --- a/packages/desktop/components/popups/MintNativeTokenConfirmationPopup.svelte +++ b/packages/desktop/components/popups/MintNativeTokenConfirmationPopup.svelte @@ -32,12 +32,12 @@ async function prepareFoundryOutput(): Promise { if ($mintTokenDetails && $selectedWallet && metadata) { - const { totalSupply, circulatingSupply, accountId } = $mintTokenDetails + const { totalSupply, circulatingSupply, accountAddress } = $mintTokenDetails const outputData = await buildFoundryOutputData( Number(totalSupply), Number(circulatingSupply), metadata, - accountId + accountAddress ) const client = await getClient() const preparedOutput = await client.buildFoundryOutput(outputData) @@ -61,10 +61,10 @@ details: IMintTokenDetails | undefined ): { [key: string]: { data: string; tooltipText?: string; isCopyable?: boolean } } | undefined { if (details) { - const { name: tokenName, symbol, accountId, url, logoUrl, decimals, totalSupply } = details + const { name: tokenName, symbol, accountAddress, url, logoUrl, decimals, totalSupply } = details return { - ...(accountId && { - account: { data: accountId, isCopyable: true }, + ...(accountAddress && { + account: { data: accountAddress, isCopyable: true }, }), ...(storageDeposit && { storageDeposit: { data: storageDeposit }, diff --git a/packages/desktop/components/popups/MintNativeTokenFormPopup.svelte b/packages/desktop/components/popups/MintNativeTokenFormPopup.svelte index 5ce0438d2d3..a5562724052 100644 --- a/packages/desktop/components/popups/MintNativeTokenFormPopup.svelte +++ b/packages/desktop/components/popups/MintNativeTokenFormPopup.svelte @@ -3,7 +3,7 @@ import { localize } from '@core/i18n' import { setMintTokenDetails, mintTokenDetails, IMintTokenDetails } from '@core/wallet' import { closePopup, openPopup, PopupId } from '@auxiliary/popup' - import { Button, Error, NumberInput, Text, TextInput, OptionalInput, FontWeight, AccountInput } from '@ui' + import { Button, Error, NumberInput, Text, TextInput, OptionalInput, FontWeight, AccountInput, TextType } from '@ui' import { onMount } from 'svelte' import { MAX_SUPPORTED_DECIMALS } from '@core/wallet/constants/max-supported-decimals.constants' import { handleError } from '@core/error/handlers/handleError' @@ -19,7 +19,7 @@ description: undefined, url: undefined, logoUrl: undefined, - accountId: undefined, + accountAddress: undefined, } let { @@ -31,7 +31,7 @@ description, url, logoUrl, - accountId, + accountAddress, } = $mintTokenDetails ?? DEFAULT let nameError: string = '' @@ -42,8 +42,8 @@ $: circulatingSupply, (circulatingSupplyError = '') let symbolError: string $: symbol, (symbolError = '') - let accountIdError: string - $: accountId, (accountIdError = '') + let accountAddressError: string + $: accountAddress, (accountAddressError = '') let error: BaseError let decimalsInput: OptionalInput @@ -64,7 +64,7 @@ description, url, logoUrl, - accountId, + accountAddress, } if (valid && isEverythingDefined(tokenDetailsForm)) { setMintTokenDetails(tokenDetailsForm) @@ -82,7 +82,7 @@ form.circulatingSupply !== undefined && form.decimals !== undefined && form.symbol !== undefined && - form.accountId !== undefined + form.accountAddress !== undefined ) } @@ -170,12 +170,12 @@
- + {localize('popups.nativeToken.formTitle')}
- + {#if error} diff --git a/packages/desktop/features/developer-tools.features.ts b/packages/desktop/features/developer-tools.features.ts index 9944ea62f0c..4dc178a0945 100644 --- a/packages/desktop/features/developer-tools.features.ts +++ b/packages/desktop/features/developer-tools.features.ts @@ -9,7 +9,7 @@ const developerToolsFeatures: IDeveloperFeatures = { enabled: true, }, mintNativeTokens: { - enabled: false, + enabled: true, }, account: { enabled: false, diff --git a/packages/shared/components/inputs/AccountInput.svelte b/packages/shared/components/inputs/AccountInput.svelte index 2229a75b2e9..e3827e5eca8 100644 --- a/packages/shared/components/inputs/AccountInput.svelte +++ b/packages/shared/components/inputs/AccountInput.svelte @@ -13,9 +13,9 @@ let modal: Modal = undefined const accountOptions: IOption[] = - $selectedWallet.balances?.accounts.map((hexAccountId: string, index: number) => { - const accountId = AddressConverter.addressToBech32(new AccountAddress(hexAccountId)) - return { key: 'Account' + (index + 1), value: accountId } + $selectedWallet?.balances?.accounts.map((hexAccountId: string, index: number) => { + const accountAddress = AddressConverter.addressToBech32(new AccountAddress(hexAccountId)) + return { key: 'Account ' + (index + 1), value: accountAddress } }) ?? [] let selected: IOption = accountOptions.find((option) => option.value === account) diff --git a/packages/shared/components/inputs/OptionalInput.svelte b/packages/shared/components/inputs/OptionalInput.svelte index 2c32697fd87..15d7724b6e3 100644 --- a/packages/shared/components/inputs/OptionalInput.svelte +++ b/packages/shared/components/inputs/OptionalInput.svelte @@ -7,7 +7,7 @@ export let label: string = '' export let description: string = '' - export let value: string | undefined = undefined + export let value: string | number | undefined = undefined export let fontSize: number = 15 export let error: string = '' export let classes: string = null diff --git a/packages/shared/lib/core/nfts/constants/default-nft-feature-entry-key.constant.ts b/packages/shared/lib/core/nfts/constants/default-nft-feature-entry-key.constant.ts deleted file mode 100644 index 1ce1d0989c1..00000000000 --- a/packages/shared/lib/core/nfts/constants/default-nft-feature-entry-key.constant.ts +++ /dev/null @@ -1 +0,0 @@ -export const DEFAULT_NFT_FEATURE_ENTRY_KEY = 'data' diff --git a/packages/shared/lib/core/nfts/constants/index.ts b/packages/shared/lib/core/nfts/constants/index.ts index 40fa0f03dae..7b8986090a5 100644 --- a/packages/shared/lib/core/nfts/constants/index.ts +++ b/packages/shared/lib/core/nfts/constants/index.ts @@ -4,4 +4,3 @@ export * from './default-max-nft-downloading-time-in-seconds.constant' export * from './default-max-nft-size-in-megabytes.constant' export * from './nft-id-byte-length.constant' export * from './nft-media-file-name.constant' -export * from './default-nft-feature-entry-key.constant' diff --git a/packages/shared/lib/core/nfts/tests/buildNftFromNftOutput.test.ts b/packages/shared/lib/core/nfts/tests/buildNftFromNftOutput.test.ts index 9b95abb63e2..1dabc0e0f10 100644 --- a/packages/shared/lib/core/nfts/tests/buildNftFromNftOutput.test.ts +++ b/packages/shared/lib/core/nfts/tests/buildNftFromNftOutput.test.ts @@ -1,5 +1,6 @@ import { plainToInstance } from 'class-transformer' import { IWrappedOutput } from '../../wallet/interfaces' +import { DEFAULT_METADATA_FEATURE_ENTRY_KEY } from '../../wallet/constants' import { buildNftFromNftOutput } from '../utils/buildNftFromNftOutput' import { AddressUnlockCondition, @@ -10,7 +11,6 @@ import { TimelockUnlockCondition, } from '@iota/sdk/out/types' import { Address, AddressType, NftOutput } from '@iota/sdk/out/types' -import { DEFAULT_NFT_FEATURE_ENTRY_KEY } from '../constants' const accountAddress = 'rms1qr47ee0fhahukrzec088v9lngv7w5k2sn3jjtwvkcpjfgxhhsazlsurxrx9' @@ -22,7 +22,7 @@ function buildImmutableFeatures() { return [ new IssuerFeature(new Ed25519Address('0x20dceb927cfdc2cea642fbf77aed81f42400145b5a4fd906f1aa40af1c31afb1')), new MetadataFeature({ - [DEFAULT_NFT_FEATURE_ENTRY_KEY]: + [DEFAULT_METADATA_FEATURE_ENTRY_KEY]: '0x7b227374616e64617264223a224952433237222c2276657273696f6e223a2276312e30222c226e616d65223a227364617364222c2274797065223a22696d6167652f706e67222c22757269223a2268747470733a2f2f697066732e696f2f697066732f516d51717a4d546176516754346634543576365057427037584e4b746f506d43396a766e313257505433676b5345227d', }), ] diff --git a/packages/shared/lib/core/wallet/actions/mintNft.ts b/packages/shared/lib/core/wallet/actions/mintNft.ts index 9243e798bd9..5376376dbe5 100644 --- a/packages/shared/lib/core/wallet/actions/mintNft.ts +++ b/packages/shared/lib/core/wallet/actions/mintNft.ts @@ -1,11 +1,6 @@ import { showAppNotification } from '@auxiliary/notification' import { localize } from '@core/i18n' -import { - addOrUpdateNftInAllWalletNfts, - buildNftFromNftOutput, - DEFAULT_NFT_FEATURE_ENTRY_KEY, - IIrc27Metadata, -} from '@core/nfts' +import { addOrUpdateNftInAllWalletNfts, buildNftFromNftOutput, IIrc27Metadata } from '@core/nfts' import { Converter } from '@core/utils' import { MetadataFeature, MintNftParams, OutputType } from '@iota/sdk/out/types' import { ActivityAction } from '../enums' @@ -18,6 +13,7 @@ import { import { NftActivity } from '../types' import { getDefaultTransactionOptions, preprocessOutgoingTransaction } from '../utils' import { generateSingleNftActivity } from '../utils/generateActivity/generateSingleNftActivity' +import { DEFAULT_METADATA_FEATURE_ENTRY_KEY } from '../constants' export async function mintNft(metadata: IIrc27Metadata, quantity: number): Promise { try { @@ -29,7 +25,7 @@ export async function mintNft(metadata: IIrc27Metadata, quantity: number): Promi issuer: wallet.depositAddress, address: wallet.depositAddress, immutableMetadata: new MetadataFeature({ - [DEFAULT_NFT_FEATURE_ENTRY_KEY]: Converter.utf8ToHex(JSON.stringify(metadata)), + [DEFAULT_METADATA_FEATURE_ENTRY_KEY]: Converter.utf8ToHex(JSON.stringify(metadata)), }), } diff --git a/packages/shared/lib/core/wallet/actions/prepareCreateNativeToken.ts b/packages/shared/lib/core/wallet/actions/prepareCreateNativeToken.ts index d281cdab17f..69dd12fc1f3 100644 --- a/packages/shared/lib/core/wallet/actions/prepareCreateNativeToken.ts +++ b/packages/shared/lib/core/wallet/actions/prepareCreateNativeToken.ts @@ -1,8 +1,9 @@ import { Converter } from '@core/utils' -import { CreateNativeTokenParams, PreparedCreateNativeTokenTransaction } from '@iota/sdk/out/types' +import { CreateNativeTokenParams, MetadataFeature, PreparedCreateNativeTokenTransaction } from '@iota/sdk/out/types' import { IIrc30Metadata } from '../interfaces' import { getSelectedWallet } from '../stores' import { getDefaultTransactionOptions } from '../utils' +import { DEFAULT_METADATA_FEATURE_ENTRY_KEY } from '../constants' export async function prepareCreateNativeToken( maximumSupply: number, @@ -15,7 +16,9 @@ export async function prepareCreateNativeToken( const params: CreateNativeTokenParams = { maximumSupply: BigInt(maximumSupply), circulatingSupply: BigInt(circulatingSupply), - foundryMetadata: Converter.utf8ToHex(JSON.stringify(metadata)), + foundryMetadata: new MetadataFeature({ + [DEFAULT_METADATA_FEATURE_ENTRY_KEY]: Converter.utf8ToHex(JSON.stringify(metadata)), + }), } return wallet.prepareCreateNativeToken(params, getDefaultTransactionOptions()) diff --git a/packages/shared/lib/core/wallet/actions/prepareMintNft.ts b/packages/shared/lib/core/wallet/actions/prepareMintNft.ts index 012d0c00719..54d60ed211d 100644 --- a/packages/shared/lib/core/wallet/actions/prepareMintNft.ts +++ b/packages/shared/lib/core/wallet/actions/prepareMintNft.ts @@ -1,15 +1,9 @@ -import { DEFAULT_NFT_FEATURE_ENTRY_KEY, IIrc27Metadata } from '@core/nfts' +import { IIrc27Metadata } from '@core/nfts' import { Converter } from '@core/utils' -import { Bech32Address, MetadataFeature, MintNftParams, PreparedTransaction } from '@iota/sdk/out/types' +import { MetadataFeature, MintNftParams, PreparedTransaction } from '@iota/sdk/out/types' import { getSelectedWallet } from '../stores' import { getDefaultTransactionOptions } from '../utils' - -// TODO: Update this temporary interface when fixed in the SDK, linked issue https://github.com/iotaledger/firefly/issues/8134 -interface MintNftParamsTemp { - issuer: Bech32Address - address: Bech32Address - immutableMetadata: MetadataFeature -} +import { DEFAULT_METADATA_FEATURE_ENTRY_KEY } from '../constants' export async function prepareMintNft( metadata: IIrc27Metadata, @@ -18,11 +12,11 @@ export async function prepareMintNft( try { const wallet = getSelectedWallet() if (!wallet) return - const mintNftParams: MintNftParamsTemp = { + const mintNftParams: MintNftParams = { issuer: wallet.depositAddress, address: wallet.depositAddress, immutableMetadata: new MetadataFeature({ - [DEFAULT_NFT_FEATURE_ENTRY_KEY]: Converter.utf8ToHex(JSON.stringify(metadata)), + [DEFAULT_METADATA_FEATURE_ENTRY_KEY]: Converter.utf8ToHex(JSON.stringify(metadata)), }), } diff --git a/packages/shared/lib/core/wallet/constants/default-metadata-feature-entry-key.constant.ts b/packages/shared/lib/core/wallet/constants/default-metadata-feature-entry-key.constant.ts new file mode 100644 index 00000000000..b81df9ce4e0 --- /dev/null +++ b/packages/shared/lib/core/wallet/constants/default-metadata-feature-entry-key.constant.ts @@ -0,0 +1 @@ +export const DEFAULT_METADATA_FEATURE_ENTRY_KEY = 'data' diff --git a/packages/shared/lib/core/wallet/constants/index.ts b/packages/shared/lib/core/wallet/constants/index.ts index a066e5b194b..0e01e7e717a 100644 --- a/packages/shared/lib/core/wallet/constants/index.ts +++ b/packages/shared/lib/core/wallet/constants/index.ts @@ -12,3 +12,4 @@ export * from './official-token-ids.constant' export * from './reserved-tag-keywords.constant' export * from './max-wallet-name-length.constant' export * from './default-sync-options.constant' +export * from './default-metadata-feature-entry-key.constant' diff --git a/packages/shared/lib/core/wallet/interfaces/mint-token-details.interface.ts b/packages/shared/lib/core/wallet/interfaces/mint-token-details.interface.ts index 58e0c0fef44..a46751093b9 100644 --- a/packages/shared/lib/core/wallet/interfaces/mint-token-details.interface.ts +++ b/packages/shared/lib/core/wallet/interfaces/mint-token-details.interface.ts @@ -7,5 +7,5 @@ export interface IMintTokenDetails { description?: string url?: string logoUrl?: string - accountId: string + accountAddress: string } diff --git a/packages/shared/lib/core/wallet/utils/buildFoundryOutputData.ts b/packages/shared/lib/core/wallet/utils/buildFoundryOutputData.ts index 064d8f22a5d..4ec28cbdeeb 100644 --- a/packages/shared/lib/core/wallet/utils/buildFoundryOutputData.ts +++ b/packages/shared/lib/core/wallet/utils/buildFoundryOutputData.ts @@ -10,23 +10,23 @@ import { import { Converter } from '@core/utils' import { IIrc30Metadata } from '../interfaces' import { getSerialNumberFromAccountAddress } from './outputs' +import { DEFAULT_METADATA_FEATURE_ENTRY_KEY } from '../constants' +import { AddressConverter } from './AddressConverter' export async function buildFoundryOutputData( totalSupply: number, circulatingSupply: number, metadata: IIrc30Metadata, - accountId: string + accountAddress: string ): Promise { - const immutableAccountUnlockCondition = new ImmutableAccountAddressUnlockCondition(new AccountAddress(accountId)) - - const unlockConditions: UnlockCondition[] = [immutableAccountUnlockCondition] - + const accountId = AddressConverter.parseBech32Address(accountAddress) + const unlockConditions: UnlockCondition[] = [ + new ImmutableAccountAddressUnlockCondition(new AccountAddress(accountId)), + ] const tokenScheme = new SimpleTokenScheme(BigInt(circulatingSupply), BigInt(0), BigInt(totalSupply)) - - const metadataFeature = new MetadataFeature(Converter.utf8ToHex(JSON.stringify(metadata))) - - const immutableFeatures: Feature[] = [metadataFeature] - + const immutableFeatures: Feature[] = [ + new MetadataFeature({ [DEFAULT_METADATA_FEATURE_ENTRY_KEY]: Converter.utf8ToHex(JSON.stringify(metadata)) }), + ] const serialNumber = await getSerialNumberFromAccountAddress(accountId) return { diff --git a/packages/shared/lib/core/wallet/utils/buildNftOutputData.ts b/packages/shared/lib/core/wallet/utils/buildNftOutputData.ts index 966c3cc351d..d06f2d6237c 100644 --- a/packages/shared/lib/core/wallet/utils/buildNftOutputData.ts +++ b/packages/shared/lib/core/wallet/utils/buildNftOutputData.ts @@ -1,7 +1,7 @@ import { AddressUnlockCondition, Ed25519Address, MetadataFeature, NftOutputBuilderParams } from '@iota/sdk/out/types' import { Converter } from '@core/utils' -import { EMPTY_HEX_ID } from '../constants' -import { IIrc27Metadata, DEFAULT_NFT_FEATURE_ENTRY_KEY } from '@core/nfts' +import { DEFAULT_METADATA_FEATURE_ENTRY_KEY, EMPTY_HEX_ID } from '../constants' +import { IIrc27Metadata } from '@core/nfts' import { AddressConverter } from './AddressConverter' export function buildNftOutputData(metadata: IIrc27Metadata, address: string): NftOutputBuilderParams { @@ -12,7 +12,7 @@ export function buildNftOutputData(metadata: IIrc27Metadata, address: string): N const unlockConditions: AddressUnlockCondition[] = [addressUnlockCondition] const metadataFeature = new MetadataFeature({ - [DEFAULT_NFT_FEATURE_ENTRY_KEY]: Converter.utf8ToHex(JSON.stringify(metadata)), + [DEFAULT_METADATA_FEATURE_ENTRY_KEY]: Converter.utf8ToHex(JSON.stringify(metadata)), }) const immutableFeatures: MetadataFeature[] = [metadataFeature] diff --git a/packages/shared/lib/core/wallet/utils/generateActivity/helper/getMetadataFromOutput.ts b/packages/shared/lib/core/wallet/utils/generateActivity/helper/getMetadataFromOutput.ts index e1a561f7d30..aa0d0f33a92 100644 --- a/packages/shared/lib/core/wallet/utils/generateActivity/helper/getMetadataFromOutput.ts +++ b/packages/shared/lib/core/wallet/utils/generateActivity/helper/getMetadataFromOutput.ts @@ -4,7 +4,7 @@ import { EXTERNALLY_OWNED_ACCOUNT } from '@core/layer-2/constants' import { parseLayer2MetadataForTransfer } from '@core/layer-2/utils' import { containsControlCharacters, Converter } from '@core/utils' import { CommonOutput, FeatureType, MetadataFeature, Output } from '@iota/sdk/out/types' -import { DEFAULT_NFT_FEATURE_ENTRY_KEY } from '@core/nfts' +import { DEFAULT_METADATA_FEATURE_ENTRY_KEY } from '../../../constants' export function getMetadataFromOutput(output: Output): string | undefined { const commonOutput = output as CommonOutput @@ -13,7 +13,7 @@ export function getMetadataFromOutput(output: Output): string | undefined { if (metadataFeature) { // TODO: update this to return all entries, linked issue https://github.com/iotaledger/firefly/issues/8120 - const data = metadataFeature?.entries?.[DEFAULT_NFT_FEATURE_ENTRY_KEY] ?? undefined + const data = metadataFeature?.entries?.[DEFAULT_METADATA_FEATURE_ENTRY_KEY] ?? undefined if (data) { const isVotingOutput = isParticipationOutput(output) diff --git a/packages/shared/lib/core/wallet/utils/getMetadataFromFoundryOutput.ts b/packages/shared/lib/core/wallet/utils/getMetadataFromFoundryOutput.ts index 4c2ce3b4791..7ea6b4b770d 100644 --- a/packages/shared/lib/core/wallet/utils/getMetadataFromFoundryOutput.ts +++ b/packages/shared/lib/core/wallet/utils/getMetadataFromFoundryOutput.ts @@ -1,15 +1,16 @@ import { FeatureType, FoundryOutput, MetadataFeature } from '@iota/sdk/out/types' +import { DEFAULT_METADATA_FEATURE_ENTRY_KEY } from '../constants' -export function getMetadataFromFoundryOutput(foundry: FoundryOutput): string { +export function getMetadataFromFoundryOutput(foundry: FoundryOutput): string | undefined { for (const feature of foundry?.immutableFeatures ?? []) { if (feature?.type === FeatureType.Metadata) { - return (feature as MetadataFeature).data + return (feature as MetadataFeature)?.entries?.[DEFAULT_METADATA_FEATURE_ENTRY_KEY] } } for (const feature of foundry?.features ?? []) { if (feature?.type === FeatureType.Metadata) { - return (feature as MetadataFeature).data + return (feature as MetadataFeature)?.entries?.[DEFAULT_METADATA_FEATURE_ENTRY_KEY] } } diff --git a/packages/shared/lib/core/wallet/utils/outputs/getMetadataFromNftOutput.ts b/packages/shared/lib/core/wallet/utils/outputs/getMetadataFromNftOutput.ts index c5f17839061..048b3200437 100644 --- a/packages/shared/lib/core/wallet/utils/outputs/getMetadataFromNftOutput.ts +++ b/packages/shared/lib/core/wallet/utils/outputs/getMetadataFromNftOutput.ts @@ -1,10 +1,10 @@ import { FeatureType, MetadataFeature, NftOutput } from '@iota/sdk/out/types' -import { DEFAULT_NFT_FEATURE_ENTRY_KEY } from '@core/nfts' +import { DEFAULT_METADATA_FEATURE_ENTRY_KEY } from '../../constants' export function getMetadataFromNftOutput(output: NftOutput): string { const metadata = output.immutableFeatures?.find( (feature) => feature.type === FeatureType.Metadata ) as MetadataFeature // TODO: update this to return all entries, linked issue https://github.com/iotaledger/firefly/issues/8120 - return metadata?.entries?.[DEFAULT_NFT_FEATURE_ENTRY_KEY] + return metadata?.entries?.[DEFAULT_METADATA_FEATURE_ENTRY_KEY] } diff --git a/packages/shared/lib/core/wallet/utils/outputs/getSerialNumberFromAccountAddress.ts b/packages/shared/lib/core/wallet/utils/outputs/getSerialNumberFromAccountAddress.ts index 914661fb0f3..3155012bf9a 100644 --- a/packages/shared/lib/core/wallet/utils/outputs/getSerialNumberFromAccountAddress.ts +++ b/packages/shared/lib/core/wallet/utils/outputs/getSerialNumberFromAccountAddress.ts @@ -1,15 +1,12 @@ import { get } from 'svelte/store' -import { api } from '@core/api' import { AccountOutput } from '@iota/sdk/out/types' import { selectedWallet } from '../../stores' -export async function getSerialNumberFromAccountAddress(accountAddress: string): Promise { +export async function getSerialNumberFromAccountAddress(accountId: string): Promise { const wallet = get(selectedWallet) if (!wallet) { throw new Error('Wallet is undefined') } - const accountId = api.bech32ToHex(accountAddress) - const [accountOutput] = await wallet.unspentOutputs({ accountIds: [accountId] }) // If it's the first state transition of the account address, the accountId is 0x0.