-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feat] Implement components to manage chainId and contract address fr…
…om URL parameters
- Loading branch information
Showing
3 changed files
with
67 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"use client"; | ||
import { useEffect, useState } from 'react'; | ||
import Interaction from "@/components/interaction"; | ||
import { useRouter } from "next/navigation"; | ||
|
||
export default function InteractionClient({ | ||
initialChainId, | ||
initialAddress, | ||
}: { | ||
initialChainId: string; | ||
initialAddress: string; | ||
}) { | ||
const [chainId, setChainId] = useState<string>(initialChainId); | ||
const [deploymentAddress, setDeploymentAddress] = useState<string>(initialAddress); | ||
const router = useRouter(); | ||
|
||
useEffect(() => { | ||
const urlParams = new URLSearchParams(window.location.search); | ||
const chainIdParam = urlParams.get("chainId"); | ||
const contractAddressParam = urlParams.get("contractAddress"); | ||
|
||
if (chainIdParam && contractAddressParam) { | ||
setChainId(chainIdParam); | ||
setDeploymentAddress(contractAddressParam); | ||
} else { | ||
router.push("/404"); | ||
} | ||
}, [router]); | ||
|
||
return ( | ||
<div className="w-full h-full"> | ||
<Interaction chainId={chainId} deploymentAddress={deploymentAddress} /> | ||
</div> | ||
); | ||
} |
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,31 @@ | ||
"use client"; | ||
|
||
import { useRouter } from "next/navigation"; | ||
import { useEffect, useState } from "react"; | ||
import InteractionClient from "./interaction-client"; | ||
import { notFound } from "next/navigation"; | ||
|
||
export default function InteractionsPage() { | ||
const router = useRouter(); | ||
const [chainId, setChainId] = useState<string | null>(null); | ||
const [contractAddress, setContractAddress] = useState<string | null>(null); | ||
|
||
useEffect(() => { | ||
const urlParams = new URLSearchParams(window.location.search); | ||
const chainIdParam = urlParams.get("chainId"); | ||
const contractAddressParam = urlParams.get("contractAddress"); | ||
|
||
if (chainIdParam && contractAddressParam) { | ||
setChainId(chainIdParam); | ||
setContractAddress(contractAddressParam); | ||
} else { | ||
notFound(); | ||
} | ||
}, [router]); | ||
|
||
if (!chainId || !contractAddress) { | ||
return <div>Loading...</div>; | ||
} | ||
|
||
return <InteractionClient initialChainId={chainId} initialAddress={contractAddress} />; | ||
} |
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