Skip to content

Commit 3be84f9

Browse files
Merge pull request #796 from scaffold-eth/cli-weekly-backmerge
Cli weekly backmerge
2 parents a3d956b + 2dd3a3b commit 3be84f9

File tree

18 files changed

+105
-95
lines changed

18 files changed

+105
-95
lines changed

.changeset/pink-vans-taste.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"create-eth": patch
3+
---
4+
5+
- Extract metadata title and description (#770)
6+
- Remove Goerli from supported networks (#771)
7+
- fix: redundant error notifications on block explorer (#775)
8+
- chore: fix typo (#777)
9+
- fix: vercel deployment linking from github (#780)
10+
- Remove useAccountBalance (#788)
11+
- Templatise README in CLI (#790, #782)
12+
- Add .env to .gitignore in nextjs package (#798)

templates/base/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"format": "yarn next:format",
1818
"postinstall": "husky install",
1919
"precommit": "lint-staged",
20-
"vercel": "vercel",
21-
"vercel:yolo": "vercel --build-env NEXT_PUBLIC_IGNORE_BUILD_ERROR=true"
20+
"vercel": "yarn workspace @se-2/nextjs vercel",
21+
"vercel:yolo": "yarn workspace @se-2/nextjs vercel:yolo"
2222
},
2323
"packageManager": "yarn@3.2.3",
2424
"devDependencies": {

templates/base/packages/nextjs/.gitignore.template.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ yarn-error.log*
2727
.pnpm-debug.log*
2828
2929
# local env files
30+
.env
3031
.env.local
3132
.env.development.local
3233
.env.test.local
3334
.env.production.local
3435
3536
# typescript
36-
*.tsbuildinfo`
37+
*.tsbuildinfo
38+
.vercel`
3739

38-
export default contents
40+
export default contents

templates/base/packages/nextjs/app/blockexplorer/_components/AddressCodeTab.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ type AddressCodeTabProps = {
44
};
55

66
export const AddressCodeTab = ({ bytecode, assembly }: AddressCodeTabProps) => {
7-
const formattedAssembly = assembly.split(" ").join("\n");
7+
const formattedAssembly = Array.from(assembly.matchAll(/\w+( 0x[a-fA-F0-9]+)?/g))
8+
.map(it => it[0])
9+
.join("\n");
810

911
return (
1012
<div className="flex flex-col gap-3 p-4">

templates/base/packages/nextjs/app/blockexplorer/page.tsx

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { useEffect } from "react";
3+
import { useEffect, useState } from "react";
44
import { PaginationButton, SearchBar, TransactionsTable } from "./_components";
55
import type { NextPage } from "next";
66
import { hardhat } from "viem/chains";
@@ -11,24 +11,23 @@ import { notification } from "~~/utils/scaffold-eth";
1111
const BlockExplorer: NextPage = () => {
1212
const { blocks, transactionReceipts, currentPage, totalBlocks, setCurrentPage, error } = useFetchBlocks();
1313
const { targetNetwork } = useTargetNetwork();
14+
const [isLocalNetwork, setIsLocalNetwork] = useState(true);
15+
const [hasError, setHasError] = useState(false);
16+
17+
useEffect(() => {
18+
if (targetNetwork.id !== hardhat.id) {
19+
setIsLocalNetwork(false);
20+
}
21+
}, [targetNetwork.id]);
1422

1523
useEffect(() => {
1624
if (targetNetwork.id === hardhat.id && error) {
17-
notification.error(
18-
<>
19-
<p className="font-bold mt-0 mb-1">Cannot connect to local provider</p>
20-
<p className="m-0">
21-
- Did you forget to run <code className="italic bg-base-300 text-base font-bold">yarn chain</code> ?
22-
</p>
23-
<p className="mt-1 break-normal">
24-
- Or you can change <code className="italic bg-base-300 text-base font-bold">targetNetwork</code> in{" "}
25-
<code className="italic bg-base-300 text-base font-bold">scaffold.config.ts</code>
26-
</p>
27-
</>,
28-
);
25+
setHasError(true);
2926
}
27+
}, [targetNetwork.id, error]);
3028

31-
if (targetNetwork.id !== hardhat.id) {
29+
useEffect(() => {
30+
if (!isLocalNetwork) {
3231
notification.error(
3332
<>
3433
<p className="font-bold mt-0 mb-1">
@@ -48,7 +47,29 @@ const BlockExplorer: NextPage = () => {
4847
</>,
4948
);
5049
}
51-
}, [error, targetNetwork]);
50+
}, [
51+
isLocalNetwork,
52+
targetNetwork.blockExplorers?.default.name,
53+
targetNetwork.blockExplorers?.default.url,
54+
targetNetwork.name,
55+
]);
56+
57+
useEffect(() => {
58+
if (hasError) {
59+
notification.error(
60+
<>
61+
<p className="font-bold mt-0 mb-1">Cannot connect to local provider</p>
62+
<p className="m-0">
63+
- Did you forget to run <code className="italic bg-base-300 text-base font-bold">yarn chain</code> ?
64+
</p>
65+
<p className="mt-1 break-normal">
66+
- Or you can change <code className="italic bg-base-300 text-base font-bold">targetNetwork</code> in{" "}
67+
<code className="italic bg-base-300 text-base font-bold">scaffold.config.ts</code>
68+
</p>
69+
</>,
70+
);
71+
}
72+
}, [hasError]);
5273

5374
return (
5475
<div className="container mx-auto my-10">

templates/base/packages/nextjs/app/layout.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,23 @@ const baseUrl = process.env.VERCEL_URL
99
: `http://localhost:${process.env.PORT || 3000}`;
1010
const imageUrl = `${baseUrl}/thumbnail.jpg`;
1111

12+
const title = "Scaffold-ETH 2 App";
13+
const titleTemplate = "%s | Scaffold-ETH 2";
14+
const description = "Built with 🏗 Scaffold-ETH 2";
15+
1216
export const metadata: Metadata = {
1317
metadataBase: new URL(baseUrl),
1418
title: {
15-
default: "Scaffold-ETH 2 App",
16-
template: "%s | Scaffold-ETH 2",
19+
default: title,
20+
template: titleTemplate,
1721
},
18-
description: "Built with 🏗 Scaffold-ETH 2",
22+
description,
1923
openGraph: {
2024
title: {
21-
default: "Scaffold-ETH 2 App",
22-
template: "%s | Scaffold-ETH 2",
25+
default: title,
26+
template: titleTemplate,
2327
},
24-
description: "Built with 🏗 Scaffold-ETH 2",
28+
description,
2529
images: [
2630
{
2731
url: imageUrl,
@@ -32,10 +36,10 @@ export const metadata: Metadata = {
3236
card: "summary_large_image",
3337
images: [imageUrl],
3438
title: {
35-
default: "Scaffold-ETH 2",
36-
template: "%s | Scaffold-ETH 2",
39+
default: title,
40+
template: titleTemplate,
3741
},
38-
description: "Built with 🏗 Scaffold-ETH 2",
42+
description,
3943
},
4044
icons: {
4145
icon: [{ url: "/favicon.png", sizes: "32x32", type: "image/png" }],

templates/base/packages/nextjs/components/scaffold-eth/Balance.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import { useState } from "react";
44
import { Address } from "viem";
5-
import { useAccountBalance } from "~~/hooks/scaffold-eth";
5+
import { useBalance } from "wagmi";
66
import { useTargetNetwork } from "~~/hooks/scaffold-eth/useTargetNetwork";
7+
import { useGlobalState } from "~~/services/store/store";
78

89
type BalanceProps = {
910
address?: Address;
@@ -16,7 +17,17 @@ type BalanceProps = {
1617
*/
1718
export const Balance = ({ address, className = "", usdMode }: BalanceProps) => {
1819
const { targetNetwork } = useTargetNetwork();
19-
const { balance, price, isError, isLoading } = useAccountBalance(address);
20+
21+
const price = useGlobalState(state => state.nativeCurrencyPrice);
22+
const {
23+
data: balance,
24+
isError,
25+
isLoading,
26+
} = useBalance({
27+
address,
28+
watch: true,
29+
});
30+
2031
const [displayUsdMode, setDisplayUsdMode] = useState(price > 0 ? Boolean(usdMode) : false);
2132

2233
const toggleBalanceMode = () => {
@@ -44,6 +55,8 @@ export const Balance = ({ address, className = "", usdMode }: BalanceProps) => {
4455
);
4556
}
4657

58+
const formattedBalance = balance ? Number(balance.formatted) : 0;
59+
4760
return (
4861
<button
4962
className={`btn btn-sm btn-ghost flex flex-col font-normal items-center hover:bg-transparent ${className}`}
@@ -53,11 +66,11 @@ export const Balance = ({ address, className = "", usdMode }: BalanceProps) => {
5366
{displayUsdMode ? (
5467
<>
5568
<span className="text-[0.8em] font-bold mr-1">$</span>
56-
<span>{(balance * price).toFixed(2)}</span>
69+
<span>{(formattedBalance * price).toFixed(2)}</span>
5770
</>
5871
) : (
5972
<>
60-
<span>{balance?.toFixed(4)}</span>
73+
<span>{formattedBalance.toFixed(4)}</span>
6174
<span className="text-[0.8em] font-bold ml-1">{targetNetwork.nativeCurrency.symbol}</span>
6275
</>
6376
)}

templates/base/packages/nextjs/components/scaffold-eth/FaucetButton.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import { useState } from "react";
44
import { createWalletClient, http, parseEther } from "viem";
55
import { hardhat } from "viem/chains";
66
import { useAccount, useNetwork } from "wagmi";
7+
import { useBalance } from "wagmi";
78
import { BanknotesIcon } from "@heroicons/react/24/outline";
8-
import { useAccountBalance, useTransactor } from "~~/hooks/scaffold-eth";
9+
import { useTransactor } from "~~/hooks/scaffold-eth";
910

1011
// Number of ETH faucet sends to an address
1112
const NUM_OF_ETH = "1";
@@ -21,7 +22,11 @@ const localWalletClient = createWalletClient({
2122
*/
2223
export const FaucetButton = () => {
2324
const { address } = useAccount();
24-
const { balance } = useAccountBalance(address);
25+
26+
const { data: balance } = useBalance({
27+
address,
28+
watch: true,
29+
});
2530

2631
const { chain: ConnectedChain } = useNetwork();
2732

@@ -50,10 +55,12 @@ export const FaucetButton = () => {
5055
return null;
5156
}
5257

58+
const isBalanceZero = balance && balance.value === 0n;
59+
5360
return (
5461
<div
5562
className={
56-
balance
63+
!isBalanceZero
5764
? "ml-1"
5865
: "ml-1 tooltip tooltip-bottom tooltip-secondary tooltip-open font-bold before:left-auto before:transform-none before:content-[attr(data-tip)] before:right-0"
5966
}

templates/base/packages/nextjs/components/scaffold-eth/Input/InputBase.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const InputBase = <T extends { toString: () => string } | undefined = str
3535
[onChange],
3636
);
3737

38-
// Runs only when reFocus prop is passed, usefull for setting the cursor
38+
// Runs only when reFocus prop is passed, useful for setting the cursor
3939
// at the end of the input. Example AddressInput
4040
const onFocus = (e: FocusEvent<HTMLInputElement, Element>) => {
4141
if (reFocus !== undefined) {

templates/base/packages/nextjs/hooks/scaffold-eth/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
export * from "./useAccountBalance";
21
export * from "./useAnimationConfig";
32
export * from "./useBurnerWallet";
43
export * from "./useDeployedContractInfo";

0 commit comments

Comments
 (0)