From fd24f2b55eafa71f3fdcd2c69fcb03ba5179b669 Mon Sep 17 00:00:00 2001 From: Samuel Van Erps Date: Sat, 2 Dec 2023 23:44:41 +0100 Subject: [PATCH 1/8] fix(address type): allows user to set his preference in scaffold config (#630) Fixes #514 --- .../components/blockexplorer/AddressStorageTab.tsx | 4 ++-- packages/nextjs/components/scaffold-eth/Address.tsx | 4 ++-- packages/nextjs/components/scaffold-eth/Balance.tsx | 3 ++- .../components/scaffold-eth/Contract/utilsDisplay.tsx | 4 ++-- packages/nextjs/components/scaffold-eth/Faucet.tsx | 2 +- .../components/scaffold-eth/Input/AddressInput.tsx | 4 ++-- .../AddressInfoDropdown.tsx | 4 ++-- .../RainbowKitCustomConnectButton/AddressQRCodeModal.tsx | 9 +++++---- .../scaffold-eth/RainbowKitCustomConnectButton/index.tsx | 7 ++++--- packages/nextjs/hooks/scaffold-eth/useAccountBalance.ts | 3 ++- .../nextjs/pages/blockexplorer/address/[address].tsx | 4 ++-- .../nextjs/pages/blockexplorer/transaction/[txHash].tsx | 4 ++-- packages/nextjs/scaffold.config.ts | 7 +++++++ packages/nextjs/types/abitype/abi.d.ts | 7 +++++-- .../nextjs/utils/scaffold-eth/fetchPriceFromUniswap.ts | 4 ++-- 15 files changed, 42 insertions(+), 28 deletions(-) diff --git a/packages/nextjs/components/blockexplorer/AddressStorageTab.tsx b/packages/nextjs/components/blockexplorer/AddressStorageTab.tsx index f9f4d4fe3..acc669123 100644 --- a/packages/nextjs/components/blockexplorer/AddressStorageTab.tsx +++ b/packages/nextjs/components/blockexplorer/AddressStorageTab.tsx @@ -1,5 +1,5 @@ import { useEffect, useState } from "react"; -import { createPublicClient, http, toHex } from "viem"; +import { Address, createPublicClient, http, toHex } from "viem"; import { hardhat } from "viem/chains"; const publicClient = createPublicClient({ @@ -7,7 +7,7 @@ const publicClient = createPublicClient({ transport: http(), }); -export const AddressStorageTab = ({ address }: { address: string }) => { +export const AddressStorageTab = ({ address }: { address: Address }) => { const [storage, setStorage] = useState([]); useEffect(() => { diff --git a/packages/nextjs/components/scaffold-eth/Address.tsx b/packages/nextjs/components/scaffold-eth/Address.tsx index 057d706bc..08c8453d3 100644 --- a/packages/nextjs/components/scaffold-eth/Address.tsx +++ b/packages/nextjs/components/scaffold-eth/Address.tsx @@ -1,7 +1,7 @@ import { useEffect, useState } from "react"; import Link from "next/link"; import { CopyToClipboard } from "react-copy-to-clipboard"; -import { isAddress } from "viem"; +import { Address as AddressType, isAddress } from "viem"; import { hardhat } from "viem/chains"; import { useEnsAvatar, useEnsName } from "wagmi"; import { CheckCircleIcon, DocumentDuplicateIcon } from "@heroicons/react/24/outline"; @@ -10,7 +10,7 @@ import { useTargetNetwork } from "~~/hooks/scaffold-eth/useTargetNetwork"; import { getBlockExplorerAddressLink } from "~~/utils/scaffold-eth"; type AddressProps = { - address?: string; + address?: AddressType; disableAddressLink?: boolean; format?: "short" | "long"; size?: "xs" | "sm" | "base" | "lg" | "xl" | "2xl" | "3xl"; diff --git a/packages/nextjs/components/scaffold-eth/Balance.tsx b/packages/nextjs/components/scaffold-eth/Balance.tsx index 66bc172e7..784603a88 100644 --- a/packages/nextjs/components/scaffold-eth/Balance.tsx +++ b/packages/nextjs/components/scaffold-eth/Balance.tsx @@ -1,8 +1,9 @@ +import { Address } from "viem"; import { useAccountBalance } from "~~/hooks/scaffold-eth"; import { useTargetNetwork } from "~~/hooks/scaffold-eth/useTargetNetwork"; type BalanceProps = { - address?: string; + address?: Address; className?: string; }; diff --git a/packages/nextjs/components/scaffold-eth/Contract/utilsDisplay.tsx b/packages/nextjs/components/scaffold-eth/Contract/utilsDisplay.tsx index 5fcf3103a..f5d212993 100644 --- a/packages/nextjs/components/scaffold-eth/Contract/utilsDisplay.tsx +++ b/packages/nextjs/components/scaffold-eth/Contract/utilsDisplay.tsx @@ -1,5 +1,5 @@ import { ReactElement } from "react"; -import { TransactionBase, TransactionReceipt, formatEther } from "viem"; +import { TransactionBase, TransactionReceipt, formatEther, isAddress } from "viem"; import { Address } from "~~/components/scaffold-eth"; import { replacer } from "~~/utils/scaffold-eth/common"; @@ -34,7 +34,7 @@ export const displayTxResult = ( } } - if (typeof displayContent === "string" && displayContent.indexOf("0x") === 0 && displayContent.length === 42) { + if (typeof displayContent === "string" && isAddress(displayContent)) { return asText ? displayContent :
; } diff --git a/packages/nextjs/components/scaffold-eth/Faucet.tsx b/packages/nextjs/components/scaffold-eth/Faucet.tsx index a21c9fa2e..3b070326a 100644 --- a/packages/nextjs/components/scaffold-eth/Faucet.tsx +++ b/packages/nextjs/components/scaffold-eth/Faucet.tsx @@ -110,7 +110,7 @@ export const Faucet = () => { setInputAddress(value)} + onChange={value => setInputAddress(value as AddressType)} /> setSendValue(value)} />