Skip to content

Commit

Permalink
533 add correct explorer link to l2 activities (#534)
Browse files Browse the repository at this point in the history
* refactor: add source and destination network to activity

* enhancement: add explorer url for testnet

* add shimmer evm explorer to whitelist

---------

Co-authored-by: Mark Nardi <[email protected]>
  • Loading branch information
nicole-obrien and MarkNerdi authored Aug 30, 2023
1 parent 833995f commit 65f9790
Show file tree
Hide file tree
Showing 29 changed files with 128 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import { getNftByIdFromAllAccountNfts } from '@core/nfts/actions'
import { ownedNfts, selectedNftId } from '@core/nfts/stores'
import { checkActiveProfileAuth } from '@core/profile/actions'
import { activeProfile } from '@core/profile/stores'
import { CollectiblesRoute, DashboardRoute, collectiblesRouter, dashboardRouter } from '@core/router'
import { setClipboard, truncateString } from '@core/utils'
import { claimActivity, rejectActivity } from '@core/wallet'
Expand All @@ -35,8 +34,6 @@
export let activityId: string
export let _onMount: (..._: any[]) => Promise<void> = async () => {}
const explorerUrl = getDefaultExplorerUrl($activeProfile?.network?.id)
$: activity = $selectedAccountActivities.find((_activity) => _activity.id === activityId)
$: isTimelocked = activity?.asyncData?.asyncStatus === ActivityAsyncStatus.Timelocked
$: isActivityIncomingAndUnclaimed =
Expand All @@ -50,6 +47,7 @@
? getNftByIdFromAllAccountNfts($selectedAccountIndex, activity.nftId)
: undefined
$: nftIsOwned = nft ? $ownedNfts.some((_onMountnft) => _onMountnft.id === nft?.id) : false
$: explorerUrl = getDefaultExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Transaction)
let title: string | undefined = localize('popups.activityDetails.title.fallback')
$: void setTitle(activity)
Expand All @@ -66,7 +64,7 @@
}
function onExplorerClick(_activity: Activity): void {
openUrlInBrowser(`${explorerUrl}/${ExplorerEndpoint.Transaction}/${_activity.transactionId}`)
openUrlInBrowser(`${explorerUrl}/${_activity.transactionId}`)
}
function onTransactionIdClick(_activity: Activity): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import { getNftByIdFromAllAccountNfts } from '@core/nfts/actions'
import { allAccountNfts, selectedNftId } from '@core/nfts/stores'
import { getBaseToken } from '@core/profile/actions'
import { activeProfile } from '@core/profile/stores'
import { collectiblesRouter } from '@core/router/routers'
import { formatTokenAmountPrecise } from '@core/token'
import { getTimeDifference } from '@core/utils'
Expand All @@ -28,8 +27,8 @@
let modal: Modal
const explorerUrl = getDefaultExplorerUrl($activeProfile?.network?.id)
const nft: INft = getNftByIdFromAllAccountNfts($selectedAccountIndex, $selectedNftId)
const explorerUrl = getDefaultExplorerUrl(nft?.networkId, ExplorerEndpoint.Nft)
const { id, name, issuer, address, metadata, downloadMetadata, storageDeposit } = nft ?? {}
const { standard, version, type, uri, description, issuerName, collectionName, attributes, soonaverseAttributes } =
Expand Down Expand Up @@ -155,7 +154,7 @@
}
function onExplorerClick(): void {
openUrlInBrowser(`${explorerUrl}/${ExplorerEndpoint.Nft}/${id}`)
openUrlInBrowser(`${explorerUrl}/${id}`)
}
function onSendClick(): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import { getNameFromNetworkId } from '@core/network'
import { type IItem, Table } from '@bloomwalletio/ui'
import { Activity } from '@core/activity'
import { getFormattedTimeStamp, localize } from '@core/i18n'
Expand Down Expand Up @@ -28,10 +29,10 @@
function setItems(_activity: Activity): void {
items = []
if (_activity?.destinationNetwork) {
if (_activity?.destinationNetworkId) {
items.push({
key: localize('general.destinationNetwork'),
value: _activity?.destinationNetwork,
value: getNameFromNetworkId(_activity?.destinationNetworkId),
})
}
if (_activity?.time) {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/components/tiles/ActivityTile.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
if (persistedToken?.verification?.status === NotVerifiedStatus.New) {
const token: IToken = {
...persistedToken,
networkId: activity.networkId,
networkId: activity.sourceNetworkId,
balance: {
total: 0,
available: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@

{#if token}
<ActivityTileContent {action} {subject} {formattedAsset}>
<TokenIcon slot="icon" persistedToken={token} networkId={activity.networkId} />
<TokenIcon slot="icon" persistedToken={token} networkId={activity.sourceNetworkId} />
</ActivityTileContent>
{/if}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export type BaseActivity = {
subject: Subject | undefined
metadata?: string
tag?: string
networkId: NetworkId
sourceNetworkId: NetworkId
destinationNetworkId: NetworkId
asyncData?: AsyncData
destinationNetwork?: string
parsedLayer2Metadata?: Layer2Metadata
}

Expand All @@ -33,6 +33,6 @@ export type AsyncData = {
expirationDate: Date
isRejected: boolean
isClaiming: boolean
claimingTransactionId: string
claimedDate: Date
claimingTransactionId?: string
claimedDate?: Date
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Subject } from '@core/wallet/types'

export type SenderInfo = {
sender: Subject | undefined
recipient: Subject
subject: Subject | undefined
isInternal: boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export async function generateActivityFromEvmTransaction(
return {
type: ActivityType.Basic,
id: transaction.transactionHash,
transactionId: transaction.transactionHash,
time: new Date(Number(timestamp) * 1000),
inclusionState: InclusionState.Confirmed,
containsValue: true,
Expand All @@ -31,6 +32,7 @@ export async function generateActivityFromEvmTransaction(
rawBaseCoinAmount: Number(transaction.value) / Number(WEI_PER_GLOW),
rawAmount: Number(transaction.value) / Number(WEI_PER_GLOW),
tokenId: getCoinType(),
networkId,
sourceNetworkId: networkId,
destinationNetworkId: networkId,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function generateBalanceChangeActivity(
rawBaseCoinAmount: Math.abs(difference),
rawAmount: Math.abs(difference),
tokenId: tokenId === '0x' ? getCoinType() : tokenId,
networkId,
sourceNetworkId: networkId,
destinationNetworkId: networkId,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export function generateSingleAliasActivity(
time,
metadata,
tag,
networkId,
sourceNetworkId: networkId,
destinationNetworkId: networkId,
inclusionState,
containsValue,
asyncData,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { isShimmerClaimingTransaction } from '@contexts/onboarding/stores'
import { IAccountState } from '@core/account'
import { IActivityGenerationParameters } from '@core/activity/types'
import { parseLayer2Metadata } from '@core/layer-2'
import { getNetworkIdFromAddress } from '@core/layer-2/actions'
import { NetworkId } from '@core/network/types'
import { getCoinType } from '@core/profile/actions'
import { activeProfileId } from '@core/profile/stores'
import { IBasicOutput } from '@iota/types'
Expand All @@ -17,7 +20,6 @@ import {
getTagFromOutput,
} from './helper'
import { getNativeTokenFromOutput } from './outputs'
import { NetworkId } from '@core/network/types'

export function generateSingleBasicActivity(
account: IAccountState,
Expand All @@ -43,12 +45,19 @@ export function generateSingleBasicActivity(
const metadata = getMetadataFromOutput(output)
const publicNote = ''

const sendingInfo = getSendingInformation(processedTransaction, output, account, networkId)
const { sender, recipient, subject, isInternal } = getSendingInformation(
processedTransaction,
output,
account,
networkId
)
const sourceNetworkId = getNetworkIdFromAddress(sender?.address, networkId)
const destinationNetworkId = getNetworkIdFromAddress(recipient?.address, sourceNetworkId)

const asyncData = getAsyncDataFromOutput(output, outputId, claimingData, account)
const parsedLayer2Metadata = parseLayer2Metadata(metadata)

// const { parsedLayer2Metadata, destinationNetwork } = getLayer2ActivityInformation(metadata, sendingInfo)
// const gasLimit = Number(parsedLayer2Metadata?.gasLimit ?? '0')
const gasLimit = 0
const gasLimit = Number(parsedLayer2Metadata?.gasLimit ?? '0')

const storageDeposit = getStorageDepositFromOutput(output)

Expand Down Expand Up @@ -83,11 +92,12 @@ export function generateSingleBasicActivity(
publicNote,
metadata,
tag,
networkId,
sourceNetworkId,
destinationNetworkId,
tokenId,
asyncData,
// destinationNetwork,
// parsedLayer2Metadata,
...sendingInfo,
parsedLayer2Metadata,
subject,
isInternal,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export function generateSingleConsolidationActivity(
storageDeposit,
metadata,
tag,
networkId,
sourceNetworkId: networkId,
destinationNetworkId: networkId,
asyncData,
amountConsolidatedInputs,
...sendingInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ export function generateSingleFoundryActivity(
isHidden,
metadata,
tag,
networkId,
sourceNetworkId: networkId,
destinationNetworkId: networkId,
asyncData,
...sendingInfo,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export function generateSingleGovernanceActivity(
storageDeposit,
metadata,
tag,
networkId,
sourceNetworkId: networkId,
destinationNetworkId: networkId,
asyncData: undefined,
...governanceInfo,
...sendingInfo,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { IAccountState } from '@core/account'
import { parseLayer2Metadata } from '@core/layer-2'
import { getNetworkIdFromAddress } from '@core/layer-2/actions'
import { NetworkId } from '@core/network/types'
import type { INftOutput } from '@iota/types'
import { ActivityType } from '../enums'
import { NftActivity } from '../types'
import type { INftOutput } from '@iota/types'
import { IActivityGenerationParameters } from '../types/activity-generation-parameters.interface'
import {
getAmountFromOutput,
getAsyncDataFromOutput,
getLayer2ActivityInformation,
getMetadataFromOutput,
getSendingInformation,
getStorageDepositFromOutput,
getTagFromOutput,
} from './helper'
import { IActivityGenerationParameters } from '../types/activity-generation-parameters.interface'
import { getNftId } from './outputs'
import { NetworkId } from '@core/network/types'

export function generateSingleNftActivity(
account: IAccountState,
Expand All @@ -34,23 +35,29 @@ export function generateSingleNftActivity(
const metadata = getMetadataFromOutput(output)
const tag = getTagFromOutput(output)

const sendingInfo = getSendingInformation(processedTransaction, output, account, networkId)
const { subject, isInternal } = sendingInfo

const rawBaseCoinAmount = getAmountFromOutput(output)
const storageDeposit = getStorageDepositFromOutput(output)

const layer2ActivityInformation = getLayer2ActivityInformation(metadata, sendingInfo)
const { sender, recipient, subject, isInternal } = getSendingInformation(
processedTransaction,
output,
account,
networkId
)
const sourceNetworkId = getNetworkIdFromAddress(sender?.address, networkId)
const destinationNetworkId = getNetworkIdFromAddress(recipient?.address, sourceNetworkId)

const asyncData = getAsyncDataFromOutput(output, outputId, claimingData, account)
const parsedLayer2Metadata = parseLayer2Metadata(metadata)

return {
type: ActivityType.Nft,
id,
transactionId,
outputId,
nftId,
networkId,
sourceNetworkId,
destinationNetworkId: destinationNetworkId,
time,
isHidden,
action,
Expand All @@ -65,6 +72,6 @@ export function generateSingleNftActivity(
subject,
isInternal,
direction,
...layer2ActivityInformation,
parsedLayer2Metadata,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function getTransactionAssets(
}
| undefined {
if (activity.type === ActivityType.Nft) {
const baseCoin = getTokenFromSelectedAccountTokens(getCoinType(), activity.networkId)
const baseCoin = getTokenFromSelectedAccountTokens(getCoinType(), activity.sourceNetworkId)
const nft = getNftByIdFromAllAccountNfts(accountIndex, activity.nftId)
return {
nft,
Expand All @@ -29,10 +29,10 @@ export function getTransactionAssets(
},
}
} else if (activity.type === ActivityType.Basic || activity.type === ActivityType.Foundry) {
const tokenWithBalance = getTokenFromSelectedAccountTokens(activity.tokenId, activity.networkId)
const tokenWithBalance = getTokenFromSelectedAccountTokens(activity.tokenId, activity.sourceNetworkId)
const persistedToken = getPersistedToken(activity.tokenId)
const token: IToken = {
networkId: activity.networkId,
networkId: activity.sourceNetworkId,
balance: {
total: 0,
available: 0,
Expand All @@ -48,7 +48,7 @@ export function getTransactionAssets(
},
}
} else {
const baseCoin = getTokenFromSelectedAccountTokens(getCoinType(), activity.networkId)
const baseCoin = getTokenFromSelectedAccountTokens(getCoinType(), activity.sourceNetworkId)
return {
tokenTransfer: {
rawAmount: String(activity.rawAmount),
Expand All @@ -61,7 +61,7 @@ export function getTransactionAssets(
}
}
} else if (activity.type === ActivityType.Governance) {
const baseCoin = getTokenFromSelectedAccountTokens(getCoinType(), activity.networkId)
const baseCoin = getTokenFromSelectedAccountTokens(getCoinType(), activity.sourceNetworkId)

const isVotingPowerActivity =
activity.governanceAction === GovernanceAction.DecreaseVotingPower ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { AsyncData, IClaimData } from '@core/activity/types'
export function getAsyncDataFromOutput(
output: Output,
outputId: string,
claimingData: IClaimData,
claimingData: IClaimData | undefined,
account: IAccountState
): AsyncData {
): AsyncData | undefined {
const isAsync = isOutputAsync(output)
if (isAsync) {
const isClaiming = false
Expand Down Expand Up @@ -42,6 +42,6 @@ export function getAsyncDataFromOutput(
claimedDate,
}
} else {
return null
return undefined
}
}
Loading

0 comments on commit 65f9790

Please sign in to comment.