diff --git a/client/src/app/AppUtils.tsx b/client/src/app/AppUtils.tsx index e03226443..cb6d9eb89 100644 --- a/client/src/app/AppUtils.tsx +++ b/client/src/app/AppUtils.tsx @@ -157,14 +157,20 @@ export const populateNetworkInfoNova = (networkName: string) => { nodeInfo?.protocolParameters.reduce((params, cur) => { return params.startEpoch > cur.startEpoch ? params : cur; }) ?? null; - const setNetworkInfoNova = useNetworkInfoNova.getState().setNetworkInfo; - setNetworkInfoNova({ - name: networkName, - tokenInfo: nodeInfo?.baseToken ?? {}, - protocolVersion: protocolInfo?.parameters.version ?? -1, - protocolInfo, - latestConfirmedSlot: nodeInfo?.status?.latestConfirmedBlockSlot ?? -1, - bech32Hrp: protocolInfo?.parameters.bech32Hrp ?? "", - }); + + const networkInfoState = useNetworkInfoNova.getState(); + const currentNetworkInfo = networkInfoState.networkInfo; + if (currentNetworkInfo?.name !== networkName || currentNetworkInfo?.protocolInfo === null) { + const setNetworkInfoNova = networkInfoState.setNetworkInfo; + + setNetworkInfoNova({ + name: networkName, + tokenInfo: nodeInfo?.baseToken ?? {}, + protocolVersion: protocolInfo?.parameters.version ?? -1, + protocolInfo, + latestConfirmedSlot: nodeInfo?.status?.latestConfirmedBlockSlot ?? -1, + bech32Hrp: protocolInfo?.parameters.bech32Hrp ?? "", + }); + } } }; diff --git a/client/src/app/components/nova/address/ImplicitAccountCreationAddressView.tsx b/client/src/app/components/nova/address/ImplicitAccountCreationAddressView.tsx new file mode 100644 index 000000000..eee1977ba --- /dev/null +++ b/client/src/app/components/nova/address/ImplicitAccountCreationAddressView.tsx @@ -0,0 +1,49 @@ +import { ImplicitAccountCreationAddress } from "@iota/sdk-wasm-nova/web"; +import React from "react"; +import { useImplicitAccountCreationAddressState } from "~/helpers/nova/hooks/useImplicitAccountCreationAddressState"; +import Bech32Address from "./Bech32Address"; +import AssociatedOutputs from "./section/association/AssociatedOutputs"; + +interface ImplicitAccountCreationAddressViewProps { + implicitAccountCreationAddress: ImplicitAccountCreationAddress; +} + +const ImplicitAccountCreationAddressView: React.FC = ({ implicitAccountCreationAddress }) => { + const { implicitAccountCreationAddressDetails } = useImplicitAccountCreationAddressState(implicitAccountCreationAddress); + + return ( +
+
+ {implicitAccountCreationAddressDetails && ( +
+
+
+

{implicitAccountCreationAddressDetails.label?.replace("Ed25519", "Address")}

+
+
+
+
+
+

General

+
+
+
+
+ +
+
+
+
+
+

Associated Outputs

+
+ +
+
+ )} +
+
+ ); +}; + +export default ImplicitAccountCreationAddressView; diff --git a/client/src/app/routes/nova/AddressPage.tsx b/client/src/app/routes/nova/AddressPage.tsx index 7236ad519..ac13d7727 100644 --- a/client/src/app/routes/nova/AddressPage.tsx +++ b/client/src/app/routes/nova/AddressPage.tsx @@ -1,4 +1,13 @@ -import { AccountAddress, Address, AddressType, AnchorAddress, Ed25519Address, NftAddress, Utils } from "@iota/sdk-wasm-nova/web"; +import { + AccountAddress, + Address, + AddressType, + AnchorAddress, + Ed25519Address, + ImplicitAccountCreationAddress, + NftAddress, + Utils, +} from "@iota/sdk-wasm-nova/web"; import React from "react"; import { RouteComponentProps } from "react-router-dom"; import AddressNotFoundPage from "~/app/components/nova/address/AddressNotFoundPage"; @@ -7,6 +16,7 @@ import AccountAddressView from "~/app/components/nova/address/AccountAddressView import Ed25519AddressView from "~/app/components/nova/address/Ed25519AddressView"; import NftAddressView from "~/app/components/nova/address/NftAddressView"; import AnchorAddressView from "~/app/components/nova/address/AnchorAddressView"; +import ImplicitAccountCreationAddressView from "~/app/components/nova/address/ImplicitAccountCreationAddressView"; import "./AddressPage.scss"; const AddressPage: React.FC> = ({ @@ -32,6 +42,10 @@ const AddressPage: React.FC> = ({ return ; case AddressType.Anchor: return ; + case AddressType.ImplicitAccountCreation: + return ( + + ); default: return (
diff --git a/client/src/helpers/nova/addressHelper.ts b/client/src/helpers/nova/addressHelper.ts index 5e3478138..55baf3641 100644 --- a/client/src/helpers/nova/addressHelper.ts +++ b/client/src/helpers/nova/addressHelper.ts @@ -108,7 +108,7 @@ export class AddressHelper { } else if (addressType === AddressType.Nft) { bech32 = Utils.nftIdToBech32(hex, hrp); } else if (addressType === AddressType.Anchor) { - // TODO Utils.anchorIdToBech32 does not exist ??? + // TODO Utils.anchorIdToBech32 does not exist https://github.com/iotaledger/iota-sdk/issues/1973 bech32 = Utils.accountIdToBech32(hex, hrp); } else if (addressType === AddressType.ImplicitAccountCreation) { bech32 = Utils.hexToBech32(hex, hrp); diff --git a/client/src/helpers/nova/hooks/useImplicitAccountCreationAddressState.ts b/client/src/helpers/nova/hooks/useImplicitAccountCreationAddressState.ts new file mode 100644 index 000000000..6f7131cc9 --- /dev/null +++ b/client/src/helpers/nova/hooks/useImplicitAccountCreationAddressState.ts @@ -0,0 +1,46 @@ +import { ImplicitAccountCreationAddress } from "@iota/sdk-wasm-nova/web"; +import { Reducer, useEffect, useReducer } from "react"; +import { useLocation } from "react-router-dom"; +import { useNetworkInfoNova } from "../networkInfo"; +import { IAddressDetails } from "~/models/api/nova/IAddressDetails"; +import { AddressHelper } from "~/helpers/nova/addressHelper"; + +export interface IImplicitAccountCreationAddressState { + implicitAccountCreationAddressDetails: IAddressDetails | null; +} + +const initialState = { + implicitAccountCreationAddressDetails: null, +}; + +/** + * Route Location Props + */ +interface IAddressPageLocationProps { + addressDetails: IAddressDetails; +} + +export const useImplicitAccountCreationAddressState = (address: ImplicitAccountCreationAddress) => { + const location = useLocation(); + const { bech32Hrp } = useNetworkInfoNova((s) => s.networkInfo); + const [state, setState] = useReducer>>( + (currentState, newState) => ({ ...currentState, ...newState }), + initialState, + ); + + useEffect(() => { + const locationState = location.state as IAddressPageLocationProps; + const { addressDetails } = locationState?.addressDetails + ? locationState + : { addressDetails: AddressHelper.buildAddress(bech32Hrp, address) }; + + setState({ + ...initialState, + implicitAccountCreationAddressDetails: addressDetails, + }); + }, []); + + return { + implicitAccountCreationAddressDetails: state.implicitAccountCreationAddressDetails, + }; +};