-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create activity from evm transaction
- Loading branch information
Showing
10 changed files
with
71 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/shared/src/lib/core/activity/utils/generateActivitiesFromChains.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Activity[]> { | ||
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 | ||
} |
2 changes: 1 addition & 1 deletion
2
...ateActivitiesFromProcessedTransactions.ts → ...ateActivitiesFromProcessedTransactions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/shared/src/lib/core/activity/utils/generateActivityFromEvmTransaction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TransactionActivity> { | ||
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, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters