Skip to content

Commit

Permalink
chore: put link to right place, clean code
Browse files Browse the repository at this point in the history
Signed-off-by: Eugene Panteleymonchuk <[email protected]>
  • Loading branch information
panteleymonchuk committed Feb 14, 2024
1 parent 8eb2093 commit 3ce0422
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ const TransactionCard: React.FC<ITransactionEntryProps> = ({
isSpent,
isFormattedAmounts,
setIsFormattedAmounts,
stardustGenesisOutputId,
stardustGenesisOutputLink,
}) => {
const valueView = (
<span className="pointer margin-r-5" onClick={() => setIsFormattedAmounts(!isFormattedAmounts)}>
Expand All @@ -32,8 +30,6 @@ const TransactionCard: React.FC<ITransactionEntryProps> = ({
<div className="card--label">Transaction Id</div>
<div className="row card--value">
<TransactionIdView
stardustGenesisOutputId={stardustGenesisOutputId}
stardustGenesisOutputLink={stardustGenesisOutputLink}
transactionId={transactionId}
isTransactionFromStardustGenesis={isTransactionFromStardustGenesis}
transactionLink={transactionLink}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,6 @@ export interface ITransactionEntryProps {
*/
isTransactionFromStardustGenesis: boolean;

/**
*
*/
stardustGenesisOutputId?: string;
/**
*
*/
stardustGenesisOutputLink?: string;

/**
* check some of outputs timestamps zero
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ const TransactionHistory: React.FC<TransactionHistoryProps> = ({ network, addres
<TransactionCard
isGenesisByDate={c.isGenesisByDate}
isTransactionFromStardustGenesis={c.isTransactionFromStardustGenesis}
stardustGenesisOutputId={c.stardustGenesisOutputId}
transactionLink={c.transactionLink}
dateFormatted={c.dateFormatted}
balanceChangeFormatted={c.balanceChangeFormatted}
Expand Down
36 changes: 10 additions & 26 deletions client/src/app/components/stardust/history/TransactionIdView.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,27 @@
import React from "react";
import { STARDUST_SUPPLY_INCREASE_TRANSACTION_ID } from "~/helpers/stardust/transactionsHelper";
import { Link } from "react-router-dom";
import { STARDUST_SUPPLY_INCREASE_OUTPUT_TICKER } from "~/helpers/stardust/transactionsHelper";
import TruncatedId from "../TruncatedId";
import Tooltip from "../../Tooltip";

export interface ITransactionIdProps {
transactionId: string;
isTransactionFromStardustGenesis: boolean;
stardustGenesisOutputId?: string;
stardustGenesisOutputLink?: string;
transactionLink: string;
}

const TransactionIdView: React.FC<ITransactionIdProps> = ({
transactionId,
isTransactionFromStardustGenesis,
transactionLink,
stardustGenesisOutputId,
stardustGenesisOutputLink,
}) => {
if (isTransactionFromStardustGenesis && transactionId.includes(STARDUST_SUPPLY_INCREASE_TRANSACTION_ID)) {
return <span>Stardust Genesis</span>;
const TransactionIdView: React.FC<ITransactionIdProps> = ({ transactionId, isTransactionFromStardustGenesis, transactionLink }) => {
if (isTransactionFromStardustGenesis && transactionId.includes(STARDUST_SUPPLY_INCREASE_OUTPUT_TICKER)) {
return (
<Link to={transactionLink}>
<span>Stardust Genesis</span>
</Link>
);
}

const truncateParams = React.useMemo(() => {
if (isTransactionFromStardustGenesis) {
return {
id: stardustGenesisOutputId as string,
link: stardustGenesisOutputLink as string,
};
}
return {
id: transactionId,
link: transactionLink,
};
}, [isTransactionFromStardustGenesis, transactionId, transactionLink, stardustGenesisOutputId, stardustGenesisOutputLink]);

return (
<>
<TruncatedId id={truncateParams.id} link={truncateParams.link} />
<TruncatedId id={transactionId} link={transactionLink} />
{isTransactionFromStardustGenesis && (
<Tooltip tooltipContent="This link opens the transaction on Chrysalis Mainnet" childrenClass="row middle">
<span className="material-icons" style={{ fontSize: "14px" }}>
Expand Down
4 changes: 0 additions & 4 deletions client/src/app/components/stardust/history/TransactionRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ const TransactionRow: React.FC<ITransactionEntryProps> = ({
isSpent,
isFormattedAmounts,
setIsFormattedAmounts,
stardustGenesisOutputLink,
stardustGenesisOutputId,
}) => {
const valueView = (
<span className="pointer" onClick={() => setIsFormattedAmounts(!isFormattedAmounts)}>
Expand All @@ -28,8 +26,6 @@ const TransactionRow: React.FC<ITransactionEntryProps> = ({
<td className="transaction-id">
<div className="row center">
<TransactionIdView
stardustGenesisOutputId={stardustGenesisOutputId}
stardustGenesisOutputLink={stardustGenesisOutputLink}
transactionId={transactionId}
isTransactionFromStardustGenesis={isTransactionFromStardustGenesis}
transactionLink={transactionLink}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ import moment from "moment/moment";

import { DateHelper } from "~helpers/dateHelper";
import { OutputWithDetails } from "~helpers/hooks/useAddressHistory";
import { STARDUST_SUPPLY_INCREASE_TRANSACTION_ID, TransactionsHelper } from "~helpers/stardust/transactionsHelper";
import { STARDUST_SUPPLY_INCREASE_OUTPUT_TICKER, TransactionsHelper } from "~helpers/stardust/transactionsHelper";
import { formatAmount } from "~helpers/stardust/valueFormatHelper";
import { CHRYSALIS_MAINNET } from "~models/config/networkType";

export interface ITransactionHistoryRecord {
isGenesisByDate: boolean;
isTransactionFromStardustGenesis: boolean;
isSpent: boolean;
stardustGenesisOutputId?: string;
stardustGenesisOutputLink?: string;
transactionLink: string;
transactionId: string;
timestamp: number;
Expand Down Expand Up @@ -59,42 +57,31 @@ export const getTransactionHistoryRecords = (
): ITransactionHistoryRecord[] => {
const calculatedTransactions: ITransactionHistoryRecord[] = [];

let isSet = false; // TODO fake transaction. Remove after confirmation
transactionIdToOutputs.forEach((outputs, transactionId, index) => {
transactionIdToOutputs.forEach((outputs, transactionId) => {
const lastOutputTime = Math.max(...outputs.map((t) => t.milestoneTimestamp));
const balanceChange = calculateBalanceChange(outputs);
const ago = moment(lastOutputTime * 1000).fromNow();

const isGenesisByDate = outputs.map((t) => t.milestoneTimestamp).some((milestoneTimestamp) => milestoneTimestamp === 0);

// TODO fake transaction. Remove after confirmation
if (!isSet) {
outputs[0].milestoneIndex = 7669900;
isSet = true;
}

let stardustGenesisOutputId;
let stardustGenesisOutputLink;
const isTransactionFromStardustGenesis = outputs.some(({ milestoneIndex, outputId }) => {
const isGenesis = TransactionsHelper.isTransactionFromIotaStardustGenesis(network, milestoneIndex);
if (isGenesis) {
stardustGenesisOutputId = outputId;
stardustGenesisOutputLink = `/${network}/output/${outputId}`;
}

return isGenesis;
});

const transactionLink = getTransactionLink(network, transactionId, isTransactionFromStardustGenesis);
const transactionLink = getTransactionLink(network, transactionId, isTransactionFromStardustGenesis, stardustGenesisOutputId);

const isSpent = balanceChange <= 0;

calculatedTransactions.push({
isGenesisByDate: isGenesisByDate,
isTransactionFromStardustGenesis: isTransactionFromStardustGenesis,
isSpent: isSpent,
stardustGenesisOutputId: stardustGenesisOutputId,
stardustGenesisOutputLink: stardustGenesisOutputLink,
transactionLink: transactionLink,
transactionId: transactionId,
timestamp: lastOutputTime,
Expand Down Expand Up @@ -124,8 +111,19 @@ export const calculateBalanceChange = (outputs: OutputWithDetails[]) => {
}, 0);
};

export const getTransactionLink = (network: string, transactionId: string, isTransactionFromStardustGenesis: boolean) => {
return isTransactionFromStardustGenesis && !transactionId.includes(STARDUST_SUPPLY_INCREASE_TRANSACTION_ID)
? `/${CHRYSALIS_MAINNET}/search/${transactionId}`
: `/${network}/transaction/${transactionId}`;
export const getTransactionLink = (
network: string,
transactionId: string,
isTransactionFromStardustGenesis: boolean,
outputId?: string,
) => {
if (isTransactionFromStardustGenesis && transactionId.includes(STARDUST_SUPPLY_INCREASE_OUTPUT_TICKER)) {
return `/${network}/output/${outputId}`;
}

if (isTransactionFromStardustGenesis && !transactionId.includes(STARDUST_SUPPLY_INCREASE_OUTPUT_TICKER)) {
return `/${CHRYSALIS_MAINNET}/search/${transactionId}`;
}

return `/${network}/transaction/${transactionId}`;
};
2 changes: 1 addition & 1 deletion client/src/app/routes/stardust/OutputPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const OutputPage: React.FC<RouteComponentProps<OutputPageProps>> = ({
} = outputMetadata ?? {};

const isTransactionFromStardustGenesis = TransactionsHelper.isTransactionFromIotaStardustGenesis(network, milestoneIndexBooked ?? 0);
const transactionLink = getTransactionLink(network, transactionId ?? "", isTransactionFromStardustGenesis);
const transactionLink = getTransactionLink(network, transactionId ?? "", isTransactionFromStardustGenesis, outputId);

return (
(output && (
Expand Down
2 changes: 1 addition & 1 deletion client/src/helpers/stardust/transactionsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const HEX_PARTICIPATE = "0x5041525449434950415445";
*/
export const STARDUST_GENESIS_MILESTONE = 7669900;

export const STARDUST_SUPPLY_INCREASE_TRANSACTION_ID = "0xb191c4bc825ac6983789e50545d5ef07a1d293a98ad974fc9498cb18";
export const STARDUST_SUPPLY_INCREASE_OUTPUT_TICKER = "0xb191c4bc825ac6983789e50545d5ef07a1d293a98ad974fc9498cb18";

export class TransactionsHelper {
public static async getInputsAndOutputs(
Expand Down

0 comments on commit 3ce0422

Please sign in to comment.