|
|
@@ -1,3 +1,4 @@
|
|
|
+import { ChainId } from "@certusone/wormhole-sdk";
|
|
|
import {
|
|
|
Container,
|
|
|
Step,
|
|
|
@@ -5,11 +6,12 @@ import {
|
|
|
StepContent,
|
|
|
Stepper,
|
|
|
} from "@material-ui/core";
|
|
|
-import { useEffect } from "react";
|
|
|
+import { useEffect, useMemo } from "react";
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
|
+import { useLocation } from "react-router";
|
|
|
import useCheckIfWormholeWrapped from "../../hooks/useCheckIfWormholeWrapped";
|
|
|
import useFetchTargetAsset from "../../hooks/useFetchTargetAsset";
|
|
|
-import { setStep } from "../../store/nftSlice";
|
|
|
+import { setSourceChain, setStep, setTargetChain } from "../../store/nftSlice";
|
|
|
import {
|
|
|
selectNFTActiveStep,
|
|
|
selectNFTIsRedeemComplete,
|
|
|
@@ -17,6 +19,7 @@ import {
|
|
|
selectNFTIsSendComplete,
|
|
|
selectNFTIsSending,
|
|
|
} from "../../store/selectors";
|
|
|
+import { CHAINS_WITH_NFT_SUPPORT } from "../../utils/consts";
|
|
|
import Redeem from "./Redeem";
|
|
|
import RedeemPreview from "./RedeemPreview";
|
|
|
import Send from "./Send";
|
|
|
@@ -37,6 +40,39 @@ function NFT() {
|
|
|
const isRedeemComplete = useSelector(selectNFTIsRedeemComplete);
|
|
|
const preventNavigation =
|
|
|
(isSending || isSendComplete || isRedeeming) && !isRedeemComplete;
|
|
|
+
|
|
|
+ const { search } = useLocation();
|
|
|
+ const query = useMemo(() => new URLSearchParams(search), [search]);
|
|
|
+ const pathSourceChain = query.get("sourceChain");
|
|
|
+ const pathTargetChain = query.get("targetChain");
|
|
|
+
|
|
|
+ //This effect initializes the state based on the path params
|
|
|
+ useEffect(() => {
|
|
|
+ if (!pathSourceChain && !pathTargetChain) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ const sourceChain: ChainId | undefined = CHAINS_WITH_NFT_SUPPORT.find(
|
|
|
+ (x) => parseFloat(pathSourceChain || "") === x.id
|
|
|
+ )?.id;
|
|
|
+ const targetChain: ChainId | undefined = CHAINS_WITH_NFT_SUPPORT.find(
|
|
|
+ (x) => parseFloat(pathTargetChain || "") === x.id
|
|
|
+ )?.id;
|
|
|
+
|
|
|
+ if (sourceChain === targetChain) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (sourceChain) {
|
|
|
+ dispatch(setSourceChain(sourceChain));
|
|
|
+ }
|
|
|
+ if (targetChain) {
|
|
|
+ dispatch(setTargetChain(targetChain));
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ console.error("Invalid path params specified.");
|
|
|
+ }
|
|
|
+ }, [pathSourceChain, pathTargetChain, dispatch]);
|
|
|
+
|
|
|
useEffect(() => {
|
|
|
if (preventNavigation) {
|
|
|
window.onbeforeunload = () => true;
|