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/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/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, 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} -
+
{ - 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/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' 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. diff --git a/packages/shared/lib/core/wallet/utils/outputs/preprocessOutgoingTransaction.ts b/packages/shared/lib/core/wallet/utils/outputs/preprocessOutgoingTransaction.ts index b49ab348049..86b555726a9 100644 --- a/packages/shared/lib/core/wallet/utils/outputs/preprocessOutgoingTransaction.ts +++ b/packages/shared/lib/core/wallet/utils/outputs/preprocessOutgoingTransaction.ts @@ -31,7 +31,6 @@ export async function preprocessOutgoingTransaction( time: new Date(Number(transaction.timestamp)), inclusionState: transaction.inclusionState, wrappedInputs: inputs, - utxoInputs, } }