-
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: Basic support for NFT address page (#1091)
* chore: Extract AddressNotFound to own component * feat: Make AddressPage.tsx an entrypoint for address pages. Refactor useAddressPageState to be Account address specific. Add AccountAddressView. * feat: Add support for Ed25519 address page (state hook and tsx component) * fix: Fix OutputPage for Nft and Account outputs * feat: Support Nft address page (basic). Add custom hooks for nft address page and load nft output details.
- Loading branch information
Showing
20 changed files
with
297 additions
and
27 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
api/src/models/api/nova/IAccountRequest.ts → ...models/api/nova/IAccountDetailsRequest.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export interface IAccountRequest { | ||
export interface IAccountDetailsRequest { | ||
/** | ||
* The network to search on. | ||
*/ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export interface INftDetailsRequest { | ||
/** | ||
* The network to search on. | ||
*/ | ||
network: string; | ||
|
||
/** | ||
* The nft id to get the nft output details for. | ||
*/ | ||
nftId: string; | ||
} |
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,11 @@ | ||
/* eslint-disable import/no-unresolved */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-argument */ | ||
import { OutputResponse } from "@iota/sdk-nova"; | ||
import { IResponse } from "./IResponse"; | ||
|
||
export interface INftDetailsResponse extends IResponse { | ||
/** | ||
* The nft output details response. | ||
*/ | ||
nftOutputDetails?: OutputResponse; | ||
} |
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
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,29 @@ | ||
import { ServiceFactory } from "../../../factories/serviceFactory"; | ||
import { INftDetailsRequest } from "../../../models/api/nova/INftDetailsRequest"; | ||
import { INftDetailsResponse } from "../../../models/api/nova/INftDetailsResponse"; | ||
import { IConfiguration } from "../../../models/configuration/IConfiguration"; | ||
import { NOVA } from "../../../models/db/protocolVersion"; | ||
import { NetworkService } from "../../../services/networkService"; | ||
import { NovaApiService } from "../../../services/nova/novaApiService"; | ||
import { ValidationHelper } from "../../../utils/validationHelper"; | ||
|
||
/** | ||
* Get nft output details by Nft id | ||
* @param config The configuration. | ||
* @param request The request. | ||
* @returns The response. | ||
*/ | ||
export async function get(config: IConfiguration, request: INftDetailsRequest): Promise<INftDetailsResponse> { | ||
const networkService = ServiceFactory.get<NetworkService>("network"); | ||
const networks = networkService.networkNames(); | ||
ValidationHelper.oneOf(request.network, networks, "network"); | ||
ValidationHelper.string(request.nftId, "nftId"); | ||
|
||
const networkConfig = networkService.get(request.network); | ||
|
||
if (networkConfig.protocolVersion !== NOVA) { | ||
return {}; | ||
} | ||
const novaApiService = ServiceFactory.get<NovaApiService>(`api-service-${networkConfig.network}`); | ||
return novaApiService.nftDetails(request.nftId); | ||
} |
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
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,52 @@ | ||
import { NftAddress } from "@iota/sdk-wasm-nova/web"; | ||
import React from "react"; | ||
import { useNftAddressState } from "~/helpers/nova/hooks/useNftAddressState"; | ||
import Spinner from "../../Spinner"; | ||
import Bech32Address from "../../stardust/address/Bech32Address"; | ||
import AssociatedOutputs from "./section/association/AssociatedOutputs"; | ||
|
||
interface NftAddressViewProps { | ||
nftAddress: NftAddress; | ||
} | ||
|
||
const NftAddressView: React.FC<NftAddressViewProps> = ({ nftAddress }) => { | ||
const { nftAddressDetails, isNftDetailsLoading } = useNftAddressState(nftAddress); | ||
const isPageLoading = isNftDetailsLoading; | ||
|
||
return ( | ||
<div className="address-page"> | ||
<div className="wrapper"> | ||
{nftAddressDetails && ( | ||
<div className="inner"> | ||
<div className="addr--header"> | ||
<div className="row middle"> | ||
<h1>{nftAddressDetails.typeLabel?.replace("Ed25519", "Address")}</h1> | ||
</div> | ||
{isPageLoading && <Spinner />} | ||
</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={nftAddressDetails} 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={nftAddressDetails} /> | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default NftAddressView; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Reducer, useEffect, useReducer } from "react"; | ||
import { NftAddress, NftOutput } from "@iota/sdk-wasm-nova/web"; | ||
import { IBech32AddressDetails } from "~/models/api/IBech32AddressDetails"; | ||
import { useNftDetails } from "./useNftDetails"; | ||
import { useLocation, useParams } from "react-router-dom"; | ||
import { AddressRouteProps } from "~/app/routes/AddressRouteProps"; | ||
import { useNetworkInfoNova } from "../networkInfo"; | ||
import { Bech32AddressHelper } from "~/helpers/nova/bech32AddressHelper"; | ||
|
||
export interface INftAddressState { | ||
nftAddressDetails: IBech32AddressDetails | null; | ||
nftOutput: NftOutput | null; | ||
isNftDetailsLoading: boolean; | ||
} | ||
|
||
const initialState = { | ||
nftAddressDetails: null, | ||
nftOutput: null, | ||
isNftDetailsLoading: true, | ||
}; | ||
|
||
/** | ||
* Route Location Props | ||
*/ | ||
interface IAddressPageLocationProps { | ||
addressDetails: IBech32AddressDetails; | ||
} | ||
|
||
export const useNftAddressState = (address: NftAddress): INftAddressState => { | ||
const location = useLocation(); | ||
const { network } = useParams<AddressRouteProps>(); | ||
const { bech32Hrp } = useNetworkInfoNova((s) => s.networkInfo); | ||
const [state, setState] = useReducer<Reducer<INftAddressState, Partial<INftAddressState>>>( | ||
(currentState, newState) => ({ ...currentState, ...newState }), | ||
initialState, | ||
); | ||
|
||
const { nftOutput, isLoading: isNftDetailsLoading } = useNftDetails(network, address.nftId); | ||
|
||
useEffect(() => { | ||
const locationState = location.state as IAddressPageLocationProps; | ||
const { addressDetails } = locationState?.addressDetails | ||
? locationState | ||
: { addressDetails: Bech32AddressHelper.buildAddress(bech32Hrp, address) }; | ||
|
||
setState({ | ||
...initialState, | ||
nftAddressDetails: addressDetails, | ||
}); | ||
}, []); | ||
|
||
useEffect(() => { | ||
setState({ | ||
nftOutput, | ||
isNftDetailsLoading, | ||
}); | ||
}, [nftOutput, isNftDetailsLoading]); | ||
|
||
return { | ||
nftAddressDetails: state.nftAddressDetails, | ||
nftOutput: state.nftOutput, | ||
isNftDetailsLoading: state.isNftDetailsLoading, | ||
}; | ||
}; |
Oops, something went wrong.