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: update Mint native Token #8130

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b824d8f
feat: update dev tools to network upgrade: Mint NFT
cpl121 Feb 29, 2024
fc214d1
Merge branches 'feat/update-dev-tools-mint-nft' and 'develop-iota2.0'…
cpl121 Mar 1, 2024
6637271
Merge branch 'develop-iota2.0' of github.com:iotaledger/firefly into …
cpl121 Mar 1, 2024
200d4c4
Merge branches 'feat/update-dev-tools-mint-nft' and 'develop-iota2.0'…
cpl121 Mar 1, 2024
837f7ad
fix: imports
cpl121 Mar 1, 2024
b1e765c
fix: test
cpl121 Mar 1, 2024
24422bd
Merge branches 'feat/update-dev-tools-mint-nft' and 'develop-iota2.0'…
cpl121 Mar 5, 2024
e3348e3
feat: update Mint native Token
cpl121 Mar 5, 2024
d2b5547
fix: rename DEFAULT_NFT_FEATURE_ENTRY_KEY
cpl121 Mar 5, 2024
cccbe35
fix: disable tests
cpl121 Mar 5, 2024
139423f
Merge branches 'feat/update-dev-tools-mint-native-token' and 'feat/up…
cpl121 Mar 5, 2024
8f7cdaf
refactor: rename DEFAULT_METADATA_FEATURE_ENTRY_KEY constant
cpl121 Mar 5, 2024
a861969
fix: error to build native tokens
cpl121 Mar 5, 2024
68affa7
fis: imports
cpl121 Mar 5, 2024
5077d35
Merge branches 'feat/update-dev-tools-mint-native-token' and 'develop…
cpl121 Mar 5, 2024
db2f86a
Merge branch 'develop-iota2.0' into feat/update-dev-tools-mint-native…
cpl121 Mar 8, 2024
16a8bbb
Merge branches 'feat/update-dev-tools-mint-native-token' and 'develop…
cpl121 Mar 12, 2024
dde6e70
Merge branch 'develop-iota2.0' into feat/update-dev-tools-mint-native…
cpl121 Mar 14, 2024
fb33ed7
Merge branch 'develop-iota2.0' into feat/update-dev-tools-mint-native…
cpl121 Mar 20, 2024
339f0a7
Merge branches 'feat/update-dev-tools-mint-native-token' and 'develop…
cpl121 Mar 21, 2024
dac7a1e
fix: update temp interface
cpl121 Mar 21, 2024
dbcf314
fix: errors
cpl121 Mar 21, 2024
56d3192
Merge branch 'develop-iota2.0' into feat/update-dev-tools-mint-native…
cpl121 Mar 25, 2024
a00b851
fix: undo votingPower in buildWalletState
cpl121 Mar 25, 2024
a0fc825
fix: remove DEFAULT_NFT_FEATURE_ENTRY_KEY reference
cpl121 Mar 25, 2024
f0279ea
Merge branch 'develop-iota2.0' into feat/update-dev-tools-mint-native…
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 @@ -32,12 +32,12 @@

async function prepareFoundryOutput(): Promise<void> {
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)
Expand All @@ -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 },
Expand Down
26 changes: 13 additions & 13 deletions packages/desktop/components/popups/MintNativeTokenFormPopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -19,7 +19,7 @@
description: undefined,
url: undefined,
logoUrl: undefined,
accountId: undefined,
accountAddress: undefined,
}

let {
Expand All @@ -31,7 +31,7 @@
description,
url,
logoUrl,
accountId,
accountAddress,
} = $mintTokenDetails ?? DEFAULT

let nameError: string = ''
Expand All @@ -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
Expand All @@ -64,7 +64,7 @@
description,
url,
logoUrl,
accountId,
accountAddress,
}
if (valid && isEverythingDefined(tokenDetailsForm)) {
setMintTokenDetails(tokenDetailsForm)
Expand All @@ -82,7 +82,7 @@
form.circulatingSupply !== undefined &&
form.decimals !== undefined &&
form.symbol !== undefined &&
form.accountId !== undefined
form.accountAddress !== undefined
)
}

Expand Down Expand Up @@ -170,12 +170,12 @@
</script>

<div class="space-y-6">
<Text type="h4" fontSize="18" lineHeight="6" fontWeight={FontWeight.semibold}>
<Text type={TextType.h4} fontSize="18" lineHeight="6" fontWeight={FontWeight.semibold}>
{localize('popups.nativeToken.formTitle')}
</Text>

<div class="space-y-4 max-h-100 scrollable-y flex-1">
<AccountInput bind:this={accountInput} bind:account={accountId} bind:error={accountIdError} />
<AccountInput bind:this={accountInput} bind:account={accountAddress} bind:error={accountAddressError} />
<TextInput
bind:value={tokenName}
label={localize('popups.nativeToken.property.tokenName')}
Expand Down Expand Up @@ -212,25 +212,25 @@
maxlength={MAX_SUPPORTED_DECIMALS}
label={localize('popups.nativeToken.property.decimals')}
description={localize('tooltips.mintNativeToken.decimals')}
fontSize="14"
fontSize={14}
/>
<OptionalInput
bind:value={description}
label={localize('popups.nativeToken.property.description')}
description={localize('tooltips.mintNativeToken.description')}
fontSize="14"
fontSize={14}
/>
<OptionalInput
bind:value={url}
label={localize('popups.nativeToken.property.url')}
description={localize('tooltips.mintNativeToken.url')}
fontSize="14"
fontSize={14}
/>
<OptionalInput
bind:value={logoUrl}
label={localize('popups.nativeToken.property.logoUrl')}
description={localize('tooltips.mintNativeToken.logoUrl')}
fontSize="14"
fontSize={14}
/>
</optional-inputs>
{#if error}
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/features/developer-tools.features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const developerToolsFeatures: IDeveloperFeatures = {
enabled: true,
},
mintNativeTokens: {
enabled: false,
enabled: true,
},
account: {
enabled: false,
Expand Down
6 changes: 3 additions & 3 deletions packages/shared/components/inputs/AccountInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/components/inputs/OptionalInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion packages/shared/lib/core/nfts/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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'

Expand All @@ -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',
}),
]
Expand Down
10 changes: 3 additions & 7 deletions packages/shared/lib/core/wallet/actions/mintNft.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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<void> {
try {
Expand All @@ -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)),
}),
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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())
Expand Down
16 changes: 5 additions & 11 deletions packages/shared/lib/core/wallet/actions/prepareMintNft.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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)),
}),
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const DEFAULT_METADATA_FEATURE_ENTRY_KEY = 'data'
1 change: 1 addition & 0 deletions packages/shared/lib/core/wallet/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export interface IMintTokenDetails {
description?: string
url?: string
logoUrl?: string
accountId: string
accountAddress: string
}
20 changes: 10 additions & 10 deletions packages/shared/lib/core/wallet/utils/buildFoundryOutputData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<FoundryOutputBuilderParams> {
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 {
Expand Down
6 changes: 3 additions & 3 deletions packages/shared/lib/core/wallet/utils/buildNftOutputData.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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]
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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]
}
Loading
Loading