Skip to content
This repository has been archived by the owner on Nov 15, 2024. It is now read-only.

Commit

Permalink
update #rebuildroles
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJonaseb11 committed Oct 26, 2024
1 parent a7b24d8 commit 8e70815
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions packages/nextjs/app/(app)/account/page.client.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,48 @@
/* 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";
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<string>("");

// 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 (
<div>
<AddressInput onChange={setAddress} value={address} placeholder="Input your address" />
<AddressQRCodeModal address={connectedAddress as Address} modalId="qr-code modal" />
<AddressInput
onChange={handleAddressChange}
value={address}
placeholder="Input your address"
/>
<AddressQRCodeModal address={connectedAddress as Address} modalId="qr-code-modal" />
<div className="flex justify-center flex-col items-center">
<p className="font-medium text-lg">Account Balance</p>
<Balance address={connectedAddress as Address} />
Expand All @@ -32,7 +53,11 @@ export const AccountPageClient: React.FC = () => {
Disconnect
</button>
</div>
<AddressInfoDropdown blockExplorerAddressLink="" displayName="" address={connectedAddress as Address} />
<AddressInfoDropdown
blockExplorerAddressLink="" // Provide a valid link if available
displayName="" // Provide a valid display name if available
address={connectedAddress as Address}
/>
</div>
);
};

0 comments on commit 8e70815

Please sign in to comment.