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: integrate mana into output page #1146

Merged
merged 6 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
49 changes: 49 additions & 0 deletions client/src/app/components/nova/KeyValueEntries.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import classNames from "classnames";
import React, { useState } from "react";
import { IKeyValue, IKeyValueEntries } from "~/app/lib/interfaces";
import DropdownIcon from "~assets/dropdown-arrow.svg?react";

function KeyValuePair({ label, value, orientation }: IKeyValue): React.JSX.Element {
return (
<>
{value !== undefined && value !== null && (
<>
<div className="card--label">{label}</div>
<div
className={classNames(
"card--value",
"row",
{ "margin-b-0": orientation === "row" },
{ "padding-l-8": orientation === "row" },
)}
>
{value}
</div>
</>
)}
</>
);
}

export default function KeyValueEntries({ isPreExpanded, label, value, entries }: IKeyValueEntries): React.JSX.Element {
const [isExpanded, setIsExpanded] = useState<boolean>(isPreExpanded ?? false);

return (
<div>
<div className="card--content__input card--value row middle" onClick={() => setIsExpanded(!isExpanded)}>
<div className={classNames("margin-r-t", "card--content--dropdown", { opened: isExpanded })}>
<DropdownIcon />
</div>
<KeyValuePair label={label} value={value} orientation="row" />
</div>

{entries && entries.length > 0 && isExpanded && (
<div className="padding-l-t left-border">
{entries.map((entry, idx) => (
<KeyValuePair key={idx} {...entry} />
))}
</div>
)}
</div>
);
}
2 changes: 2 additions & 0 deletions client/src/app/components/nova/OutputView.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@import "../../../scss/media-queries";
@import "../../../scss/variables";
@import "../../../scss/mixins";
@import "../../../scss/fonts";

.card--content__output {
padding: 0 30px;
Expand Down
15 changes: 7 additions & 8 deletions client/src/app/components/nova/OutputView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import classNames from "classnames";
import {
Output,
OutputType,
BasicOutput,
CommonOutput,
AccountOutput,
AnchorOutput,
Expand All @@ -23,6 +22,8 @@ import FeatureView from "./FeaturesView";
import TruncatedId from "../stardust/TruncatedId";
import { HexHelper } from "~/helpers/stardust/hexHelper";
import bigInt from "big-integer";
import { OutputManaDetails, getManaKeyValueEntries } from "~/helpers/nova/manaUtils";
import KeyValueEntries from "./KeyValueEntries";
import "./OutputView.scss";

interface OutputViewProps {
Expand All @@ -31,16 +32,18 @@ interface OutputViewProps {
showCopyAmount: boolean;
isPreExpanded?: boolean;
isLinksDisabled?: boolean;
manaDetails: OutputManaDetails | null;
}

const OutputView: React.FC<OutputViewProps> = ({ outputId, output, showCopyAmount, isPreExpanded, isLinksDisabled }) => {
const OutputView: React.FC<OutputViewProps> = ({ outputId, output, showCopyAmount, isPreExpanded, isLinksDisabled, manaDetails }) => {
const [isExpanded, setIsExpanded] = useState(isPreExpanded ?? false);
const [isFormattedBalance, setIsFormattedBalance] = useState(true);
const { bech32Hrp, name: network } = useNetworkInfoNova((s) => s.networkInfo);

const aliasOrNftBech32 = buildAddressForAliasOrNft(outputId, output, bech32Hrp);
const outputIdTransactionPart = `${outputId.slice(0, 8)}....${outputId.slice(-8, -4)}`;
const outputIdIndexPart = outputId.slice(-4);
const manaEntries = getManaKeyValueEntries(manaDetails);

const header = (
<div onClick={() => setIsExpanded(!isExpanded)} className="card--value card-header--wrapper">
Expand Down Expand Up @@ -158,12 +161,8 @@ const OutputView: React.FC<OutputViewProps> = ({ outputId, output, showCopyAmoun
{(output.type === OutputType.Basic ||
output.type === OutputType.Account ||
output.type === OutputType.Anchor ||
output.type === OutputType.Nft) && (
<React.Fragment>
<div className="card--label">Stored mana:</div>
<div className="card--value row">{(output as BasicOutput).mana?.toString()}</div>
</React.Fragment>
)}
output.type === OutputType.Nft) &&
manaDetails?.totalMana && <KeyValueEntries isPreExpanded={true} {...manaEntries} />}
{output.type === OutputType.Delegation && (
<React.Fragment>
<div className="card--label">Delegated amount:</div>
Expand Down
1 change: 1 addition & 0 deletions client/src/app/lib/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./routes.interfaces";
export * from "./key-value.interfaces";
10 changes: 10 additions & 0 deletions client/src/app/lib/interfaces/key-value.interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface IKeyValue {
orientation?: "row" | "column";
label: string;
value: string | number | null | undefined;
}

export interface IKeyValueEntries extends IKeyValue {
isPreExpanded?: boolean;
entries?: IKeyValue[];
}
45 changes: 7 additions & 38 deletions client/src/app/routes/nova/OutputPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ const OutputPage: React.FC<RouteComponentProps<OutputPageProps>> = ({
</div>
<div className="section">
<div className="card">
<OutputView outputId={outputId} output={output} showCopyAmount={true} isPreExpanded={true} />
<OutputView
outputId={outputId}
output={output}
showCopyAmount={true}
isPreExpanded={true}
manaDetails={outputManaDetails}
/>
</div>

<div className="section--header row row--tablet-responsive middle space-between">
Expand Down Expand Up @@ -140,43 +146,6 @@ const OutputPage: React.FC<RouteComponentProps<OutputPageProps>> = ({
</div>
</div>
)}

{outputManaDetails && (
<>
<div className="section--data">
<div className="label">Stored mana</div>
<div className="value code row middle">
<span className="margin-r-t">{outputManaDetails.storedMana}</span>
</div>
</div>
<div className="section--data">
<div className="label">Stored mana (decayed)</div>
<div className="value code row middle">
<span className="margin-r-t">{outputManaDetails.storedManaDecayed}</span>
</div>
</div>
<div className="section--data">
<div className="label">Potential mana</div>
<div className="value code row middle">
<span className="margin-r-t">{outputManaDetails.potentialMana}</span>
</div>
</div>
{outputManaDetails.delegationRewards && (
<div className="section--data">
<div className="label">Mana rewards</div>
<div className="value code row middle">
<span className="margin-r-t">{outputManaDetails.delegationRewards}</span>
</div>
</div>
)}
<div className="section--data">
<div className="label">Total mana</div>
<div className="value code row middle">
<span className="margin-r-t">{outputManaDetails.totalMana}</span>
</div>
</div>
</>
)}
</div>
</div>
</div>
Expand Down
29 changes: 29 additions & 0 deletions client/src/helpers/nova/manaUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BasicOutput, ManaRewardsResponse, Output, ProtocolParameters, Utils } from "@iota/sdk-wasm-nova/web";
import { IKeyValueEntries } from "~/app/lib/interfaces";

export interface OutputManaDetails {
storedMana: string;
Expand Down Expand Up @@ -33,3 +34,31 @@ export function buildManaDetailsForOutput(
totalMana: totalMana.toString(),
};
}

export function getManaKeyValueEntries(manaDetails: OutputManaDetails | null): IKeyValueEntries {
const showDecayMana = manaDetails?.storedMana && manaDetails?.storedManaDecayed;
const decay = showDecayMana ? Number(manaDetails?.storedMana ?? 0) - Number(manaDetails?.storedManaDecayed ?? 0) : undefined;

return {
label: "Mana:",
value: manaDetails?.totalMana,
entries: [
{
label: "Stored:",
value: manaDetails?.storedMana,
},
{
label: "Decay:",
value: decay,
},
{
label: "Potential:",
value: manaDetails?.potentialMana,
},
{
label: "Delegation Rewards:",
value: manaDetails?.delegationRewards,
},
],
};
}
Loading