From e806be8f37f6e12a315dad67bde819f44a416056 Mon Sep 17 00:00:00 2001 From: Marc Espin Date: Thu, 28 Mar 2024 17:21:34 +0100 Subject: [PATCH] fix: Receive funds to implicit account address (#8260) 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 * fix: tx history: include account output in average txs * fix: Fix incorrect timestamp in Incoming txs * fix: Receive funds to implicit account address * feat: add mana to txs in tx activities and activity details (#8263) Co-authored-by: Marc Espin Co-authored-by: Begoña Álvarez de la Cruz * Revert "feat: add mana to txs in tx activities and activity details (#8263)" (#8277) This reverts commit e9e832bff4cddc7db8d870d5b6f392b8caccb64e. --------- Co-authored-by: cpl121 Co-authored-by: cpl121 <100352899+cpl121@users.noreply.github.com> Co-authored-by: Begoña Álvarez de la Cruz --- .../generateActivity/generateActivities.ts | 10 ++++++++-- .../generateActivitiesFromBasicOutputs.ts | 2 +- .../outputs/preprocessIncomingTransaction.ts | 18 ++++++++---------- ...tNonRemainderBasicOutputsFromTransaction.ts | 6 +++--- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/packages/shared/lib/core/wallet/utils/generateActivity/generateActivities.ts b/packages/shared/lib/core/wallet/utils/generateActivity/generateActivities.ts index 7e54cc2ce2c..69f1ac2375e 100644 --- a/packages/shared/lib/core/wallet/utils/generateActivity/generateActivities.ts +++ b/packages/shared/lib/core/wallet/utils/generateActivity/generateActivities.ts @@ -1,5 +1,5 @@ import { IWalletState } from '@core/wallet/interfaces' -import { ActivityAction, ActivityType, IProcessedTransaction } from '@core/wallet' +import { ActivityAction, ActivityType, IProcessedTransaction, getSenderAddressFromInputs } from '@core/wallet' import { Activity } from '@core/wallet/types' import { isParticipationOutput } from '@contexts/governance/utils' import { generateSingleAccountActivity } from './generateSingleAccountActivity' @@ -33,6 +33,8 @@ async function generateActivitiesFromProcessedTransactionsWithInputs( wallet: IWalletState ): Promise { const { outputs, wrappedInputs } = processedTransaction + const sender = getSenderAddressFromInputs(wrappedInputs) + const isSentToImplicitAccountCreationAddress = sender === (await wallet.implicitAccountCreationAddress()) const activities: Activity[] = [] const containsFoundryActivity = outputs.some((output) => output.output.type === OutputType.Foundry) @@ -75,7 +77,11 @@ async function generateActivitiesFromProcessedTransactionsWithInputs( const anchorActivities = await generateActivitiesFromAnchorOutputs(processedTransaction, wallet) activities.push(...anchorActivities) } - if (!containsFoundryActivity && !containsNftActivity && !containsAccountActivity && !governanceOutput) { + + if ( + (!containsFoundryActivity && !containsNftActivity && !containsAccountActivity && !governanceOutput) || + isSentToImplicitAccountCreationAddress + ) { const basicActivities = await generateActivitiesFromBasicOutputs(processedTransaction, wallet) activities.push(...basicActivities) } diff --git a/packages/shared/lib/core/wallet/utils/generateActivity/generateActivitiesFromBasicOutputs.ts b/packages/shared/lib/core/wallet/utils/generateActivity/generateActivitiesFromBasicOutputs.ts index 2554635b9d4..2dcd8d34649 100644 --- a/packages/shared/lib/core/wallet/utils/generateActivity/generateActivitiesFromBasicOutputs.ts +++ b/packages/shared/lib/core/wallet/utils/generateActivity/generateActivitiesFromBasicOutputs.ts @@ -23,7 +23,7 @@ export async function generateActivitiesFromBasicOutputs( const basicOutputs = getNonRemainderBasicOutputsFromTransaction( processedTransaction.outputs, - wallet.depositAddress, + [wallet.depositAddress, await wallet.implicitAccountCreationAddress()], processedTransaction.direction ) const burnedNftInputs = getBurnedNftInputs(processedTransaction) diff --git a/packages/shared/lib/core/wallet/utils/outputs/preprocessIncomingTransaction.ts b/packages/shared/lib/core/wallet/utils/outputs/preprocessIncomingTransaction.ts index 36ca70ac4cb..fc4037b45c1 100644 --- a/packages/shared/lib/core/wallet/utils/outputs/preprocessIncomingTransaction.ts +++ b/packages/shared/lib/core/wallet/utils/outputs/preprocessIncomingTransaction.ts @@ -1,6 +1,5 @@ import { IProcessedTransaction, IWrappedOutput } from '../../interfaces' import { Output, OutputType, OutputWithMetadata, TransactionWithMetadata, UTXOInput } from '@iota/sdk/out/types' -// import { computeOutputId } from './computeOutputId' import { getOutputIdFromTransactionIdAndIndex } from './getOutputIdFromTransactionIdAndIndex' import { ActivityDirection } from '../../enums' import { getUnixTimestampFromNodeInfoAndSlotIndex, nodeInfoProtocolParameters } from '@core/network' @@ -18,21 +17,20 @@ export function preprocessIncomingTransaction(transaction: TransactionWithMetada const outputs = convertTransactionsOutputTypesToWrappedOutputs(transactionId, regularTransactionEssence.outputs) const utxoInputs = regularTransactionEssence.inputs.map((i) => i as UTXOInput) - // const inputIds = utxoInputs.map((input) => { - // const transactionId = input.transactionId - // const transactionOutputIndex = input.transactionOutputIndex - // return computeOutputId(transactionId, transactionOutputIndex) - // }) - // const inputs = await Promise.all(inputIds.map((inputId) => wallet.getOutput(inputId))) + const inputs = transaction.inputs.map((input) => ({ + output: input.output, + outputId: input.metadata.outputId, + metadata: input.metadata, + remainder: true, + })) return { - outputs: outputs, + outputs, transactionId, direction: ActivityDirection.Incoming, time: new Date(slotUnixTimestamp * MILLISECONDS_PER_SECOND), inclusionState: transaction.inclusionState, - wrappedInputs: [], - // wrappedInputs: inputs, + wrappedInputs: inputs, utxoInputs, } } diff --git a/packages/shared/lib/core/wallet/utils/transactions/getNonRemainderBasicOutputsFromTransaction.ts b/packages/shared/lib/core/wallet/utils/transactions/getNonRemainderBasicOutputsFromTransaction.ts index 31ae0147492..e5e78d0dfe3 100644 --- a/packages/shared/lib/core/wallet/utils/transactions/getNonRemainderBasicOutputsFromTransaction.ts +++ b/packages/shared/lib/core/wallet/utils/transactions/getNonRemainderBasicOutputsFromTransaction.ts @@ -5,16 +5,16 @@ import { CommonOutput } from '@iota/sdk/out/types' export function getNonRemainderBasicOutputsFromTransaction( wrappedOutputs: IWrappedOutput[], - walletDepositAddress: string, + validAddresses: string[], direction: ActivityDirection ): IWrappedOutput[] { return wrappedOutputs.filter((outputData) => { const recipientAddress = getRecipientAddressFromOutput(outputData.output as CommonOutput) if (direction === ActivityDirection.Incoming || direction === ActivityDirection.SelfTransaction) { - return !outputData.remainder && walletDepositAddress === recipientAddress + return !outputData.remainder && validAddresses.includes(recipientAddress) } else { - return walletDepositAddress !== recipientAddress + return !validAddresses.includes(recipientAddress) } }) }