-
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.
feat: create activity from evm transaction (#467)
* generate sent evm transactions * add transaction after send * fix types * get correct subject * gas fee in activity popup Co-authored-by: MarkNerdi996 <[email protected]> --------- Co-authored-by: Matthew Maxwell <[email protected]> Co-authored-by: Nicole O'Brien <[email protected]> Co-authored-by: MarkNerdi996 <[email protected]>
- Loading branch information
1 parent
e562d00
commit 476bceb
Showing
14 changed files
with
169 additions
and
107 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
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 networkId = chain.getConfiguration().id | ||
|
||
const transactions = getPersistedEvmTransactions(account.index, networkId) | ||
for (const transaction of transactions) { | ||
const activity = await generateActivityFromEvmTransaction(transaction, networkId, 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
36 changes: 36 additions & 0 deletions
36
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,36 @@ | ||
import { PersistedEvmTransaction, TransactionActivity } from '../types' | ||
import { ActivityAction, ActivityDirection, ActivityType, InclusionState } from '../enums' | ||
import { getCoinType } from '@core/profile/actions' | ||
import { getSubjectFromAddress } from '@core/wallet' | ||
import { WEI_PER_GLOW } from '@core/layer-2' | ||
import Web3 from 'web3' | ||
import { NetworkId } from '@core/network/types' | ||
|
||
export async function generateActivityFromEvmTransaction( | ||
transaction: PersistedEvmTransaction, | ||
networkId: NetworkId, | ||
provider: Web3 | ||
): Promise<TransactionActivity> { | ||
const direction = ActivityDirection.Outgoing // Currently only sent transactions are supported | ||
|
||
const subject = getSubjectFromAddress(transaction.to, networkId) | ||
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, | ||
gasUsed: transaction.gasUsed, | ||
subject, | ||
rawBaseCoinAmount: Number(transaction.value) / Number(WEI_PER_GLOW), | ||
rawAmount: Number(transaction.value) / Number(WEI_PER_GLOW), | ||
tokenId: getCoinType(), | ||
networkId, | ||
} | ||
} |
Oops, something went wrong.