diff --git a/packages/shared/lib/core/account/interfaces/account.interface.ts b/packages/shared/lib/core/account/interfaces/account.interface.ts index 8b58e7d741c..bf0cff6c634 100644 --- a/packages/shared/lib/core/account/interfaces/account.interface.ts +++ b/packages/shared/lib/core/account/interfaces/account.interface.ts @@ -40,12 +40,13 @@ import type { FoundryOutputBuilderParams, NftOutputBuilderParams, INode, + AccountAddress, } from '@iota/wallet/out/types' import { ParticipationEventType } from '@iota/wallet/out/types' export interface IAccount { - addresses(): Promise + addresses(): Promise addressesWithUnspentOutputs(): Promise buildAliasOutput(data: AliasOutputBuilderParams): Promise buildBasicOutput(data: BasicOutputBuilderParams): Promise @@ -124,4 +125,5 @@ export interface IAccount { vote(eventId?: string, answers?: number[]): Promise verifyEd25519Signature(signature: Ed25519Signature, message: HexEncodedString): Promise verifySecp256k1EcdsaSignature(signature: Secp256k1EcdsaSignature, message: HexEncodedString): Promise + minimumRequiredStorageDeposit(output: Output): Promise } diff --git a/packages/shared/lib/core/nfts/actions/loadNftsForActiveProfile.ts b/packages/shared/lib/core/nfts/actions/loadNftsForActiveProfile.ts index f79d0b61a04..fac08a18912 100644 --- a/packages/shared/lib/core/nfts/actions/loadNftsForActiveProfile.ts +++ b/packages/shared/lib/core/nfts/actions/loadNftsForActiveProfile.ts @@ -7,6 +7,7 @@ import { OUTPUT_TYPE_NFT } from '../../wallet/constants' import { INft } from '../interfaces' import { buildNftFromNftOutput } from '../utils' import { setAccountNftsInAllAccountNfts } from './setAccountNftsInAllAccountNfts' +import { NftOutput } from '@iota/wallet/out/types' export async function loadNftsForActiveProfile(): Promise { const allAccounts = get(activeAccounts) @@ -31,7 +32,8 @@ async function loadNftsForAccount(account: IAccountState): Promise { .sort((a, b) => b.metadata.milestoneTimestampBooked - a.metadata.milestoneTimestampBooked) for (const outputData of sortedNftOutputs) { if (outputData.output.type === OUTPUT_TYPE_NFT) { - const nftId = getNftId(outputData.output.nftId, outputData.outputId) + const nftOutput = outputData.output as NftOutput + const nftId = getNftId(nftOutput.nftId, outputData.outputId) if (!accountNfts.some((nft) => nft.id === nftId)) { const nft = buildNftFromNftOutput(outputData as IWrappedOutput, account.depositAddress, false) accountNfts.push(nft) diff --git a/packages/shared/lib/core/nfts/utils/buildNftFromNftOutput.ts b/packages/shared/lib/core/nfts/utils/buildNftFromNftOutput.ts index dba3eb07ba4..ce577988f79 100644 --- a/packages/shared/lib/core/nfts/utils/buildNftFromNftOutput.ts +++ b/packages/shared/lib/core/nfts/utils/buildNftFromNftOutput.ts @@ -13,7 +13,7 @@ import { parseNftMetadata } from './parseNftMetadata' import { composeUrlFromNftUri } from './composeUrlFromNftUri' import { getSpendableStatusFromUnspentNftOutput } from './getSpendableStatusFromUnspentNftOutput' import { ADDRESS_TYPE_NFT } from '@core/wallet/constants' -import { NftOutput } from '@iota/wallet/out/types' +import { Address, NftOutput } from '@iota/wallet/out/types' export function buildNftFromNftOutput( wrappedOutput: IWrappedOutput, @@ -32,11 +32,11 @@ export function buildNftFromNftOutput( } const id = getNftId(nftOutput.getNftId(), wrappedOutput.outputId) - const address = getBech32AddressFromAddressTypes({ type: ADDRESS_TYPE_NFT, nftId: id }) + const address = getBech32AddressFromAddressTypes({ type: ADDRESS_TYPE_NFT, nftId: id } as unknown as Address) const issuer = getIssuerFromNftOutput(nftOutput) const metadata = getMetadataFromNftOutput(nftOutput) const parsedMetadata = parseNftMetadata(metadata) - const composedUrl = composeUrlFromNftUri(parsedMetadata?.uri) + const composedUrl = composeUrlFromNftUri(parsedMetadata.uri) const filePath = `${get(activeProfileId)}/nfts/${id}` const storageDeposit = Number(nftOutput.amount) diff --git a/packages/shared/lib/core/profile-manager/actions/events-handlers/handleNewOutputEvent.ts b/packages/shared/lib/core/profile-manager/actions/events-handlers/handleNewOutputEvent.ts index d005603a5c3..bcfa178bbc3 100644 --- a/packages/shared/lib/core/profile-manager/actions/events-handlers/handleNewOutputEvent.ts +++ b/packages/shared/lib/core/profile-manager/actions/events-handlers/handleNewOutputEvent.ts @@ -1,4 +1,4 @@ -import { Event, NewOutputWalletEvent } from '@iota/wallet/out/types' +import { AliasOutput, Event, NewOutputWalletEvent } from '@iota/wallet/out/types' import { WalletEventType } from '@iota/wallet/out/types' import { syncBalance } from '@core/account/actions/syncBalance' @@ -32,34 +32,39 @@ export function handleNewOutputEvent(error: Error, rawEvent: Event): void { export async function handleNewOutputEventInternal(accountIndex: number, payload: NewOutputWalletEvent): Promise { const account = get(activeAccounts)?.find((account) => account.index === accountIndex) - const output = payload.output + const outputData = payload.output - if (!account || !output) return + if (!account || !outputData) return - const address = getBech32AddressFromAddressTypes(output?.address) + const output = outputData.output as AliasOutput + + const address = getBech32AddressFromAddressTypes(outputData?.address) const isNewAliasOutput = - output.output.type === OUTPUT_TYPE_ALIAS && - output.output.stateIndex === 0 && - !get(allAccountActivities)[accountIndex].find((_activity) => _activity.id === output.outputId) - const isNftOutput = output.output.type === OUTPUT_TYPE_NFT + output.type === OUTPUT_TYPE_ALIAS && + output.stateIndex === 0 && + !get(allAccountActivities)[accountIndex].find((_activity) => _activity.id === outputData.outputId) + const isNftOutput = outputData.output.type === OUTPUT_TYPE_NFT - if ((account?.depositAddress === address && !output?.remainder) || isNewAliasOutput) { + if ((account?.depositAddress === address && !outputData?.remainder) || isNewAliasOutput) { await syncBalance(account.index) - const processedOutput = preprocessGroupedOutputs([output], payload?.transactionInputs ?? [], account) + const processedOutput = preprocessGroupedOutputs([outputData], payload?.transactionInputs ?? [], account) const activities = await generateActivities(processedOutput, account) for (const activity of activities) { if (activity.type === ActivityType.Basic || activity.type === ActivityType.Foundry) { const asset = await getOrRequestAssetFromPersistedAssets(activity.assetId) - addPersistedAsset(asset) + if (asset) { + addPersistedAsset(asset) + } } } addActivitiesToAccountActivitiesInAllAccountActivities(account.index, activities) } if (isNftOutput) { - const nft = buildNftFromNftOutput(output as IWrappedOutput, account.depositAddress) + const wrappedOutput = outputData.output as unknown as IWrappedOutput + const nft = buildNftFromNftOutput(wrappedOutput, account.depositAddress) addOrUpdateNftInAllAccountNfts(account.index, nft) void addNftsToDownloadQueue(accountIndex, [nft]) diff --git a/packages/shared/lib/core/wallet/utils/generateActivity/generateSingleBasicActivity.ts b/packages/shared/lib/core/wallet/utils/generateActivity/generateSingleBasicActivity.ts index 98a469e65d7..cd62a38ded1 100644 --- a/packages/shared/lib/core/wallet/utils/generateActivity/generateSingleBasicActivity.ts +++ b/packages/shared/lib/core/wallet/utils/generateActivity/generateSingleBasicActivity.ts @@ -52,7 +52,7 @@ export async function generateSingleBasicActivity( const baseTokenAmount = getAmountFromOutput(output) - storageDeposit - gasBudget - const nativeToken = getNativeTokenFromOutput(output) + const nativeToken = await getNativeTokenFromOutput(output) const assetId = fallbackAssetId ?? nativeToken?.id ?? getCoinType() let surplus: number | undefined = undefined diff --git a/packages/shared/lib/core/wallet/utils/generateActivity/generateSingleFoundryActivity.ts b/packages/shared/lib/core/wallet/utils/generateActivity/generateSingleFoundryActivity.ts index ef752e6ab80..e636ab1a77b 100644 --- a/packages/shared/lib/core/wallet/utils/generateActivity/generateSingleFoundryActivity.ts +++ b/packages/shared/lib/core/wallet/utils/generateActivity/generateSingleFoundryActivity.ts @@ -44,7 +44,7 @@ export async function generateSingleFoundryActivity( const containsValue = true const id = outputId || transactionId - const nativeToken = getNativeTokenFromOutput(output) + const nativeToken = await getNativeTokenFromOutput(output) const assetId = nativeToken?.id ?? getCoinType() const storageDeposit = getAmountFromOutput(output) diff --git a/packages/shared/lib/core/wallet/utils/generateActivity/helper/getLayer2ActivityInformation.ts b/packages/shared/lib/core/wallet/utils/generateActivity/helper/getLayer2ActivityInformation.ts index b9e422605b5..37ffb119579 100644 --- a/packages/shared/lib/core/wallet/utils/generateActivity/helper/getLayer2ActivityInformation.ts +++ b/packages/shared/lib/core/wallet/utils/generateActivity/helper/getLayer2ActivityInformation.ts @@ -14,7 +14,7 @@ export function getLayer2ActivityInformation( try { parsedLayer2Metadata = parseLayer2Metadata(metadata) destinationNetwork = getDestinationNetworkFromAddress( - sendingInfo.subject.type === 'address' ? sendingInfo.subject.address : undefined + sendingInfo.subject?.type === 'address' ? sendingInfo.subject.address : undefined ) } catch (_err) { parsedLayer2Metadata = null diff --git a/packages/shared/lib/core/wallet/utils/generateActivity/helper/getSendingInformation.ts b/packages/shared/lib/core/wallet/utils/generateActivity/helper/getSendingInformation.ts index 3935b245b3e..224adf3bddb 100644 --- a/packages/shared/lib/core/wallet/utils/generateActivity/helper/getSendingInformation.ts +++ b/packages/shared/lib/core/wallet/utils/generateActivity/helper/getSendingInformation.ts @@ -6,11 +6,11 @@ import { getSubjectFromAddress } from '../../getSubjectFromAddress' import { isSubjectInternal } from '../../isSubjectInternal' import { getRecipientFromOutput } from '../../outputs' import { getSenderAddressFromInputs, getSenderFromTransaction } from '../../transactions' -import { Output } from '@iota/wallet/out/types' +import { CommonOutput } from '@iota/wallet/out/types' export function getSendingInformation( processedTransaction: IProcessedTransaction, - output: Output, + output: CommonOutput, account: IAccountState ): SenderInfo { const { direction, wrappedInputs } = processedTransaction diff --git a/packages/shared/lib/core/wallet/utils/outputs/getNativeTokenFromOutput.ts b/packages/shared/lib/core/wallet/utils/outputs/getNativeTokenFromOutput.ts index 5426c553199..77fbd0e9477 100644 --- a/packages/shared/lib/core/wallet/utils/outputs/getNativeTokenFromOutput.ts +++ b/packages/shared/lib/core/wallet/utils/outputs/getNativeTokenFromOutput.ts @@ -2,11 +2,11 @@ import { buildFoundryId } from './getFoundryId' import type { CommonOutput, FoundryOutput, INativeToken, SimpleTokenScheme } from '@iota/wallet/out/types' import { OutputType } from '@iota/wallet/out/types' -export function getNativeTokenFromOutput(output: CommonOutput): INativeToken | undefined { +export async function getNativeTokenFromOutput(output: CommonOutput): Promise { if (output?.type === OutputType.Foundry) { const foundryOutput = output as FoundryOutput return { - id: buildFoundryId(output as FoundryOutput), + id: await buildFoundryId(output as FoundryOutput), amount: (foundryOutput.tokenScheme as SimpleTokenScheme).mintedTokens, } } diff --git a/packages/shared/lib/core/wallet/utils/outputs/getRecipientAddressFromOutput.ts b/packages/shared/lib/core/wallet/utils/outputs/getRecipientAddressFromOutput.ts index 2ac767295d3..f349a45dadb 100644 --- a/packages/shared/lib/core/wallet/utils/outputs/getRecipientAddressFromOutput.ts +++ b/packages/shared/lib/core/wallet/utils/outputs/getRecipientAddressFromOutput.ts @@ -1,11 +1,12 @@ +import { AddressUnlockCondition, CommonOutput } from '@iota/wallet/out/types' import { UNLOCK_CONDITION_ADDRESS } from '../../constants' -import { Output } from '../../types' import { getBech32AddressFromAddressTypes } from '../getBech32AddressFromAddressTypes' -export function getRecipientAddressFromOutput(output: Output): string { +export function getRecipientAddressFromOutput(output: CommonOutput): string | undefined { for (const unlockCondition of output.unlockConditions) { if (unlockCondition.type === UNLOCK_CONDITION_ADDRESS) { - return getBech32AddressFromAddressTypes(unlockCondition.address) + const addressUnlockCondition = unlockCondition as AddressUnlockCondition + return getBech32AddressFromAddressTypes(addressUnlockCondition.address) } } } diff --git a/packages/shared/lib/core/wallet/utils/outputs/getRecipientFromOutput.ts b/packages/shared/lib/core/wallet/utils/outputs/getRecipientFromOutput.ts index 080a786d34f..75090b954db 100644 --- a/packages/shared/lib/core/wallet/utils/outputs/getRecipientFromOutput.ts +++ b/packages/shared/lib/core/wallet/utils/outputs/getRecipientFromOutput.ts @@ -1,8 +1,11 @@ import { getRecipientAddressFromOutput } from './getRecipientAddressFromOutput' -import { Output, Subject } from '../../types' +import { Subject } from '../../types' import { getSubjectFromAddress } from '../getSubjectFromAddress' +import { CommonOutput } from '@iota/wallet' -export function getRecipientFromOutput(output: Output): Subject { +export function getRecipientFromOutput(output: CommonOutput): Subject | undefined { const recipientAddress = getRecipientAddressFromOutput(output) - return getSubjectFromAddress(recipientAddress) + if (recipientAddress) { + return getSubjectFromAddress(recipientAddress) + } } diff --git a/packages/shared/lib/core/wallet/utils/outputs/getSenderFromOutput.ts b/packages/shared/lib/core/wallet/utils/outputs/getSenderFromOutput.ts index 916b27d45dd..c6eabe54fe0 100644 --- a/packages/shared/lib/core/wallet/utils/outputs/getSenderFromOutput.ts +++ b/packages/shared/lib/core/wallet/utils/outputs/getSenderFromOutput.ts @@ -1,15 +1,22 @@ -import { Output, Subject } from '../../types' +import { Subject } from '../../types' import { getBech32AddressFromAddressTypes } from '../getBech32AddressFromAddressTypes' import { UNLOCK_CONDITION_EXPIRATION, UNLOCK_CONDITION_STORAGE_DEPOSIT_RETURN } from '@core/wallet/constants' import { getSubjectFromAddress } from '../getSubjectFromAddress' +import { CommonOutput, ExpirationUnlockCondition, StorageDepositReturnUnlockCondition } from '@iota/wallet' -export function getSenderFromOutput(output: Output): Subject | undefined { +export function getSenderFromOutput(output: CommonOutput): Subject | undefined { for (const unlockCondition of output.unlockConditions) { if ( unlockCondition?.type === UNLOCK_CONDITION_STORAGE_DEPOSIT_RETURN || unlockCondition?.type === UNLOCK_CONDITION_EXPIRATION ) { - return getSubjectFromAddress(getBech32AddressFromAddressTypes(unlockCondition?.returnAddress)) + const storageOrExpirationUnlockCondition = unlockCondition as + | StorageDepositReturnUnlockCondition + | ExpirationUnlockCondition + const address = getBech32AddressFromAddressTypes(storageOrExpirationUnlockCondition?.returnAddress) + if (address) { + return getSubjectFromAddress(address) + } } } } diff --git a/packages/shared/lib/core/wallet/utils/outputs/preprocessGroupedOutputs.ts b/packages/shared/lib/core/wallet/utils/outputs/preprocessGroupedOutputs.ts index 5ee9c750646..935649daa51 100644 --- a/packages/shared/lib/core/wallet/utils/outputs/preprocessGroupedOutputs.ts +++ b/packages/shared/lib/core/wallet/utils/outputs/preprocessGroupedOutputs.ts @@ -83,12 +83,7 @@ function convertTransactionOutputResponseToWrappedOutput( } function getUtxoInputsFromWrappedInputs(wrappedInputs: IWrappedOutput[]): UTXOInput[] { - // TODO-sdk This won't work probably return ( - wrappedInputs?.map((input) => ({ - type: 0, - transactionId: input.metadata?.transactionId, - transactionInputIndex: input.metadata?.outputIndex, - })) ?? [] + wrappedInputs?.map((input) => new UTXOInput(input.metadata?.transactionId, input.metadata?.outputIndex)) ?? [] ) } diff --git a/packages/shared/lib/core/wallet/utils/send/validateSendConfirmation.ts b/packages/shared/lib/core/wallet/utils/send/validateSendConfirmation.ts index 7ebc709daa1..5e7df9aa4f7 100644 --- a/packages/shared/lib/core/wallet/utils/send/validateSendConfirmation.ts +++ b/packages/shared/lib/core/wallet/utils/send/validateSendConfirmation.ts @@ -6,9 +6,9 @@ import { IAccountState } from '@core/account/interfaces' import { CommonOutput, ExpirationUnlockCondition, OutputType, UnlockConditionType } from '@iota/wallet/out/types' export async function validateSendConfirmation(account: IAccountState, output: CommonOutput): Promise { - const parseNumber: (value: string) => number = (value: string) => parseInt(value, 10) ?? 0 + const parseNumber = (value: string) => parseInt(value, 10) ?? 0 const amount = parseNumber(output?.amount) - const balance = parseNumber(getSelectedAccount()?.balances?.baseCoin.available ?? '0') + const balance = parseNumber(getSelectedAccount()?.balances?.baseCoin.available.toString() ?? '0') const { storageDeposit, giftedStorageDeposit } = await getStorageDepositFromOutput(account, output) const expirationUnlockCondition = output.unlockConditions.find( diff --git a/packages/shared/lib/core/wallet/utils/transactions/activityOutputContainsValue.ts b/packages/shared/lib/core/wallet/utils/transactions/activityOutputContainsValue.ts index 9549640acaf..ed4d7d32045 100644 --- a/packages/shared/lib/core/wallet/utils/transactions/activityOutputContainsValue.ts +++ b/packages/shared/lib/core/wallet/utils/transactions/activityOutputContainsValue.ts @@ -15,7 +15,7 @@ export async function activityOutputContainsValue( const output = wrappedOutput.output as BasicOutput const isAsync = isOutputAsync(output) - const nativeToken = getNativeTokenFromOutput(output) + const nativeToken = await getNativeTokenFromOutput(output) const { storageDeposit } = await getStorageDepositFromOutput(account, output) const rawAmount = getAmountFromOutput(output) - storageDeposit diff --git a/packages/shared/lib/core/wallet/utils/transactions/getSenderFromTransaction.ts b/packages/shared/lib/core/wallet/utils/transactions/getSenderFromTransaction.ts index 2697301f213..41405058b1e 100644 --- a/packages/shared/lib/core/wallet/utils/transactions/getSenderFromTransaction.ts +++ b/packages/shared/lib/core/wallet/utils/transactions/getSenderFromTransaction.ts @@ -1,10 +1,11 @@ -import { Output, Subject } from '@core/wallet/types' +import { Subject } from '@core/wallet/types' +import { CommonOutput } from '@iota/wallet' import { getSenderFromOutput } from '../outputs/getSenderFromOutput' export function getSenderFromTransaction( isIncoming: boolean, accountAddress: string, - output: Output + output: CommonOutput ): Subject | undefined { if (isIncoming) { return getSenderFromOutput(output)