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

Use usePublicClient instead of createPublicClient to use the global alchemy api key #80

Merged
merged 1 commit into from
Dec 25, 2024
Merged
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
11 changes: 3 additions & 8 deletions packages/nextjs/components/address-vision/ButtonsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import Image from "next/image";
import Link from "next/link";
import { SafeOwner } from "./SafeOwner";
import { useTheme } from "next-themes";
import { Address, createPublicClient, http, isAddress } from "viem";
import { mainnet } from "viem/chains";
import { Address, isAddress } from "viem";
import { usePublicClient } from "wagmi";
import { useAddressStore } from "~~/services/store/store";

const GNOSIS_SAFE_BYTECODE_PATTERN = "0x608060405273ffffffffffffffffffffffffffffffffffffffff600054167fa619486e";
Expand All @@ -26,19 +26,14 @@ const SAFE_ABI = [
},
];

export const client = createPublicClient({
chain: mainnet,
transport: http(),
});

export const ButtonsCard = () => {
const [isContractAddress, setIsContractAddress] = useState<boolean>(false);
const [isGnosisSafe, setIsGnosisSafe] = useState<boolean>(false);
const [safeOwners, setSafeOwners] = useState<Address[]>([]);
const [safeThreshold, setSafeThreshold] = useState<number>(0);

const { resolvedAddress: address } = useAddressStore();

const client = usePublicClient();
const { resolvedTheme } = useTheme();
const isDarkMode = resolvedTheme === "dark";

Expand Down
11 changes: 4 additions & 7 deletions packages/nextjs/components/address-vision/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,18 @@ import { useRouter } from "next/router";
import { AddressInput } from "../scaffold-eth";
import { QrScanner } from "@yudiel/react-qr-scanner";
import { Address, isAddress } from "viem";
import { createPublicClient, http } from "viem";
import { mainnet } from "viem/chains";
import { normalize } from "viem/ens";
import { usePublicClient } from "wagmi";
import { QrCodeIcon, XMarkIcon } from "@heroicons/react/24/outline";
import { useAddressStore, useNetworkBalancesStore } from "~~/services/store/store";
import { notification } from "~~/utils/scaffold-eth";

const client = createPublicClient({
chain: mainnet,
transport: http(),
});

export const Navbar = () => {
const [inputValue, setInputValue] = useState("");
const [isScannerVisible, setIsScannerVisible] = useState(false);
const [inputChanged, setInputChanged] = useState(false);

const client = usePublicClient();
const router = useRouter();
const inputRef = useRef<HTMLInputElement>(null);

Expand Down Expand Up @@ -61,6 +56,7 @@ export const Navbar = () => {
router.push(`/${trimmedAddress}`, undefined, { shallow: true });
setEnsName(trimmedAddress);
async function getEnsAddress(ensName: string) {
if (!client) return;
const resolvedEnsName = await client.getEnsAddress({ name: normalize(ensName) });
if (!resolvedEnsName) {
notification.error("ENS name not found");
Expand All @@ -75,6 +71,7 @@ export const Navbar = () => {
} else if (isAddress(trimmedAddress)) {
setResolvedAddress(trimmedAddress);
async function getEnsName(address: Address) {
if (!client) return;
const ensName = await client.getEnsName({ address });
router.push(`/${ensName || address}`, undefined, { shallow: true });
setEnsName(ensName || "");
Expand Down
1 change: 1 addition & 0 deletions packages/nextjs/components/address-vision/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from "./NftsCarousel";
export * from "./QRCodeCard";
export * from "./SafeOwner";
export * from "./TokensTable";
export * from "./TotalBalanceCard";
18 changes: 9 additions & 9 deletions packages/nextjs/pages/[address].tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { useEffect } from "react";
import { useRouter } from "next/router";
import type { GetServerSideProps, NextPage } from "next";
import { createPublicClient, http, isAddress } from "viem";
import { mainnet } from "viem/chains";
import { isAddress } from "viem";
import * as chains from "wagmi/chains";
import { MetaHeader } from "~~/components/MetaHeader";
import { AddressCard, ButtonsCard, Navbar, NetworkCard, QRCodeCard } from "~~/components/address-vision/";
import { TotalBalanceCard } from "~~/components/address-vision/TotalBalanceCard";
import {
AddressCard,
ButtonsCard,
Navbar,
NetworkCard,
QRCodeCard,
TotalBalanceCard,
} from "~~/components/address-vision/";
import { useAddressStore } from "~~/services/store/store";

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

type Props = {
address: string;
};
Expand Down
3 changes: 2 additions & 1 deletion packages/nextjs/services/web3/wagmiConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { http } from "viem";
import { mainnet } from "viem/chains";
import { createConfig } from "wagmi";
import { getAlchemyHttpUrl } from "~~/utils/scaffold-eth";

export const wagmiConfig = createConfig({
chains: [mainnet],
ssr: true,
transports: {
[mainnet.id]: http(),
[mainnet.id]: http(getAlchemyHttpUrl(1)),
},
});
Loading