diff --git a/packages/shared/src/components/molecules/activity-info/GenericActivityInformation.svelte b/packages/shared/src/components/molecules/activity-info/GenericActivityInformation.svelte index a88c283cd6..adf10cc263 100644 --- a/packages/shared/src/components/molecules/activity-info/GenericActivityInformation.svelte +++ b/packages/shared/src/components/molecules/activity-info/GenericActivityInformation.svelte @@ -18,7 +18,7 @@ $: claimedTime = getFormattedTimeStamp(activity?.asyncData?.claimedDate) $: hasStorageDeposit = activity?.storageDeposit || (activity?.storageDeposit === 0 && activity?.giftedStorageDeposit === 0) - $: gasBudget = activity?.parsedLayer2Metadata?.gasBudget + $: gasBudget = activity?.gas ?? activity?.parsedLayer2Metadata?.gasBudget $: formattedTransactionTime = getFormattedTimeStamp(activity?.time) $: formattedTimelockDate = getFormattedTimeStamp(activity?.asyncData?.timelockDate) diff --git a/packages/shared/src/lib/core/activity/actions/generateAndStoreActivitiesForAccount.ts b/packages/shared/src/lib/core/activity/actions/generateAndStoreActivitiesForAccount.ts index 28524202b0..08185a920a 100644 --- a/packages/shared/src/lib/core/activity/actions/generateAndStoreActivitiesForAccount.ts +++ b/packages/shared/src/lib/core/activity/actions/generateAndStoreActivitiesForAccount.ts @@ -6,9 +6,10 @@ import { preprocessTransactionsForAccount } from './preprocessTransactionsForAcc import { preprocessOutputsForAccount } from './preprocessOutputsForAccount' import { linkTransactionsWithClaimingTransactions } from './linkTransactionsWithClaimingTransactions' import { hideActivitiesForFoundries } from './hideActivitiesForFoundries' -import { generateActivitiesFromProcessedTransactions } from './generateActivitiesFromProcessedTransactions' +import { generateActivitiesFromProcessedTransactions } from '../utils/generateActivitiesFromProcessedTransactions' import { loadAssetsForAllActivities } from './loadAssetsForAllAccounts' -import { generateActivitiesFromBalanceChanges, setOutgoingAsyncActivitiesToClaimed } from '@core/activity/actions' +import { setOutgoingAsyncActivitiesToClaimed } from '@core/activity/actions' +import { generateActivitiesFromBalanceChanges, generateActivitiesFromChains } from '../utils' export async function generateAndStoreActivitiesForAccount(account: IAccountState): Promise { // Step 1: process account transactions and outputs into processed transactions @@ -23,9 +24,11 @@ export async function generateAndStoreActivitiesForAccount(account: IAccountStat // Step 3: generate activities from processed transactions const activities = generateActivitiesFromProcessedTransactions(linkedProcessedTransactions, account) const balanceChangeActivities = generateActivitiesFromBalanceChanges(account) - activities.push(...balanceChangeActivities) + const chainActivities = await generateActivitiesFromChains(account) + activities.push(...chainActivities) + // Step 4: set account activities with generated activities setAccountActivitiesInAllAccountActivities(account.index, activities) diff --git a/packages/shared/src/lib/core/activity/actions/index.ts b/packages/shared/src/lib/core/activity/actions/index.ts index c38a675acf..746dadb3e5 100644 --- a/packages/shared/src/lib/core/activity/actions/index.ts +++ b/packages/shared/src/lib/core/activity/actions/index.ts @@ -1,5 +1,4 @@ export * from './calculateAndAddPersistedBalanceChange' -export * from './generateActivitiesFromBalanceChanges' export * from './generateAndStoreActivitiesForAccount' export * from './generateAndStoreActivitiesForAllAccounts' export * from './hideActivitiesForFoundries' diff --git a/packages/shared/src/lib/core/activity/stores/persisted-transactions.store.ts b/packages/shared/src/lib/core/activity/stores/persisted-transactions.store.ts index e3df476cbb..110a7b07aa 100644 --- a/packages/shared/src/lib/core/activity/stores/persisted-transactions.store.ts +++ b/packages/shared/src/lib/core/activity/stores/persisted-transactions.store.ts @@ -14,7 +14,7 @@ interface IPersistedEvmTransactions { export const persistedEvmTransactions = persistent('evmTransactions', {}) export function getPersistedEvmTransactions(accountIndex: number, chainId: string | number): PersistedEvmTransaction[] { - return get(persistedEvmTransactions)?.[get(activeProfileId)]?.[accountIndex]?.[chainId] + return get(persistedEvmTransactions)?.[get(activeProfileId)]?.[accountIndex]?.[chainId] ?? [] } export function addPersistedTransaction( diff --git a/packages/shared/src/lib/core/activity/types/base-activity.type.ts b/packages/shared/src/lib/core/activity/types/base-activity.type.ts index acadc84d49..699ed430d6 100644 --- a/packages/shared/src/lib/core/activity/types/base-activity.type.ts +++ b/packages/shared/src/lib/core/activity/types/base-activity.type.ts @@ -15,6 +15,7 @@ export type BaseActivity = { action: ActivityAction isInternal: boolean storageDeposit: number + gas?: number rawBaseCoinAmount?: number subject: Subject | undefined metadata?: string diff --git a/packages/shared/src/lib/core/activity/actions/generateActivitiesFromBalanceChanges.ts b/packages/shared/src/lib/core/activity/utils/generateActivitiesFromBalanceChanges.ts similarity index 92% rename from packages/shared/src/lib/core/activity/actions/generateActivitiesFromBalanceChanges.ts rename to packages/shared/src/lib/core/activity/utils/generateActivitiesFromBalanceChanges.ts index 7bae9b3b3e..fa76fa963a 100644 --- a/packages/shared/src/lib/core/activity/actions/generateActivitiesFromBalanceChanges.ts +++ b/packages/shared/src/lib/core/activity/utils/generateActivitiesFromBalanceChanges.ts @@ -3,7 +3,7 @@ import { Activity } from '../types' import { getBalanceChanges } from '../stores' import { get } from 'svelte/store' import { network } from '@core/network' -import { generateBalanceChangeActivity } from '../utils' +import { generateBalanceChangeActivity } from './generateBalanceChangeActivity' export function generateActivitiesFromBalanceChanges(account: IAccountState): Activity[] { const activities: Activity[] = [] diff --git a/packages/shared/src/lib/core/activity/utils/generateActivitiesFromChains.ts b/packages/shared/src/lib/core/activity/utils/generateActivitiesFromChains.ts new file mode 100644 index 0000000000..8a9f8bbc89 --- /dev/null +++ b/packages/shared/src/lib/core/activity/utils/generateActivitiesFromChains.ts @@ -0,0 +1,23 @@ +import { IAccountState } from '@core/account' +import { Activity } from '../types' +import { getPersistedEvmTransactions } from '../stores' +import { generateActivityFromEvmTransaction } from './generateActivityFromEvmTransaction' +import { get } from 'svelte/store' +import { network } from '@core/network' + +export async function generateActivitiesFromChains(account: IAccountState): Promise { + const activities: Activity[] = [] + + const chains = get(network)?.getChains() ?? [] + for (const chain of chains) { + const chainId = chain.getConfiguration().chainId + + const transactions = getPersistedEvmTransactions(account.index, chainId) + for (const transaction of transactions) { + const activity = await generateActivityFromEvmTransaction(transaction, chainId, chain.getProvider()) + activities.push(activity) + } + } + + return activities +} diff --git a/packages/shared/src/lib/core/activity/actions/generateActivitiesFromProcessedTransactions.ts b/packages/shared/src/lib/core/activity/utils/generateActivitiesFromProcessedTransactions.ts similarity index 92% rename from packages/shared/src/lib/core/activity/actions/generateActivitiesFromProcessedTransactions.ts rename to packages/shared/src/lib/core/activity/utils/generateActivitiesFromProcessedTransactions.ts index 1bc5983ac0..e51fc2970b 100644 --- a/packages/shared/src/lib/core/activity/actions/generateActivitiesFromProcessedTransactions.ts +++ b/packages/shared/src/lib/core/activity/utils/generateActivitiesFromProcessedTransactions.ts @@ -1,6 +1,6 @@ import { IAccountState } from '@core/account' import { Activity, IProcessedTransaction } from '../types' -import { generateActivities } from '../utils' +import { generateActivities } from '.' export function generateActivitiesFromProcessedTransactions( processedTransactions: IProcessedTransaction[], diff --git a/packages/shared/src/lib/core/activity/utils/generateActivityFromEvmTransaction.ts b/packages/shared/src/lib/core/activity/utils/generateActivityFromEvmTransaction.ts new file mode 100644 index 0000000000..9fdcb8ac82 --- /dev/null +++ b/packages/shared/src/lib/core/activity/utils/generateActivityFromEvmTransaction.ts @@ -0,0 +1,34 @@ +import { PersistedEvmTransaction, TransactionActivity } from '../types' +import { ActivityAction, ActivityDirection, ActivityType, InclusionState } from '../enums' +import { getCoinType } from '@core/profile/actions' +import { SubjectType } from '@core/wallet' +import { WEI_PER_GLOW } from '@core/layer-2' +import Web3 from 'web3' + +export async function generateActivityFromEvmTransaction( + transaction: PersistedEvmTransaction, + chainId: number, + provider: Web3 +): Promise { + const direction = ActivityDirection.Outgoing // Currently only sent transactions are supported + + const timestamp = (await provider.eth.getBlock(transaction.blockNumber)).timestamp + return { + type: ActivityType.Basic, + id: transaction.transactionHash, + time: new Date(Number(timestamp) * 1000), + inclusionState: InclusionState.Confirmed, + containsValue: true, + isAssetHidden: false, + direction, + action: ActivityAction.Send, + isInternal: false, + storageDeposit: 0, + gas: transaction.gasUsed, + subject: { type: SubjectType.Address, address: transaction.to }, + rawBaseCoinAmount: Number(transaction.value) / Number(WEI_PER_GLOW), + rawAmount: Number(transaction.value) / Number(WEI_PER_GLOW), + tokenId: getCoinType(), + chainId, + } +} diff --git a/packages/shared/src/lib/core/activity/utils/index.ts b/packages/shared/src/lib/core/activity/utils/index.ts index bb13a4f855..eba4c29621 100644 --- a/packages/shared/src/lib/core/activity/utils/index.ts +++ b/packages/shared/src/lib/core/activity/utils/index.ts @@ -1,9 +1,12 @@ export * from './activityOutputContainsValue' export * from './generateActivities' export * from './generateActivitiesFromAliasOutputs' +export * from './generateActivitiesFromBalanceChanges' export * from './generateActivitiesFromBasicOutputs' +export * from './generateActivitiesFromChains' export * from './generateActivitiesFromFoundryOutputs' export * from './generateActivitiesFromNftOutputs' +export * from './generateActivitiesFromProcessedTransactions' export * from './generateBalanceChangeActivity' export * from './generateSingleAliasActivity' export * from './generateSingleBasicActivity'