Skip to content

Commit

Permalink
fix: reload after 1s
Browse files Browse the repository at this point in the history
  • Loading branch information
yongenaelf committed Nov 16, 2024
1 parent c4fd37e commit 025e0f2
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions components/contract-viewer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"use client";

import React, { useState } from "react";
import React, { useEffect, useState } from "react";
import { useSearchParams } from "next/navigation";
import { useWallet } from "@/data/wallet";
import { ContractView } from "aelf-smartcontract-viewer";
import { useTheme } from "next-themes";
import { Button } from "../ui/button";

const sideChainTestnetRpc = "https://tdvw-test-node.aelf.io";

Expand All @@ -16,25 +15,26 @@ const ContractViewer = ({ name }: { name: string }) => {
const contractViewerAddress = searchParams.get("contract-viewer-address");
const [key, setKey] = useState("0");

useEffect(() => {
setTimeout(() => {
setKey(prev => parseInt(prev) + 1 + "");
}, 1000);
}, [contractViewerAddress]);

if (!contractViewerAddress || !wallet?.wallet) {
return;
}

return (
<>
<div className="flex">
<Button className="mx-auto mt-2" onClick={() => setKey(prev => parseInt(prev) + 1 + "")}>Refresh</Button>
</div>
<ContractView
key={key}
wallet={wallet.wallet}
address={contractViewerAddress}
headerTitle={"Contract View"}
rpcUrl={sideChainTestnetRpc}
contractName={name}
theme={resolvedTheme as "dark" | "light"}
/>
</>
<ContractView
key={key}
wallet={wallet.wallet}
address={contractViewerAddress}
headerTitle={"Contract View"}
rpcUrl={sideChainTestnetRpc}
contractName={name}
theme={resolvedTheme as "dark" | "light"}
/>
);
};

Expand Down

0 comments on commit 025e0f2

Please sign in to comment.