-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add ImplicitAccountCreation address page case (#1098)
* feat: Add ImplicitAccountCreation address page case * fix: Set networkInfoNova only if needed (prevents React set state on unmounted component issue)
- Loading branch information
Showing
5 changed files
with
126 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
client/src/app/components/nova/address/ImplicitAccountCreationAddressView.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ImplicitAccountCreationAddressViewProps> = ({ implicitAccountCreationAddress }) => { | ||
const { implicitAccountCreationAddressDetails } = useImplicitAccountCreationAddressState(implicitAccountCreationAddress); | ||
|
||
return ( | ||
<div className="address-page"> | ||
<div className="wrapper"> | ||
{implicitAccountCreationAddressDetails && ( | ||
<div className="inner"> | ||
<div className="addr--header"> | ||
<div className="row middle"> | ||
<h1>{implicitAccountCreationAddressDetails.label?.replace("Ed25519", "Address")}</h1> | ||
</div> | ||
</div> | ||
<div className="section no-border-bottom padding-b-0"> | ||
<div className="section--header"> | ||
<div className="row middle"> | ||
<h2>General</h2> | ||
</div> | ||
</div> | ||
<div className="general-content"> | ||
<div className="section--data"> | ||
<Bech32Address addressDetails={implicitAccountCreationAddressDetails} advancedMode={true} /> | ||
</div> | ||
</div> | ||
</div> | ||
<div className="section no-border-bottom padding-b-0"> | ||
<div className="row middle"> | ||
<h2>Associated Outputs</h2> | ||
</div> | ||
<AssociatedOutputs addressDetails={implicitAccountCreationAddressDetails} /> | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ImplicitAccountCreationAddressView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
client/src/helpers/nova/hooks/useImplicitAccountCreationAddressState.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Reducer<IImplicitAccountCreationAddressState, Partial<IImplicitAccountCreationAddressState>>>( | ||
(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, | ||
}; | ||
}; |