Skip to content

Commit

Permalink
fix: updated wallet, setparams and contractName logic
Browse files Browse the repository at this point in the history
  • Loading branch information
RutvikGhaskataEalf committed Oct 4, 2024
1 parent 76b8668 commit 1cc3cd8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
6 changes: 3 additions & 3 deletions app/workspace/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use client";

import { Fragment } from "react";
import { BuildDeployPanel } from "@/components/build-deploy-panel";
import TopBottom from "@/components/top-bottom";
import {
Expand All @@ -11,9 +12,8 @@ import Cli from "@/components/workspace/cli";
import Editor from "@/components/workspace/editor";
import FileExplorer from "@/components/file-explorer";
import ContractViewer from "@/components/contract-viewer";
import { Fragment } from "react";

export default function Page() {
export default function Page({params: {id}}: {params: {id: string}}) {
return (
<ResizablePanelGroup direction="horizontal" className="border">
<ResizablePanel defaultSize={25} className="flex flex-col">
Expand All @@ -24,7 +24,7 @@ export default function Page() {
<FileExplorer />
</Fragment>
}
bottom={<ContractViewer />}
bottom={<ContractViewer name={id}/>}
topDefaultSize={30}
bottomDefaultSize={70}
/>
Expand Down
21 changes: 9 additions & 12 deletions components/contract-viewer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
"use client";

import React, { useEffect, useState } from "react";
import { usePathname, useSearchParams } from "next/navigation";
import React from "react";
import { useSearchParams } from "next/navigation";
import { useWallet } from "@/data/wallet";
import AElf from "aelf-sdk";
import { ContractView } from "aelf-smartcontract-viewer";

const ContractViewer = () => {
const searchParams = useSearchParams();
const pathName = usePathname();
const contractName = pathName.split("/")[2];
const sideChainTestnetRpc = "https://explorer-test-side02.aelf.io/chain";

const ContractViewer = ({ name }: { name: string }) => {
const searchParams = useSearchParams();
const wallet = useWallet();
const aelfWallet = wallet?.privateKey && AElf.wallet.getWalletByPrivateKey(wallet.privateKey);
const contractViewerAddress = searchParams.get("contract-viewer-address");

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

return (
<ContractView
wallet={aelfWallet}
wallet={wallet.wallet}
address={contractViewerAddress}
headerTitle={"Contract View"}
rpcUrl="https://explorer-test-side02.aelf.io/chain"
contractName={contractName}
rpcUrl={sideChainTestnetRpc}
contractName={name}
/>
);
};
Expand Down
11 changes: 3 additions & 8 deletions components/workspace/use-cli-commands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -390,17 +390,12 @@ function CheckProposalInfo({ id }: { id: string }) {

function DeployedContractDetails({ id }: { id?: string }) {
const { data } = useLogs(id);
const pathname = usePathname();
const router = useRouter();
const searchParams = useSearchParams();
const contractViewerAddress = searchParams.get("contract-viewer-address");
const setSearchParams = useSetSearchParams();

if (!data) return <Deploying />;

if(data?.address){
if(!contractViewerAddress){
router.replace(pathname + `?contract-viewer-address=${data.address}`);
}
if (data?.address) {
setSearchParams({ ["contract-viewer-address"]: data.address });
}

return <p>Contract Address: {data.address}</p>;
Expand Down

0 comments on commit 1cc3cd8

Please sign in to comment.