-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: tx history: include account output in average txs (#8253)
* feat: Sync SDK types * feat: stop generating txs out of outputs * fix: tx history: include account output in average txs --------- Co-authored-by: marc2332 <[email protected]> Co-authored-by: Begoña Álvarez de la Cruz <[email protected]>
- Loading branch information
1 parent
b3633ee
commit d5ed5c7
Showing
8 changed files
with
130 additions
and
58 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
2 changes: 1 addition & 1 deletion
2
packages/shared/lib/core/wallet/utils/outputs/computeOutputId.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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { TransactionId, OutputId } from '@iota/sdk/out/types' | ||
import { api } from '@core/api' | ||
|
||
export function computeOutputId(id: TransactionId, index: number): Promise<OutputId> { | ||
export function computeOutputId(id: TransactionId, index: number): OutputId { | ||
return api.computeOutputId(id, index) | ||
} |
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
57 changes: 57 additions & 0 deletions
57
packages/shared/lib/core/wallet/utils/outputs/preprocessIncomingTransaction.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,57 @@ | ||
import { IProcessedTransaction, IWrappedOutput } from '../../interfaces' | ||
import { Output, OutputType, OutputWithMetadata, TransactionWithMetadata, UTXOInput } from '@iota/sdk/out/types' | ||
// import { computeOutputId } from './computeOutputId' | ||
import { getOutputIdFromTransactionIdAndIndex } from './getOutputIdFromTransactionIdAndIndex' | ||
import { ActivityDirection } from '../../enums' | ||
|
||
export function preprocessIncomingTransaction(transaction: TransactionWithMetadata): IProcessedTransaction { | ||
const regularTransactionEssence = transaction.payload.transaction | ||
const transactionId = transaction?.transactionId?.toString() | ||
|
||
const outputs = convertTransactionsOutputTypesToWrappedOutputs(transactionId, regularTransactionEssence.outputs) | ||
|
||
const utxoInputs = regularTransactionEssence.inputs.map((i) => i as UTXOInput) | ||
// const inputIds = utxoInputs.map((input) => { | ||
// const transactionId = input.transactionId | ||
// const transactionOutputIndex = input.transactionOutputIndex | ||
// return computeOutputId(transactionId, transactionOutputIndex) | ||
// }) | ||
// const inputs = await Promise.all(inputIds.map((inputId) => wallet.getOutput(inputId))) | ||
|
||
return { | ||
outputs: outputs, | ||
transactionId, | ||
direction: ActivityDirection.Incoming, | ||
time: new Date(Number(transaction.timestamp)), | ||
inclusionState: transaction.inclusionState, | ||
wrappedInputs: [], | ||
// wrappedInputs: <IWrappedOutput[]>inputs, | ||
utxoInputs, | ||
} | ||
} | ||
|
||
function convertTransactionsOutputTypesToWrappedOutputs( | ||
transactionId: string, | ||
outputTypes: Output[] | ||
): IWrappedOutput[] { | ||
return outputTypes.map((outputType, index) => | ||
convertTransactionOutputTypeToWrappedOutput(transactionId, index, outputType) | ||
) | ||
} | ||
|
||
function convertTransactionOutputTypeToWrappedOutput( | ||
transactionId: string, | ||
index: number, | ||
outputType: Output | ||
): IWrappedOutput { | ||
const outputId = getOutputIdFromTransactionIdAndIndex(transactionId, index) | ||
OutputWithMetadata | ||
return { | ||
outputId, | ||
output: outputType, | ||
remainder: | ||
index === 0 || (outputType.type !== OutputType.Basic && outputType.type !== OutputType.Account) | ||
? false | ||
: true, // when sending prepared output in the resulting transactions outputs array it will always be first output(index = 0) | ||
} | ||
} |
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
9 changes: 4 additions & 5 deletions
9
packages/shared/lib/core/wallet/utils/transactions/getDirectionFromOutgoingTransaction.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