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

fix(AddressType): cleanup overrides #515

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useEffect, useState } from "react";
import { createPublicClient, http, toHex } from "viem";
import { Address, createPublicClient, http, toHex } from "viem";
import { hardhat } from "wagmi/chains";

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

export const AddressStorageTab = ({ address }: { address: string }) => {
export const AddressStorageTab = ({ address }: { address: Address }) => {
const [storage, setStorage] = useState<string[]>([]);

useEffect(() => {
Expand Down
8 changes: 6 additions & 2 deletions packages/nextjs/components/scaffold-eth/Address.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useState } from "react";
import Link from "next/link";
import Blockies from "react-blockies";
import { CopyToClipboard } from "react-copy-to-clipboard";
import { isAddress } from "viem";
import { Address as AddressType, isAddress } from "viem";
import { useEnsAvatar, useEnsName } from "wagmi";
import { hardhat } from "wagmi/chains";
import { CheckCircleIcon, DocumentDuplicateIcon } from "@heroicons/react/24/outline";
Expand Down Expand Up @@ -33,7 +33,11 @@ export const Address = ({ address, disableAddressLink, format, size = "base" }:
const [ensAvatar, setEnsAvatar] = useState<string | null>();
const [addressCopied, setAddressCopied] = useState(false);

const { data: fetchedEns } = useEnsName({ address, enabled: isAddress(address ?? ""), chainId: 1 });
const { data: fetchedEns } = useEnsName({
address: address as AddressType,
enabled: isAddress(address ?? ""),
chainId: 1,
});
const { data: fetchedEnsAvatar } = useEnsAvatar({
name: fetchedEns,
enabled: Boolean(fetchedEns),
Expand Down
3 changes: 2 additions & 1 deletion packages/nextjs/components/scaffold-eth/Balance.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Address } from "viem";
import { useAccountBalance } from "~~/hooks/scaffold-eth";
import { getTargetNetwork } from "~~/utils/scaffold-eth";

Expand All @@ -11,7 +12,7 @@ type TBalanceProps = {
*/
export const Balance = ({ address, className = "" }: TBalanceProps) => {
const configuredNetwork = getTargetNetwork();
const { balance, price, isError, isLoading, onToggleBalance, isEthBalance } = useAccountBalance(address);
const { balance, price, isError, isLoading, onToggleBalance, isEthBalance } = useAccountBalance(address as Address);

if (!address || isLoading || balance === null) {
return (
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/components/scaffold-eth/Faucet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const Faucet = () => {
<AddressInput
placeholder="Destination Address"
value={inputAddress ?? ""}
onChange={value => setInputAddress(value)}
onChange={value => setInputAddress(value as AddressType)}
/>
<EtherInput placeholder="Amount to send" value={sendValue} onChange={value => setSendValue(value)} />
<button className="h-10 btn btn-primary btn-sm px-2 rounded-full" onClick={sendETH} disabled={loading}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const AddressInput = ({ value, name, placeholder, onChange, disabled }: C

const [enteredEnsName, setEnteredEnsName] = useState<string>();
const { data: ensName, isLoading: isEnsNameLoading } = useEnsName({
address: value,
address: value as Address,
enabled: isAddress(value),
chainId: 1,
cacheTime: 30_000,
Expand Down Expand Up @@ -56,7 +56,7 @@ export const AddressInput = ({ value, name, placeholder, onChange, disabled }: C
name={name}
placeholder={placeholder}
error={ensAddress === null}
value={value}
value={value as Address}
onChange={handleChange}
disabled={isEnsAddressLoading || isEnsNameLoading || disabled}
prefix={
Expand Down
3 changes: 2 additions & 1 deletion packages/nextjs/hooks/scaffold-eth/useAccountBalance.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { useCallback, useEffect, useState } from "react";
import { Address } from "viem";
import { useBalance } from "wagmi";
import { useGlobalState } from "~~/services/store/store";
import { getTargetNetwork } from "~~/utils/scaffold-eth";

export function useAccountBalance(address?: string) {
export function useAccountBalance(address?: Address) {
const [isEthBalance, setIsEthBalance] = useState(true);
const [balance, setBalance] = useState<number | null>(null);
const price = useGlobalState(state => state.nativeCurrencyPrice);
Expand Down
4 changes: 0 additions & 4 deletions packages/nextjs/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ const nextConfig = {
eslint: {
ignoreDuringBuilds: process.env.NEXT_PUBLIC_IGNORE_BUILD_ERROR === "true",
},
webpack: config => {
config.resolve.fallback = { fs: false, net: false, tls: false };
return config;
},
};

module.exports = nextConfig;
4 changes: 2 additions & 2 deletions packages/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"react-hot-toast": "^2.4.0",
"use-debounce": "^8.0.4",
"usehooks-ts": "^2.7.2",
"viem": "^1.6.7",
"wagmi": "1.3.10",
"viem": "^1.10.1",
"wagmi": "^1.3.11",
"zustand": "^4.1.2"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/nextjs/pages/blockexplorer/address/[address].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useRouter } from "next/router";
import fs from "fs";
import { GetServerSideProps } from "next";
import path from "path";
import { createPublicClient, http } from "viem";
import { Address as AddressType, createPublicClient, http } from "viem";
import { hardhat } from "wagmi/chains";
import {
AddressCodeTab,
Expand All @@ -23,7 +23,7 @@ type AddressCodeTabProps = {
};

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

Expand Down
13 changes: 0 additions & 13 deletions packages/nextjs/types/abitype/abi.d.ts

This file was deleted.

4 changes: 3 additions & 1 deletion packages/nextjs/utils/scaffold-eth/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ type Expand<T> = T extends object ? (T extends infer O ? { [K in keyof O]: O[K]

type UnionToIntersection<U> = Expand<(U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never>;

type OptionalTupple<T> = T extends readonly [infer H, ...infer R] ? readonly [H | undefined, ...OptionalTupple<R>] : T;
type OptionalTupple<T> = T extends readonly [infer H, ...infer R]
? readonly [(H extends Address ? string : H) | undefined, ...OptionalTupple<R>]
: T;

type UseScaffoldArgsParam<
TContractName extends ContractName,
Expand Down
4 changes: 2 additions & 2 deletions packages/nextjs/utils/scaffold-eth/fetchPriceFromUniswap.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CurrencyAmount, Token } from "@uniswap/sdk-core";
import { Pair, Route } from "@uniswap/v2-sdk";
import { createPublicClient, http, parseAbi } from "viem";
import { Address, createPublicClient, http, parseAbi } from "viem";
import { mainnet } from "wagmi";
import scaffoldConfig from "~~/scaffold.config";
import { getTargetNetwork } from "~~/utils/scaffold-eth";
Expand Down Expand Up @@ -28,7 +28,7 @@ export const fetchPriceFromUniswap = async (): Promise<number> => {
configuredNetwork.nativeCurrencyTokenAddress || "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
18,
);
const pairAddress = Pair.getAddress(TOKEN, DAI);
const pairAddress = Pair.getAddress(TOKEN, DAI) as Address;

const wagmiConfig = {
address: pairAddress,
Expand Down
Loading