diff --git a/packages/shared/lib/core/wallet/actions/activities/linkTransactionsWithClaimingTransactions.ts b/packages/shared/lib/core/wallet/actions/activities/linkTransactionsWithClaimingTransactions.ts index d55edcb912e..842ff5b7470 100644 --- a/packages/shared/lib/core/wallet/actions/activities/linkTransactionsWithClaimingTransactions.ts +++ b/packages/shared/lib/core/wallet/actions/activities/linkTransactionsWithClaimingTransactions.ts @@ -1,6 +1,6 @@ import { IWalletState } from '@core/wallet/interfaces' import { activeProfileId } from '@core/profile' -import { ActivityDirection, IProcessedTransaction } from '@core/wallet' +import { ActivityDirection, IClaimedActivities, IProcessedTransaction } from '@core/wallet' import { isOutputAsync } from '@core/wallet/utils/outputs/isOutputAsync' import { get } from 'svelte/store' import { addClaimedActivity, claimedActivities } from '../../stores' @@ -17,9 +17,11 @@ export function linkTransactionsWithClaimingTransactions( wallet: IWalletState ): IProcessedTransaction[] { const resultingTransactions = [] - const transactionsIncludedAsClaimingTransactions = [] + const transactionsIncludedAsClaimingTransactions: string[] = [] + + const claimedWalletActivities: { [transactionId: string]: IClaimedActivities } = + get(claimedActivities)?.[get(activeProfileId)]?.[wallet.id] - const claimedWalletActivities = get(claimedActivities)?.[get(activeProfileId)]?.[wallet.id] const sortedTransactions = transactions.sort((t1, t2) => (t1.time > t2.time ? 1 : -1)) const incomingAsyncTransactions: IProcessedTransaction[] = [] for (const transaction of sortedTransactions) { @@ -28,13 +30,12 @@ export function linkTransactionsWithClaimingTransactions( transaction.outputs.some((_output) => isOutputAsync(_output.output)) && (transaction.direction === ActivityDirection.Incoming || transaction.direction === ActivityDirection.SelfTransaction) - if (isClaimingTransaction) { continue } else if (isIncomingAsyncTransaction) { // If we have the corresponding claiming transaction cached in local storage, we get that data and update the async transaction const claimedActivity = claimedWalletActivities?.[transaction?.transactionId] - if (claimedActivity && claimedActivity.claimingTransactionId === transaction?.transactionId) { + if (claimedActivity) { const claimingData = { claimedDate: new Date(claimedActivity.claimedTimestamp), claimingTransactionId: claimedActivity.claimingTransactionId, @@ -72,14 +73,13 @@ export function linkTransactionsWithClaimingTransactions( } } } - return resultingTransactions } function searchClaimedTransactionInIncomingAsyncTransactions( allAsyncTransaction: IProcessedTransaction[], transaction: IProcessedTransaction -): IProcessedTransaction { +): IProcessedTransaction | undefined { return allAsyncTransaction.find((candidate) => transaction.utxoInputs?.some((input) => input?.transactionId === candidate?.transactionId) ) diff --git a/packages/shared/lib/core/wallet/actions/events-handlers/handleNewOutputEvent.ts b/packages/shared/lib/core/wallet/actions/events-handlers/handleNewOutputEvent.ts index 57842b0b330..5e6ea9b6dca 100644 --- a/packages/shared/lib/core/wallet/actions/events-handlers/handleNewOutputEvent.ts +++ b/packages/shared/lib/core/wallet/actions/events-handlers/handleNewOutputEvent.ts @@ -2,21 +2,16 @@ import { addNftsToDownloadQueue, addOrUpdateNftInAllWalletNfts, buildNftFromNftO import { activeWallets, updateActiveWallet } from '@core/profile' import { checkAndRemoveProfilePicture, updateActiveWalletPersistedData } from '@core/profile/actions' import { - ActivityType, IWrappedOutput, WalletApiEventHandler, - addActivitiesToWalletActivitiesInAllWalletActivities, - addPersistedAsset, - generateActivities, AddressConverter, - getOrRequestAssetFromPersistedAssets, hasBlockIssuerFeature, isAccountOutput, isDelegationOutput, isImplicitAccountOutput, - preprocessGroupedOutputs, syncBalance, validateWalletApiEvent, + generateAndStoreActivitiesForWallet, } from '@core/wallet' import { AccountAddress, @@ -64,18 +59,7 @@ export async function handleNewOutputEventInternal(walletId: string, payload: Ne const accountOutputs = await wallet.accounts() updateActiveWallet(wallet.id, { walletOutputs, accountOutputs, walletUnspentOutputs }) - const processedOutput = preprocessGroupedOutputs([outputData], payload?.transactionInputs ?? [], wallet) - - const activities = await generateActivities(processedOutput, wallet) - for (const activity of activities) { - if (activity.type === ActivityType.Basic || activity.type === ActivityType.Foundry) { - const asset = await getOrRequestAssetFromPersistedAssets(activity.assetId) - if (asset) { - addPersistedAsset(asset) - } - } - } - addActivitiesToWalletActivitiesInAllWalletActivities(wallet.id, activities) + await generateAndStoreActivitiesForWallet(wallet) } if (isImplicitAccountOutput(outputData)) { await syncBalance(wallet.id, true) diff --git a/packages/shared/lib/core/wallet/actions/events-handlers/handleSpentOutputEvent.ts b/packages/shared/lib/core/wallet/actions/events-handlers/handleSpentOutputEvent.ts index f610af6ce9b..be44235b34c 100644 --- a/packages/shared/lib/core/wallet/actions/events-handlers/handleSpentOutputEvent.ts +++ b/packages/shared/lib/core/wallet/actions/events-handlers/handleSpentOutputEvent.ts @@ -1,18 +1,12 @@ -import { getNftByIdFromAllWalletNfts, updateNftInAllWalletNfts } from '@core/nfts' import { activeWallets, updateActiveWallet } from '@core/profile' import { - ActivityAsyncStatus, - ActivityType, WalletApiEventHandler, - allWalletActivities, + generateAndStoreActivitiesForWallet, isDelegationOutput, syncBalance, - updateAsyncDataByTransactionId, validateWalletApiEvent, } from '@core/wallet' import { SpentOutputWalletEvent, WalletEvent, WalletEventType } from '@iota/sdk/out/types' -import { nodeInfoProtocolParameters } from '@core/network' -import { getUnixTimestampFromNodeInfoAndSlotIndex } from '@core/network/helpers/getSlotInfoFromNodeProtocolParameters' import { get } from 'svelte/store' import { closePopup } from 'shared/lib/auxiliary/popup' @@ -37,33 +31,8 @@ export async function handleSpentOutputEventInternal(walletId: string, payload: const walletUnspentOutputs = await wallet.unspentOutputs() const implicitAccountOutputs = await wallet.implicitAccounts() updateActiveWallet(walletId, { walletOutputs, accountOutputs, implicitAccountOutputs, walletUnspentOutputs }) - } - const outputId = output?.outputId - const activity = get(allWalletActivities)?.[walletId]?.find((_activity) => _activity.outputId === outputId) - if (activity && activity.asyncData?.asyncStatus === ActivityAsyncStatus.Unclaimed) { - const transactionId = output?.metadata?.included.transactionId - updateAsyncDataByTransactionId(walletId, transactionId, { - asyncStatus: ActivityAsyncStatus.Claimed, - }) - } - - if (activity?.type === ActivityType.Nft) { - const previousOutputId = getNftByIdFromAllWalletNfts(walletId, activity.nftId)?.latestOutputId - const protocolParameters = get(nodeInfoProtocolParameters) - if (!wallet || !previousOutputId || !protocolParameters) return - const previousOutput = await wallet.getOutput(previousOutputId) - const unixTimestampOutputMetadata = getUnixTimestampFromNodeInfoAndSlotIndex( - protocolParameters, - output.metadata.included.slot - ) - const unixTimestampPreviousOutputMetadata = getUnixTimestampFromNodeInfoAndSlotIndex( - protocolParameters, - previousOutput.metadata.included.slot - ) - if (unixTimestampOutputMetadata > unixTimestampPreviousOutputMetadata) { - updateNftInAllWalletNfts(walletId, activity.nftId, { isSpendable: false }) - } + await generateAndStoreActivitiesForWallet(wallet) } if (_isDelegationOutput && wallet?.hasDelegationRewardClaimTransactionInProgress) {