Skip to content

Commit

Permalink
fix: Fix PR feedback (Improve usage of networkName from useNetworkInf…
Browse files Browse the repository at this point in the history
…oNova)
  • Loading branch information
msarcev committed Jan 25, 2024
1 parent a704189 commit caf1739
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 27 deletions.
8 changes: 4 additions & 4 deletions api/src/services/nova/novaApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ export class NovaApi {
* @returns The account details.
*/
public static async accountDetails(network: INetwork, accountId: string): Promise<IAccountResponse | undefined> {
const aliasOutputId = await this.tryFetchNodeThenPermanode<string, string>(accountId, "accountOutputId", network);
const accountOutputId = await this.tryFetchNodeThenPermanode<string, string>(accountId, "accountOutputId", network);

if (aliasOutputId) {
const outputResponse = await this.outputDetails(network, aliasOutputId);
if (accountOutputId) {
const outputResponse = await this.outputDetails(network, accountOutputId);
return outputResponse.error ? { error: outputResponse.error } : { accountDetails: outputResponse.output };
}

return { message: "Alias output not found" };
return { message: "Account output not found" };
}

/**
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/AppUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const populateNetworkInfoNova = (networkName: string) => {
}) ?? null;
const setNetworkInfoNova = useNetworkInfoNova.getState().setNetworkInfo;
setNetworkInfoNova({
name: nodeInfo?.name ?? "",
name: networkName,
tokenInfo: nodeInfo?.baseToken ?? {},
protocolVersion: protocolInfo?.parameters.version ?? -1,
bech32Hrp: protocolInfo?.parameters.bech32Hrp ?? "",
Expand Down
6 changes: 3 additions & 3 deletions client/src/app/components/nova/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
/* eslint-disable jsdoc/require-returns */
import { Utils } from "@iota/sdk-wasm-nova/web";
import classNames from "classnames";
import React, { useContext, useState } from "react";
import React, { useState } from "react";
import { useHistory, Link } from "react-router-dom";
import Bech32Address from "../stardust/address/Bech32Address";
import { useNetworkInfoNova } from "~helpers/nova/networkInfo";
import OutputView from "./OutputView";
import DropdownIcon from "~assets/dropdown-arrow.svg?react";
import { formatAmount } from "~helpers/stardust/valueFormatHelper";
import { IInput } from "~models/api/nova/IInput";
import NetworkContext from "../../context/NetworkContext";

interface InputProps {
/**
Expand All @@ -27,7 +27,7 @@ interface InputProps {
*/
const Input: React.FC<InputProps> = ({ input, network }) => {
const history = useHistory();
const { tokenInfo } = useContext(NetworkContext);
const { tokenInfo } = useNetworkInfoNova((s) => s.networkInfo);
const [isExpanded, setIsExpanded] = useState(false);
const [isFormattedBalance, setIsFormattedBalance] = useState(true);

Expand Down
5 changes: 2 additions & 3 deletions client/src/app/components/nova/OutputView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,17 @@ import { Bech32AddressHelper } from "~/helpers/nova/bech32AddressHelper";
import "./OutputView.scss";

interface OutputViewProps {
network: string;
outputId: string;
output: Output;
showCopyAmount: boolean;
isPreExpanded?: boolean;
isLinksDisabled?: boolean;
}

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

const aliasOrNftBech32 = buildAddressForAliasOrNft(outputId, output, bech32Hrp);
const outputIdTransactionPart = `${outputId.slice(0, 8)}....${outputId.slice(-8, -4)}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ import React, { useEffect, useState } from "react";
import { AssociatedOutputTab, buildAssociatedOutputsTabs, outputTypeToAssociations } from "./AssociatedOutputsUtils";
import AssociationSection from "./AssociationSection";
import { useAssociatedOutputs } from "~helpers/nova/hooks/useAssociatedOutputs";
import { useNetworkInfoNova } from "~helpers/nova/networkInfo";
import { IBech32AddressDetails } from "~models/api/IBech32AddressDetails";
import { AssociationType, IAssociation } from "~models/api/nova/IAssociationsResponse";
import "./AssociatedOutputs.scss";

interface AssociatedOutputsProps {
/**
* The network in context.
*/
readonly network: string;
/**
* Address details
*/
Expand All @@ -26,7 +23,8 @@ interface AssociatedOutputsProps {
readonly setIsLoading?: (isLoading: boolean) => void;
}

const AssociatedOutputs: React.FC<AssociatedOutputsProps> = ({ network, addressDetails, setOutputCount, setIsLoading }) => {
const AssociatedOutputs: React.FC<AssociatedOutputsProps> = ({ addressDetails, setOutputCount, setIsLoading }) => {
const { name: network } = useNetworkInfoNova((s) => s.networkInfo);
const [currentTab, setCurrentTab] = useState<AssociatedOutputTab>("Basic");
const [associations, isLoading] = useAssociatedOutputs(network, addressDetails, setOutputCount);
const [tabsToRender, setTabsToRender] = useState<AssociatedOutputTab[]>([]);
Expand Down Expand Up @@ -69,7 +67,6 @@ const AssociatedOutputs: React.FC<AssociatedOutputsProps> = ({ network, addressD
);
return (
<AssociationSection
network={network}
key={`${currentTab}-${idx}`}
association={associationType}
outputIds={targetAssociation?.outputIds}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const buildAssociatedOutputsTabs = (associations: IAssociation[]): Associ
tabs.push("Anchor");
}
if (associations.some((association) => AssociationType[association.type].startsWith("DELEGATION"))) {
tabs.push("Account");
tabs.push("Delegation");
}
if (associations.some((association) => AssociationType[association.type].startsWith("FOUNDRY"))) {
tabs.push("Foundry");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { useNetworkInfoNova } from "~/helpers/nova/networkInfo";
import "./AssociationSection.scss";

interface IAssociatedSectionProps {
readonly network: string;
readonly association: AssociationType;
readonly outputIds: string[] | undefined;
}
Expand All @@ -24,8 +23,8 @@ interface IOutputTableItem {

const PAGE_SIZE = 10;

const AssociationSection: React.FC<IAssociatedSectionProps> = ({ network, association, outputIds }) => {
const { tokenInfo } = useNetworkInfoNova((s) => s.networkInfo);
const AssociationSection: React.FC<IAssociatedSectionProps> = ({ association, outputIds }) => {
const { tokenInfo, name: network } = useNetworkInfoNova((s) => s.networkInfo);
const [isExpanded, setIsExpanded] = useState(false);
const [isFormatBalance, setIsFormatBalance] = useState(false);
const [loadMoreCounter, setLoadMoreCounter] = useState<number | undefined>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from "react";
import Modal from "~/app/components/Modal";
import Unlocks from "~/app/components/nova/Unlocks";
import OutputView from "~/app/components/nova/OutputView";
import { useNetworkInfoNova } from "~helpers/nova/networkInfo";
import transactionPayloadMessage from "~assets/modals/stardust/block/transaction-payload.json";
import { IInput } from "~/models/api/nova/IInput";
import Input from "~/app/components/nova/Input";
Expand All @@ -14,7 +15,8 @@ interface SignedTransactionPayloadProps {
}

const SignedTransactionPayload: React.FC<SignedTransactionPayloadProps> = ({ payload, inputs, header }) => {
const { networkId, outputs } = payload.transaction;
const { outputs } = payload.transaction;
const { name: network } = useNetworkInfoNova(s => s.networkInfo);
const transactionId = Utils.transactionId(payload);

return (
Expand All @@ -36,7 +38,7 @@ const SignedTransactionPayload: React.FC<SignedTransactionPayloadProps> = ({ pay
</div>
<div className="transaction-payload_outputs card--content">
{inputs.map((input, idx) => (
<Input key={idx} network={networkId} input={input} />
<Input key={idx} network={network} input={input} />
))}
<Unlocks unlocks={payload.unlocks} />
</div>
Expand Down
4 changes: 2 additions & 2 deletions client/src/app/routes/nova/AddressPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import "./AddressPage.scss";

const AddressPage: React.FC<RouteComponentProps<AddressRouteProps>> = ({
match: {
params: { network, address },
params: { address },
},
}) => {
const [state] = useAddressPageState();
Expand Down Expand Up @@ -51,7 +51,7 @@ const AddressPage: React.FC<RouteComponentProps<AddressRouteProps>> = ({
<div className="row middle">
<h2>Associated Outputs</h2>
</div>
<AssociatedOutputs network={network} addressDetails={bech32AddressDetails} />
<AssociatedOutputs addressDetails={bech32AddressDetails} />
</div>
</div>
)}
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/routes/nova/Block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import taggedDataPayloadInfo from "~assets/modals/stardust/block/tagged-data-pay
import transactionPayloadInfo from "~assets/modals/stardust/block/transaction-payload.json";
import { useBlockMetadata } from "~/helpers/nova/hooks/useBlockMetadata";
import TransactionMetadataSection from "~/app/components/nova/block/section/TransactionMetadataSection";

export interface BlockProps {
/**
* The network to lookup.
Expand All @@ -33,7 +34,6 @@ export interface BlockProps {
}

const Block: React.FC<RouteComponentProps<BlockProps>> = ({
history,
match: {
params: { network, blockId },
},
Expand Down
1 change: 0 additions & 1 deletion client/src/helpers/nova/hooks/useAddressPageState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export const useAddressPageState = (): [IAddressState, React.Dispatch<Partial<IA
initialState,
);

// const addressBech32: string | null = state.bech32AddressDetails?.bech32 ?? null;
const addressHex: string | null = state.bech32AddressDetails?.hex ?? null;
const addressType: number | null = state.bech32AddressDetails?.type ?? null;

Expand Down

0 comments on commit caf1739

Please sign in to comment.