From 8e70815d87890fb0753827bb4df3626267e381fe Mon Sep 17 00:00:00 2001 From: 0xJonaseb11 Date: Sat, 26 Oct 2024 18:48:10 +0200 Subject: [PATCH] update #rebuildroles --- .../nextjs/app/(app)/account/page.client.tsx | 41 +++++++++++++++---- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/packages/nextjs/app/(app)/account/page.client.tsx b/packages/nextjs/app/(app)/account/page.client.tsx index e540ceb..03260d5 100644 --- a/packages/nextjs/app/(app)/account/page.client.tsx +++ b/packages/nextjs/app/(app)/account/page.client.tsx @@ -1,7 +1,7 @@ /* eslint-disable prettier/prettier */ "use client"; -import { useState } from "react"; +import { useState, useEffect } from "react"; import { Address } from "viem"; import { useAccount, useDisconnect } from "wagmi"; import { Balance } from "~~/components/scaffold-eth"; @@ -9,19 +9,40 @@ import { AddressInput } from "~~/components/scaffold-eth"; import { AddressInfoDropdown } from "~~/components/scaffold-eth/RainbowKitCustomConnectButton/AddressInfoDropdown"; import { AddressQRCodeModal } from "~~/components/scaffold-eth/RainbowKitCustomConnectButton/AddressQRCodeModal"; -/* eslint-disable prettier/prettier */ - -// import { Address } from "~~/components/scaffold-eth"; +// Helper function to validate Ethereum addresses +const isValidAddress = (addr: string): boolean => { + return /^(0x)?[0-9a-fA-F]{40}$/.test(addr); +}; export const AccountPageClient: React.FC = () => { const { address: connectedAddress } = useAccount(); const { disconnect } = useDisconnect(); - const [address, setAddress] = useState(""); + const [address, setAddress] = useState(""); + + // Effect to handle connected address initialization + useEffect(() => { + if (connectedAddress && isValidAddress(connectedAddress)) { + setAddress(connectedAddress); + } + }, [connectedAddress]); + + const handleAddressChange = (newAddress: string) => { + if (isValidAddress(newAddress)) { + setAddress(newAddress); + } else { + // Optionally handle invalid address case + console.error("Invalid address"); + } + }; return (
- - + +

Account Balance

@@ -32,7 +53,11 @@ export const AccountPageClient: React.FC = () => { Disconnect
- +
); };