Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add mana to txs in tx activities and activity details #8278

Merged
merged 25 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e73bd56
feat: Sync SDK types
marc2332 Mar 22, 2024
4d28457
feat: stop generating txs out of outputs
marc2332 Mar 22, 2024
71f88e7
fix: tx history: include account output in average txs
cpl121 Mar 22, 2024
eb19a90
Merge branch 'develop-iota2.0' into feat/sync-sdk-types
cpl121 Mar 22, 2024
a850bb8
Merge branch 'feat/sync-sdk-types' into feat/stop-generating-txs-out-…
cpl121 Mar 22, 2024
3cedefe
Merge branch 'feat/stop-generating-txs-out-of-outputs' into fix/tx-hi…
cpl121 Mar 22, 2024
e499fa4
fix: Fix incorrect timestamp in Incoming txs
marc2332 Mar 25, 2024
4098672
fix: Receive funds to implicit account address
marc2332 Mar 25, 2024
07cf0a4
Merge branches 'fix/tx-history-include-account-output-in-avg-txs' and…
cpl121 Mar 25, 2024
c3f486e
Merge branch 'develop-iota2.0' into fix/tx-history-include-account-ou…
cpl121 Mar 25, 2024
a501aa2
Merge branch 'fix/tx-history-include-account-output-in-avg-txs' into …
cpl121 Mar 25, 2024
ea52b1c
Merge branch 'fix/incorrect-timestamp-incoming-txs' into fix/receive-…
cpl121 Mar 25, 2024
de89392
Merge branch 'develop-iota2.0' into fix/tx-history-include-account-ou…
cpl121 Mar 25, 2024
278543c
Merge branch 'fix/tx-history-include-account-output-in-avg-txs' into …
cpl121 Mar 25, 2024
f3f4e32
Merge branch 'fix/incorrect-timestamp-incoming-txs' into fix/receive-…
cpl121 Mar 25, 2024
e07821c
Merge branches 'fix/incorrect-timestamp-incoming-txs' and 'develop-io…
cpl121 Mar 25, 2024
c1d22a9
Merge branch 'fix/incorrect-timestamp-incoming-txs' into fix/receive-…
cpl121 Mar 25, 2024
a4f5c78
feat: add mana to txs in tx activities and activity details
cpl121 Mar 26, 2024
541013a
Merge branch 'develop-iota2.0' into fix/incorrect-timestamp-incoming-txs
cpl121 Mar 27, 2024
8d3126b
Merge branch 'fix/incorrect-timestamp-incoming-txs' into fix/receive-…
cpl121 Mar 27, 2024
ba82151
Merge branch 'fix/receive-funds-to-implicit-account-address' into fea…
cpl121 Mar 27, 2024
b2ecdce
Merge branch 'develop-iota2.0' into fix/receive-funds-to-implicit-acc…
cpl121 Mar 27, 2024
d979caf
Merge branch 'fix/receive-funds-to-implicit-account-address' into fea…
begonaalvarezd Mar 27, 2024
d7293f1
resolve conflicts
marc2332 Mar 28, 2024
357b80b
Merge branch 'develop-iota2.0' into feat/add-mana-to-tx-history
begonaalvarezd Mar 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import { KeyValueBox } from '@ui'
import { getFormattedTimeStamp, localize } from '@core/i18n'
import { activeProfile, getBaseToken } from '@core/profile'
import { Activity, formatTokenAmountPrecise } from '@core/wallet'
import { ExplorerEndpoint } from '@core/network'
import { Activity, ActivityDirection, formatTokenAmountBestMatch, formatTokenAmountPrecise } from '@core/wallet'
import { DEFAULT_MANA, ExplorerEndpoint } from '@core/network'
import { getOfficialExplorerUrl } from '@core/network/utils'
import { openUrlInBrowser } from '@core/app'
import { IKeyValueBoxList, truncateString } from '@core/utils'
Expand All @@ -28,6 +28,8 @@
$: formattedGiftedStorageDeposit = formatTokenAmountPrecise(activity?.giftedStorageDeposit ?? 0, getBaseToken())
$: formattedSurplus = formatTokenAmountPrecise(activity?.surplus ?? 0, getBaseToken())
$: formattedGasFee = formatTokenAmountPrecise(Number(gasFee ?? 0), getBaseToken())
$: formattedManaPrefix = activity.direction === ActivityDirection.Incoming ? '' : '- '
$: formattedMana = formattedManaPrefix + formatTokenAmountBestMatch(Number(activity?.mana ?? 0), DEFAULT_MANA)

let transactionDetailsList: IKeyValueBoxList
$: transactionDetailsList = {
Expand Down Expand Up @@ -62,6 +64,9 @@
timelockDate: { data: formattedTimelockDate, isTooltipVisible: true },
}),
...(claimedTime && { claimedTime: { data: claimedTime } }),
...(typeof activity?.mana === 'number' && {
mana: { data: formattedMana },
}),
}

function onTransactionIdClick(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface IProcessedTransaction {
utxoInputs: UTXOInput[]
wrappedInputs: IWrappedOutput[]
claimingData?: IClaimData
mana: number
}

export interface IClaimData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type BaseActivity = {
asyncData: AsyncData
destinationNetwork?: string
parsedLayer2Metadata?: Partial<Layer2Metadata>
mana: number
}

export type AsyncData = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function generateSingleAccountActivity(
wallet: IWalletState,
{ action, processedTransaction, wrappedOutput }: IActivityGenerationParameters
): Promise<AccountActivity> {
const { transactionId, claimingData, direction, time, inclusionState } = processedTransaction
const { transactionId, claimingData, direction, time, inclusionState, mana } = processedTransaction

const output = wrappedOutput.output as AccountOutput
const outputId = wrappedOutput.outputId
Expand Down Expand Up @@ -57,6 +57,7 @@ export async function generateSingleAccountActivity(
inclusionState,
containsValue,
asyncData,
mana,
...sendingInfo,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function generateSingleAnchorActivity(
wallet: IWalletState,
{ action, processedTransaction, wrappedOutput }: IActivityGenerationParameters
): Promise<AnchorActivity> {
const { transactionId, claimingData, direction, time, inclusionState } = processedTransaction
const { transactionId, claimingData, direction, time, inclusionState, mana } = processedTransaction

const output = wrappedOutput.output as AnchorOutput
const outputId = wrappedOutput.outputId
Expand Down Expand Up @@ -56,6 +56,7 @@ export async function generateSingleAnchorActivity(
inclusionState,
containsValue,
asyncData,
mana,
...sendingInfo,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function generateSingleBasicActivity(
fallbackAssetId?: string,
fallbackAmount?: number
): Promise<TransactionActivity> {
const { transactionId, direction, claimingData, time, inclusionState } = processedTransaction
const { transactionId, direction, claimingData, time, inclusionState, mana } = processedTransaction

const isHidden = false
const isAssetHidden = false
Expand Down Expand Up @@ -102,6 +102,7 @@ export async function generateSingleBasicActivity(
asyncData,
destinationNetwork,
parsedLayer2Metadata,
mana,
...sendingInfo,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function generateSingleConsolidationActivity(
wallet: IWalletState,
{ action, processedTransaction, wrappedOutput }: IActivityGenerationParameters
): Promise<ConsolidationActivity> {
const { transactionId, direction, claimingData, time, inclusionState, wrappedInputs } = processedTransaction
const { transactionId, direction, claimingData, time, inclusionState, wrappedInputs, mana } = processedTransaction

const isHidden = false
const isAssetHidden = false
Expand Down Expand Up @@ -54,6 +54,7 @@ export async function generateSingleConsolidationActivity(
tag,
asyncData,
amountConsolidatedInputs,
mana,
...sendingInfo,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function generateSingleFoundryActivity(
wallet: IWalletState,
{ action, processedTransaction, wrappedOutput }: IActivityGenerationParameters
): Promise<FoundryActivity> {
const { transactionId, claimingData, time, direction, inclusionState } = processedTransaction
const { transactionId, claimingData, time, direction, inclusionState, mana } = processedTransaction

const output = wrappedOutput.output as FoundryOutput
const outputId = wrappedOutput.outputId
Expand Down Expand Up @@ -78,6 +78,7 @@ export async function generateSingleFoundryActivity(
metadata,
tag,
asyncData,
mana,
...sendingInfo,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function generateSingleGovernanceActivity(
wallet: IWalletState,
{ action, processedTransaction, wrappedOutput }: IActivityGenerationParameters
): Promise<GovernanceActivity> {
const { transactionId, direction, time, inclusionState, wrappedInputs } = processedTransaction
const { transactionId, direction, time, inclusionState, wrappedInputs, mana } = processedTransaction

const isHidden = false
const isAssetHidden = false
Expand Down Expand Up @@ -55,6 +55,7 @@ export async function generateSingleGovernanceActivity(
metadata,
tag,
asyncData: null,
mana,
...governanceInfo,
...sendingInfo,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function generateSingleNftActivity(
{ action, processedTransaction, wrappedOutput }: IActivityGenerationParameters,
nftIdFromInput?: string
): Promise<NftActivity> {
const { claimingData, time, inclusionState, transactionId, direction } = processedTransaction
const { claimingData, time, inclusionState, transactionId, direction, mana } = processedTransaction
const outputId = wrappedOutput.outputId
const output = wrappedOutput.output as NftOutput
const id = outputId || transactionId
Expand Down Expand Up @@ -81,5 +81,6 @@ export async function generateSingleNftActivity(
direction,
destinationNetwork,
parsedLayer2Metadata,
mana,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function generateVestingActivity(
wallet: IWalletState,
{ action, processedTransaction, wrappedOutput }: IActivityGenerationParameters
): Promise<VestingActivity> {
const { transactionId, direction, claimingData, time, inclusionState } = processedTransaction
const { transactionId, direction, claimingData, time, inclusionState, mana } = processedTransaction

const isHidden = false
const isAssetHidden = false
Expand Down Expand Up @@ -63,6 +63,7 @@ export async function generateVestingActivity(
tag,
asyncData,
destinationNetwork,
mana,
...sendingInfo,
...parsedLayer2Metadata,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IProcessedTransaction, IWrappedOutput } from '../../interfaces'
import { Output, OutputType, OutputWithMetadata, TransactionWithMetadata, UTXOInput } from '@iota/sdk/out/types'
import { Output, OutputType, TransactionWithMetadata, UTXOInput } from '@iota/sdk/out/types'
import { getOutputIdFromTransactionIdAndIndex } from './getOutputIdFromTransactionIdAndIndex'
import { ActivityDirection } from '../../enums'
import { getUnixTimestampFromNodeInfoAndSlotIndex, nodeInfoProtocolParameters } from '@core/network'
Expand All @@ -24,13 +24,18 @@ export function preprocessIncomingTransaction(transaction: TransactionWithMetada
remainder: true,
}))

const manaCost = outputs
.filter((output) => !output.remainder)
.reduce((acc, output) => acc + Number(output.output.mana), 0)

return {
outputs,
transactionId,
direction: ActivityDirection.Incoming,
time: new Date(slotUnixTimestamp * MILLISECONDS_PER_SECOND),
inclusionState: transaction.inclusionState,
wrappedInputs: <IWrappedOutput[]>inputs,
mana: manaCost,
utxoInputs,
}
}
Expand All @@ -50,7 +55,6 @@ function convertTransactionOutputTypeToWrappedOutput(
outputType: Output
): IWrappedOutput {
const outputId = getOutputIdFromTransactionIdAndIndex(transactionId, index)
OutputWithMetadata
return {
outputId,
output: outputType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import { IProcessedTransaction, IWrappedOutput } from '../../interfaces'
import { Output, OutputType, OutputWithMetadata, TransactionWithMetadata, UTXOInput } from '@iota/sdk/out/types'
import {
AccountOutput,
Output,
OutputType,
OutputWithMetadata,
TransactionWithMetadata,
UTXOInput,
} from '@iota/sdk/out/types'
import { computeOutputId } from './computeOutputId'
import { getOutputIdFromTransactionIdAndIndex } from './getOutputIdFromTransactionIdAndIndex'
import { getDirectionFromOutgoingTransaction } from '../transactions'
import { IWalletState } from '@core/wallet/interfaces'
import { getPassiveManaForOutput } from '@core/network'
import { MILLISECONDS_PER_SECOND } from '@core/utils'
import { getUnixTimestampFromNodeInfoAndSlotIndex, nodeInfoProtocolParameters } from '@core/network'
import { get } from 'svelte/store'
Expand Down Expand Up @@ -31,12 +39,24 @@ export async function preprocessOutgoingTransaction(

const inputs = await Promise.all(inputIds.map((inputId) => wallet.getOutput(inputId)))

let manaCost = 0
const prevAccountOutput = inputs.find((input) => (input.output as AccountOutput).accountId)
if (prevAccountOutput) {
const prevMana = getPassiveManaForOutput(prevAccountOutput) ?? 0
const postAccountOutput = outputs.find(
(output) =>
(prevAccountOutput.output as AccountOutput).accountId === (output.output as AccountOutput).accountId
)
manaCost = prevMana - Number(postAccountOutput?.output?.mana ?? 0)
}

return {
outputs: outputs,
transactionId,
direction,
time: new Date(slotUnixTimestamp * MILLISECONDS_PER_SECOND),
inclusionState: transaction.inclusionState,
mana: manaCost,
wrappedInputs: <IWrappedOutput[]>inputs,
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1733,7 +1733,8 @@
"manaCost": "Estimated Mana cost",
"availableMana": "Available mana",
"insufficientMana": "Insufficient {availableMana}.",
"secondsToRefreshManaCost": "{seconds} seconds to refresh the mana cost"
"secondsToRefreshManaCost": "{seconds} seconds to refresh the mana cost",
"mana": "Mana"
},
"filters":{
"title": "Filters",
Expand Down
Loading