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

App router migration #535

Merged
merged 124 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from 122 commits
Commits
Show all changes
124 commits
Select commit Hold shift + click to select a range
20cdff9
app-router-migration
Anurag-Raut Sep 14, 2023
e050e8b
uncomment-metaheader
Anurag-Raut Sep 14, 2023
a4f353a
Update Header.tsx
Anurag-Raut Sep 14, 2023
76d8228
Update tsconfig.json
Anurag-Raut Sep 14, 2023
a990fea
Update yarn.lock
Anurag-Raut Sep 14, 2023
e454498
Delete packages/nextjs/.vscode directory
Anurag-Raut Sep 14, 2023
c0c312a
Update deployedContracts.ts
Anurag-Raut Sep 14, 2023
0dd9d03
Update RainbowKitCustomConnectButton.tsx
Anurag-Raut Sep 14, 2023
af5be55
Update yarn.lock
Anurag-Raut Sep 14, 2023
adeead8
Update package.json
Anurag-Raut Sep 14, 2023
b6b9a7e
app-router-migration-v2
Anurag-Raut Sep 15, 2023
ded8906
Merge branch 'scaffold-eth:main' into main
Anurag-Raut Sep 15, 2023
cc456be
Merge branch 'scaffold-eth:main' into app-router-migration
Anurag-Raut Sep 15, 2023
8f8e8bd
Merge branch 'main' into app-router-migration
Anurag-Raut Sep 15, 2023
08dfebe
updated eslint-config-next
Anurag-Raut Sep 15, 2023
1e48d9e
prettier
Anurag-Raut Sep 17, 2023
28bbcba
prettier
Anurag-Raut Sep 17, 2023
ac9b765
prettier
Anurag-Raut Sep 17, 2023
2a189b0
metadata-changes
Anurag-Raut Sep 17, 2023
6bee794
metadata-changes
Anurag-Raut Sep 17, 2023
6afa79b
deleted-generateMetadata
Anurag-Raut Sep 17, 2023
faef342
Merge pull request #1 from Anurag-Raut/app-router
Anurag-Raut Sep 17, 2023
156f121
updated-app-component
Anurag-Raut Sep 17, 2023
18deb6a
updated-app-component
Anurag-Raut Sep 17, 2023
b590126
Merge pull request #2 from Anurag-Raut/app-router
Anurag-Raut Sep 17, 2023
4556315
Merge branch 'app-router-migration' of https://github.com/Anurag-Raut…
Anurag-Raut Sep 17, 2023
b37614e
cleaned package.json
Anurag-Raut Sep 17, 2023
ad352d6
reviewed-changed-1
Anurag-Raut Sep 18, 2023
d0265e1
reviwed-changed-2
Anurag-Raut Sep 18, 2023
199b355
reviwed-changed-2
Anurag-Raut Sep 18, 2023
d2d9d2c
package.json update
Anurag-Raut Sep 18, 2023
c1857d2
yarn.lock
Anurag-Raut Sep 18, 2023
c21808f
migrated getServerSideProps
Anurag-Raut Sep 19, 2023
3335cad
progressBar
Anurag-Raut Sep 19, 2023
960cba7
progressBar
Anurag-Raut Sep 19, 2023
cd73561
cleaned-layout.tsx
Anurag-Raut Sep 19, 2023
b184af4
cleaned-layout.tsx
Anurag-Raut Sep 19, 2023
2b6972b
cleaned-layout.tsx
Anurag-Raut Sep 19, 2023
a5ad389
cleaned-layout.tsx
Anurag-Raut Sep 19, 2023
7b05362
ts-config-update
Anurag-Raut Sep 19, 2023
e5c31a2
removed-blockexplorer-changes
Anurag-Raut Sep 19, 2023
db260e4
reviewed changes
Anurag-Raut Sep 21, 2023
bda79e8
reviewed changes-2
Anurag-Raut Sep 21, 2023
c924101
reviewed changes-2
Anurag-Raut Sep 21, 2023
6aaba10
reviewed changes-2
Anurag-Raut Sep 21, 2023
9033328
reviewed changes-2
Anurag-Raut Sep 21, 2023
773c454
Merge pull request #3 from Anurag-Raut/anurag-app-router
Anurag-Raut Sep 21, 2023
2c83707
package.json es-lint-update
Anurag-Raut Sep 21, 2023
3ce7ca8
package.json es-lint-update
Anurag-Raut Sep 21, 2023
e2e1b80
Merge pull request #4 from Anurag-Raut/anurag-app-router
Anurag-Raut Sep 21, 2023
3524605
useFetchBlocks refactor
Anurag-Raut Sep 21, 2023
88d9b66
Merge pull request #5 from Anurag-Raut/anurag-app-router
Anurag-Raut Sep 21, 2023
adf982c
added Block explorer metadata
Anurag-Raut Sep 21, 2023
782184d
next update
Anurag-Raut Sep 21, 2023
abb78bc
Merge pull request #6 from Anurag-Raut/anurag-app-router
Anurag-Raut Sep 21, 2023
ff9395b
chnaged project structure
Anurag-Raut Sep 21, 2023
89c905e
changed project structure
Anurag-Raut Sep 21, 2023
044c6e0
Merge pull request #7 from Anurag-Raut/anurag-app-router
Anurag-Raut Sep 21, 2023
230024d
added HARDHAT_CHAIN_ID for app/address/page
Anurag-Raut Sep 22, 2023
a94f6d7
formatted
Anurag-Raut Sep 22, 2023
26571dd
Merge pull request #8 from Anurag-Raut/anurag-app-router
Anurag-Raut Sep 22, 2023
21b087f
Merge branch 'main' into app-router-migration
carletex Sep 22, 2023
8e74e7b
remove export from getData
Anurag-Raut Sep 22, 2023
bc3e6fb
Merge pull request #9 from Anurag-Raut/anurag-app-router
Anurag-Raut Sep 22, 2023
77e30b5
Merge branch 'scaffold-eth:main' into anurag-app-router
Anurag-Raut Sep 22, 2023
8ffbb94
Update page.tsx
Anurag-Raut Sep 22, 2023
23df879
Merge pull request #10 from Anurag-Raut/anurag-app-router
Anurag-Raut Sep 22, 2023
35e9b51
Merge branch 'main' into app-router-migration
carletex Sep 26, 2023
d4b34bf
Merge pull request #11 from scaffold-eth/main
Anurag-Raut Sep 27, 2023
ffeee93
get metadaa updated
Anurag-Raut Sep 27, 2023
b8233cd
get metadata updated
Anurag-Raut Sep 27, 2023
2b774f6
Merge pull request #12 from Anurag-Raut/anurag-app-router
Anurag-Raut Sep 27, 2023
06ae079
changed import format
Anurag-Raut Sep 27, 2023
375f49d
Merge pull request #13 from Anurag-Raut/anurag-app-router
Anurag-Raut Sep 27, 2023
5c0040e
getMetadata - added imageRelativePath
Anurag-Raut Sep 27, 2023
a6e6e56
Merge pull request #14 from Anurag-Raut/anurag-app-router
Anurag-Raut Sep 27, 2023
964e282
Rename getMetaData.ts to getMetadata.ts
Anurag-Raut Sep 27, 2023
6d71a4a
Merge branch 'scaffold-eth:main' into anurag-app-router
Anurag-Raut Sep 30, 2023
2ae2b29
Merge branch 'scaffold-eth:main' into app-router-migration
Anurag-Raut Sep 30, 2023
6a63984
fixed blockexplorer/address
Anurag-Raut Sep 30, 2023
63a9206
Merge branch 'anurag-app-router' of https://github.com/Anurag-Raut/se…
Anurag-Raut Sep 30, 2023
ec00b99
fixed blockexplorer/address
Anurag-Raut Sep 30, 2023
5233cb5
Merge pull request #15 from Anurag-Raut/anurag-app-router
Anurag-Raut Sep 30, 2023
bbf8385
getMetadata changes
Anurag-Raut Sep 30, 2023
28d0fe1
Merge pull request #17 from scaffold-eth/main
Anurag-Raut Sep 30, 2023
7d195b5
fixed blockexplorer/address
Anurag-Raut Sep 30, 2023
32af33a
Merge branch 'app-router-migration' of https://github.com/Anurag-Raut…
Anurag-Raut Sep 30, 2023
51346e2
feat: address client component
rin-st Sep 30, 2023
3163c87
fix: custom use-dark-mode
rin-st Sep 30, 2023
a5ea525
Merge branch 'app-router-migration' of github.com:Anurag-Raut/se-2 in…
rin-st Sep 30, 2023
2885850
fix: remove redundant component
rin-st Sep 30, 2023
231b30f
removed Use client for utils
Anurag-Raut Oct 2, 2023
acb0f7a
feat: update use dark mode
rin-st Oct 3, 2023
23433b9
Merge pull request #20 from scaffold-eth/main
Anurag-Raut Oct 6, 2023
33fbd28
Merge branch 'main' of https://github.com/Anurag-Raut/se-2 into app-r…
Anurag-Raut Oct 6, 2023
4b9c677
used viem/chains
Anurag-Raut Oct 6, 2023
6f7af01
added metadataBase
Anurag-Raut Oct 6, 2023
18c0667
Merge pull request #19 from scaffold-eth/fix/use-dark-theme
Anurag-Raut Oct 6, 2023
d0008cb
localise debug contract components inside its route
technophile-04 Oct 7, 2023
42ba096
use import alias in ReadOnlyFunctionForm
technophile-04 Oct 7, 2023
5703ebb
up wagmi to 1.4.3 and use viem/chains for chains
technophile-04 Oct 7, 2023
8b2bdd7
up rainbowkit
technophile-04 Oct 7, 2023
8a6d2a0
up vercel
technophile-04 Oct 7, 2023
3b771e8
up next
technophile-04 Oct 7, 2023
baeb69d
remove forced style from #510
technophile-04 Oct 7, 2023
e6c8904
add active style to Navlink
technophile-04 Oct 8, 2023
1cc8bd2
up @types/react
technophile-04 Oct 8, 2023
4d2f910
revert: up @types/react
technophile-04 Oct 8, 2023
18a2675
Merge branch 'main' into app-router-migration
technophile-04 Oct 11, 2023
2ac9487
use dynamic import for RainbowkitCustomConnectBtn
technophile-04 Oct 11, 2023
8b85502
Revert "use dynamic import for RainbowkitCustomConnectBtn"
technophile-04 Oct 11, 2023
d288d63
add //@refresh reset in RainbowkitCustomConnectButton
technophile-04 Oct 11, 2023
c4142a1
simplify useAutoConnect and useAccount as single source of truth
technophile-04 Oct 11, 2023
1cb40d1
Merge branch 'upstream/main' into app-router-migration
technophile-04 Jan 6, 2024
94647df
update next version
technophile-04 Jan 6, 2024
d0094d7
use named export for zustand create
technophile-04 Jan 6, 2024
22f22fd
up min node version in README and lint.yaml file
technophile-04 Jan 6, 2024
bd9a3ef
fix lts syntax
technophile-04 Jan 6, 2024
edb412c
use barrel files for blockexplorer
technophile-04 Jan 6, 2024
8d2baac
remove use client from AddressComponent
technophile-04 Jan 6, 2024
9c3cca6
add new line b/w 9-10 in layout.tsx
technophile-04 Jan 6, 2024
dba645e
fix: useDarkMode
rin-st Jan 6, 2024
14936c4
update debug page route
Pabl0cks Jan 7, 2024
5a6a6d9
merge upstream/main
technophile-04 Jan 8, 2024
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: 3 additions & 3 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node: [16.x]
node: [lts/*]

steps:
- name: Checkout
Expand All @@ -25,13 +25,13 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache : yarn
cache: yarn

- name: Install dependencies
run: yarn install --immutable

- name: Run hardhat node, deploy contracts (& generate contracts typescript output)
run: yarn chain & yarn deploy
run: yarn chain & yarn deploy

- name: Run nextjs lint
run: yarn next:lint --max-warnings=0
Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn lint-staged --verbose
yarn lint-staged --verbose
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

Before you begin, you need to install the following tools:

- [Node (v18 LTS)](https://nodejs.org/en/download/)
- [Node (>= v18.17)](https://nodejs.org/en/download/)
- Yarn ([v1](https://classic.yarnpkg.com/en/docs/install/) or [v2+](https://yarnpkg.com/getting-started/install))
- [Git](https://git-scm.com/downloads)

Expand Down
35 changes: 35 additions & 0 deletions packages/nextjs/app/blockexplorer/_components/AddressComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { BackButton } from "./BackButton";
import { ContractTabs } from "./ContractTabs";
import { Address, Balance } from "~~/components/scaffold-eth";

export const AddressComponent = ({
address,
contractData,
}: {
address: string;
contractData: { bytecode: string; assembly: string } | null;
}) => {
return (
<div className="m-10 mb-20">
<div className="flex justify-start mb-5">
<BackButton />
</div>
<div className="col-span-5 grid grid-cols-1 lg:grid-cols-2 gap-8 lg:gap-10">
<div className="col-span-1 flex flex-col">
<div className="bg-base-100 border-base-300 border shadow-md shadow-secondary rounded-3xl px-6 lg:px-8 mb-6 space-y-1 py-4 overflow-x-auto">
<div className="flex">
<div className="flex flex-col gap-1">
<Address address={address} format="long" />
<div className="flex gap-1 items-center">
<span className="font-bold text-sm">Balance:</span>
<Balance address={address} className="text" />
</div>
</div>
</div>
</div>
</div>
</div>
<ContractTabs address={address} contractData={contractData} />
</div>
);
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use client";

import { useEffect, useState } from "react";
import { Address, createPublicClient, http, toHex } from "viem";
import { hardhat } from "viem/chains";
Expand Down
12 changes: 12 additions & 0 deletions packages/nextjs/app/blockexplorer/_components/BackButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use client";

import { useRouter } from "next/navigation";

export const BackButton = () => {
const router = useRouter();
return (
<button className="btn btn-sm btn-primary" onClick={() => router.back()}>
Back
</button>
);
};
92 changes: 92 additions & 0 deletions packages/nextjs/app/blockexplorer/_components/ContractTabs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
"use client";

import { useEffect, useState } from "react";
import { AddressCodeTab } from "./AddressCodeTab";
import { AddressLogsTab } from "./AddressLogsTab";
import { AddressStorageTab } from "./AddressStorageTab";
import { PaginationButton } from "./PaginationButton";
import { TransactionsTable } from "./TransactionsTable";
import { createPublicClient, http } from "viem";
import { hardhat } from "viem/chains";
import { useFetchBlocks } from "~~/hooks/scaffold-eth";

type AddressCodeTabProps = {
bytecode: string;
assembly: string;
};

type PageProps = {
address: string;
contractData: AddressCodeTabProps | null;
};

const publicClient = createPublicClient({
chain: hardhat,
transport: http(),
});

export const ContractTabs = ({ address, contractData }: PageProps) => {
const { blocks, transactionReceipts, currentPage, totalBlocks, setCurrentPage } = useFetchBlocks();
const [activeTab, setActiveTab] = useState("transactions");
const [isContract, setIsContract] = useState(false);

useEffect(() => {
const checkIsContract = async () => {
const contractCode = await publicClient.getBytecode({ address: address });
setIsContract(contractCode !== undefined && contractCode !== "0x");
};

checkIsContract();
}, [address]);

const filteredBlocks = blocks.filter(block =>
block.transactions.some(tx => {
if (typeof tx === "string") {
return false;
}
return tx.from.toLowerCase() === address.toLowerCase() || tx.to?.toLowerCase() === address.toLowerCase();
}),
);

return (
<>
{isContract && (
<div className="tabs tabs-lifted w-min">
<button
className={`tab ${activeTab === "transactions" ? "tab-active" : ""}`}
onClick={() => setActiveTab("transactions")}
>
Transactions
</button>
<button className={`tab ${activeTab === "code" ? "tab-active" : ""}`} onClick={() => setActiveTab("code")}>
Code
</button>
<button
className={`tab ${activeTab === "storage" ? "tab-active" : ""}`}
onClick={() => setActiveTab("storage")}
>
Storage
</button>
<button className={`tab ${activeTab === "logs" ? "tab-active" : ""}`} onClick={() => setActiveTab("logs")}>
Logs
</button>
</div>
)}
{activeTab === "transactions" && (
<div className="pt-4">
<TransactionsTable blocks={filteredBlocks} transactionReceipts={transactionReceipts} />
<PaginationButton
currentPage={currentPage}
totalItems={Number(totalBlocks)}
setCurrentPage={setCurrentPage}
/>
</div>
)}
{activeTab === "code" && contractData && (
<AddressCodeTab bytecode={contractData.bytecode} assembly={contractData.assembly} />
)}
{activeTab === "storage" && <AddressStorageTab address={address} />}
{activeTab === "logs" && <AddressLogsTab address={address} />}
</>
);
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use client";

import { useState } from "react";
import { useRouter } from "next/router";
import { useRouter } from "next/navigation";
import { isAddress, isHex } from "viem";
import { hardhat } from "viem/chains";
import { usePublicClient } from "wagmi";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use client";

import { useState } from "react";
import Link from "next/link";
import { CopyToClipboard } from "react-copy-to-clipboard";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TransactionHash } from "./TransactionHash";
import { formatEther } from "viem";
import { TransactionHash } from "~~/components/blockexplorer/TransactionHash";
import { Address } from "~~/components/scaffold-eth";
import { useTargetNetwork } from "~~/hooks/scaffold-eth/useTargetNetwork";
import { TransactionWithFunction } from "~~/utils/scaffold-eth";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from "./AddressCodeTab";
export * from "./AddressLogsTab";
export * from "./AddressStorageTab";
export * from "./PaginationButton";
export * from "./SearchBar";
export * from "./BackButton";
export * from "./AddressCodeTab";
export * from "./TransactionHash";
export * from "./ContractTabs";
export * from "./PaginationButton";
export * from "./TransactionsTable";
85 changes: 85 additions & 0 deletions packages/nextjs/app/blockexplorer/address/[address]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import fs from "fs";
import path from "path";
import { hardhat } from "viem/chains";
import { AddressComponent } from "~~/app/blockexplorer/_components/AddressComponent";
import deployedContracts from "~~/contracts/deployedContracts";
import { GenericContractsDeclaration } from "~~/utils/scaffold-eth/contract";

type PageProps = {
params: { address: string };
};

async function fetchByteCodeAndAssembly(buildInfoDirectory: string, contractPath: string) {
const buildInfoFiles = fs.readdirSync(buildInfoDirectory);
let bytecode = "";
let assembly = "";

for (let i = 0; i < buildInfoFiles.length; i++) {
const filePath = path.join(buildInfoDirectory, buildInfoFiles[i]);

const buildInfo = JSON.parse(fs.readFileSync(filePath, "utf8"));

if (buildInfo.output.contracts[contractPath]) {
for (const contract in buildInfo.output.contracts[contractPath]) {
bytecode = buildInfo.output.contracts[contractPath][contract].evm.bytecode.object;
assembly = buildInfo.output.contracts[contractPath][contract].evm.bytecode.opcodes;
break;
}
}

if (bytecode && assembly) {
break;
}
}

return { bytecode, assembly };
}

const getContractData = async (address: string) => {
const contracts = deployedContracts as GenericContractsDeclaration | null;
const chainId = hardhat.id;
let contractPath = "";

const buildInfoDirectory = path.join(
__dirname,
"..",
"..",
"..",
"..",
"..",
"..",
"..",
"hardhat",
"artifacts",
"build-info",
);

if (!fs.existsSync(buildInfoDirectory)) {
throw new Error(`Directory ${buildInfoDirectory} not found.`);
}

const deployedContractsOnChain = contracts ? contracts[chainId] : {};
for (const [contractName, contractInfo] of Object.entries(deployedContractsOnChain)) {
if (contractInfo.address.toLowerCase() === address) {
contractPath = `contracts/${contractName}.sol`;
break;
}
}

if (!contractPath) {
// No contract found at this address
return null;
}

const { bytecode, assembly } = await fetchByteCodeAndAssembly(buildInfoDirectory, contractPath);

return { bytecode, assembly };
};

const AddressPage = async ({ params }: PageProps) => {
const address = params?.address as string;
const contractData: { bytecode: string; assembly: string } | null = await getContractData(address);
return <AddressComponent address={address} contractData={contractData} />;
};

export default AddressPage;
12 changes: 12 additions & 0 deletions packages/nextjs/app/blockexplorer/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { getMetadata } from "~~/utils/scaffold-eth/getMetadata";

export const metadata = getMetadata({
title: "Block Explorer",
description: "Block Explorer created with 🏗 Scaffold-ETH 2",
});

const BlockExplorerLayout = ({ children }: { children: React.ReactNode }) => {
return <>{children}</>;
};

export default BlockExplorerLayout;
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use client";

import { useEffect } from "react";
import { PaginationButton, SearchBar, TransactionsTable } from "./_components";
import type { NextPage } from "next";
import { hardhat } from "viem/chains";
import { PaginationButton } from "~~/components/blockexplorer/PaginationButton";
import { SearchBar } from "~~/components/blockexplorer/SearchBar";
import { TransactionsTable } from "~~/components/blockexplorer/TransactionsTable";
import { useFetchBlocks } from "~~/hooks/scaffold-eth";
import { useTargetNetwork } from "~~/hooks/scaffold-eth/useTargetNetwork";
import { notification } from "~~/utils/scaffold-eth";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use client";

import { useEffect, useState } from "react";
import { useRouter } from "next/router";
import { useRouter } from "next/navigation";
import type { NextPage } from "next";
import { Hash, Transaction, TransactionReceipt, formatEther, formatUnits } from "viem";
import { hardhat } from "viem/chains";
Expand All @@ -9,11 +11,13 @@ import { useTargetNetwork } from "~~/hooks/scaffold-eth/useTargetNetwork";
import { decodeTransactionData, getFunctionDetails } from "~~/utils/scaffold-eth";
import { replacer } from "~~/utils/scaffold-eth/common";

const TransactionPage: NextPage = () => {
type PageProps = {
params: { txHash?: Hash };
};
const TransactionPage: NextPage<PageProps> = ({ params }: PageProps) => {
const client = usePublicClient({ chainId: hardhat.id });

const txHash = params?.txHash as Hash;
const router = useRouter();
const { txHash } = router.query as { txHash?: Hash };
const [transaction, setTransaction] = useState<Transaction>();
const [receipt, setReceipt] = useState<TransactionReceipt>();
const [functionCalled, setFunctionCalled] = useState<string>();
Expand Down
Loading