Skip to content

Commit

Permalink
fix: calculation for transaction.
Browse files Browse the repository at this point in the history
Signed-off-by: Eugene Panteleymonchuk <[email protected]>
  • Loading branch information
panteleymonchuk committed Jan 19, 2024
1 parent 0853db0 commit 91de9a8
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CommonOutput, ExpirationUnlockCondition, INodeInfoBaseToken, UnlockConditionType } from "@iota/sdk-wasm/web";
import { CommonOutput, INodeInfoBaseToken } from "@iota/sdk-wasm/web";
import moment from "moment/moment";

import { DateHelper } from "~helpers/dateHelper";
Expand Down Expand Up @@ -61,8 +61,6 @@ export const getTransactionHistoryRecords = (

transactionIdToOutputs.forEach((outputs, transactionId) => {
const lastOutputTime = Math.max(...outputs.map((t) => t.milestoneTimestamp));

console.log("--- getTransactionHistoryRecords", transactionId, outputs);
const balanceChange = calculateBalanceChange(outputs);
const ago = moment(lastOutputTime * 1000).fromNow();

Expand Down Expand Up @@ -111,15 +109,6 @@ export const calculateBalanceChange = (outputs: OutputWithDetails[]) => {
let amount = Number(outputFromDetails.amount);
if (output.isSpent) {
amount = -1 * amount;
// we need to cover the case where the output is spent not by the current address,
// but by the return address of an expired expiration unlock condition
const expirationUnlockCondition = outputFromDetails.unlockConditions?.find(
({ type }) => type === UnlockConditionType.Expiration,
) as ExpirationUnlockCondition;

if (expirationUnlockCondition && output.milestoneTimestamp > expirationUnlockCondition.unixTime) {
amount = 0;
}
}
return acc + amount;
}, 0);
Expand Down
7 changes: 0 additions & 7 deletions client/src/helpers/hooks/useAddressHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,6 @@ export function useAddressHistory(

const groupedOutputsByTransactionId = groupOutputsByTransactionId(updatedOutputsWithDetails);

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
window.outputs = updatedOutputsWithDetails;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
window.groupedOutputsByTransactionId = groupedOutputsByTransactionId;

setTransactionIdToOutputs(groupedOutputsByTransactionId);
setOutputsWithDetails([...outputsWithDetails, ...fulfilledOutputs]);
setCursor(cursor);
Expand Down
8 changes: 0 additions & 8 deletions client/src/helpers/hooks/useInputsAndOutputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@ export function useInputsAndOutputs(
bech32Hrp,
apiClient,
);

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
window.inputs = inputs;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
window.outputs = outputs;

if (isMounted) {
setInputs(inputs);
setUnlocks(unlocks);
Expand Down

0 comments on commit 91de9a8

Please sign in to comment.