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: Add Nft redirect route (Nova) #1441

Merged
merged 2 commits into from
Apr 24, 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
6 changes: 4 additions & 2 deletions client/src/app/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import StardustBlock from "./routes/stardust/Block";
import StardustFoundry from "./routes/stardust/Foundry";
import { Landing as StardustLanding } from "./routes/stardust/landing/Landing";
import NovaLanding from "./routes/nova/landing/Landing";
import NftRedirectRoute from "./routes/stardust/NftRedirectRoute";
import NftRedirectRouteStardust from "./routes/stardust/NftRedirectRoute";
import NftRedirectRouteNova from "./routes/nova/NftRedirectRoute";
import StardustOutputList from "./routes/stardust/OutputList";
import StardustOutputPage from "./routes/stardust/OutputPage";
import NovaBlockPage from "./routes/nova/Block";
Expand Down Expand Up @@ -169,7 +170,7 @@ const buildAppRoutes = (protocolVersion: string, withNetworkContext: (wrappedCom
<Route path="/:network/visualizer/" key={keys.next().value} component={StardustVisualizer} />,
<Route path="/:network/search/:query?" key={keys.next().value} component={StardustSearch} />,
<Route path="/:network/addr/:address" key={keys.next().value} component={StardustAddressPage} />,
<Route path="/:network/nft/:nftId" key={keys.next().value} component={NftRedirectRoute} />,
<Route path="/:network/nft/:nftId" key={keys.next().value} component={NftRedirectRouteStardust} />,
<Route path="/:network/block/:blockId" key={keys.next().value} component={StardustBlock} />,
<Route path="/:network/transaction/:transactionId" key={keys.next().value} component={StardustTransactionPage} />,
<Route path="/:network/output/:outputId" key={keys.next().value} component={StardustOutputPage} />,
Expand All @@ -189,6 +190,7 @@ const buildAppRoutes = (protocolVersion: string, withNetworkContext: (wrappedCom
<Route path="/:network/epoch/:epochIndex" key={keys.next().value} component={NovaEpochPage} />,
<Route path="/:network/transaction/:transactionId" key={keys.next().value} component={NovaTransactionPage} />,
<Route path="/:network/foundry/:foundryId" key={keys.next().value} component={NovaFoundryPage} />,
<Route path="/:network/nft/:nftId" key={keys.next().value} component={NftRedirectRouteNova} />,
<Route path="/:network/statistics" key={keys.next().value} component={NovaStatisticsPage} />,
<Route path="/:network/validators" key={keys.next().value} component={ValidatorsPage} />,
<Route path="/:network/outputs" key={keys.next().value} component={NovaOutputsPage} />,
Expand Down
36 changes: 36 additions & 0 deletions client/src/app/routes/nova/NftRedirectRoute.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { AddressType } from "@iota/sdk-wasm-nova/web";
import React from "react";
import { Redirect, RouteComponentProps } from "react-router-dom";
import { AddressHelper } from "~helpers/nova/addressHelper";
import { useNetworkInfoNova } from "~/helpers/nova/networkInfo";

interface NftRedirectRouteProps {
/**
* The network.
*/
network: string;

/**
* The nftId to redirect.
*/
nftId: string;
}

const ADDRESS_ROUTE = "addr";

const NftRedirectRoute: React.FC<RouteComponentProps<NftRedirectRouteProps>> = ({
match: {
params: { network, nftId },
},
}) => {
const { bech32Hrp } = useNetworkInfoNova((s) => s.networkInfo);
const nftAddress = AddressHelper.buildAddress(bech32Hrp, nftId, AddressType.Nft);
const redirectState = {
addressDetails: nftAddress,
};
const routeParam = nftAddress.bech32;
const redirect = `/${network}/${ADDRESS_ROUTE}/${routeParam}`;
return <Redirect to={{ pathname: redirect, state: redirectState }} />;
};

export default NftRedirectRoute;
Loading