Skip to content

Commit

Permalink
updates to <profile /> prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
fakepixels committed Oct 3, 2024
1 parent 92b23a5 commit c069560
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function Page() {
</div>
</section>
<section className="templateSection flex w-full flex-col items-center justify-center gap-4 rounded-xl bg-gray-100 px-2 py-4 md:grow">
<div className="flex h-[450px] w-[450px] max-w-full items-center justify-center rounded-xl bg-[#030712]">
<div className="flex h-[450px] w-[450px] max-w-full items-center justify-center rounded-xl bg-[#140431]">
<IdentityWrapper />
</div>
</section>
Expand Down
8 changes: 8 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { createPublicClient, http } from 'viem'

import { mainnet } from 'viem/chains'

export const publicClient = createPublicClient({
chain: mainnet,
transport: http()
})
68 changes: 52 additions & 16 deletions src/components/IdentityWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,57 @@ import {
Avatar,
Name
} from '@coinbase/onchainkit/identity';
import { base } from 'viem/chains';
import { useAccount } from 'wagmi';

export default function IdentityWrapper() {
const { address } = useAccount();
return (
<div className="mx-auto max-w-2xl p-4">
{address && (
<div className="relative space-y-2">
<div className="flex items-center space-x-4 rounded-full bg-white bg-opacity-20 p-2 transition-all duration-300 hover:bg-opacity-30">
<Avatar address={address} chain={base} />
<Name address={address} chain={base} className="text-m text-white" />
</div>
import { base } from 'viem/chains';
import { useAccount } from 'wagmi';
import { normalize } from 'viem/ens'
import { publicClient } from '../client'
import { useEffect, useState } from 'react';
import { getName } from '@coinbase/onchainkit/identity';

export default function IdentityWrapper() {
const { address } = useAccount();
const [ensText, setEnsText] = useState<string | null>(null);

useEffect(() => {
console.log("Address:", address); // Debug log
const fetchEnsText = async () => {
if (address) {
try {
const name = await getName({chain: base, address: address}); // Get the name of the address
console.log("Name:", name);
const normalizedAddress = normalize(name as string); // Normalize the fetched name
console.log("Normalized Address:", normalizedAddress);
const text = await publicClient.getEnsText({
name: normalizedAddress,
key: 'com.twitter'
});
console.log("ENS Text Response:", text);
setEnsText(text);
} catch (error) {
console.error("Error fetching ENS text:", error);
}
}
};
fetchEnsText();
}, [address]);

return (
<div className="mx-auto max-w-2xl p-4">
{address ? (
<div className="relative space-y-2">
<div className="flex items-center space-x-4 rounded-full bg-white bg-opacity-20 p-2 transition-all duration-300 hover:bg-opacity-30">
<Avatar address={address} chain={base} />
<Name address={address} chain={base} className="text-m text-white" />
</div>
)}
</div>
);
{ensText && (
<div className="text-white">
Twitter account: <a href={`https://x.com/${ensText}`} target="_blank" rel="noopener noreferrer" className="hover:underline">{ensText}</a>
</div>
)}
</div>
) : (
<div className="text-white">No address found</div> // Debug message
)}
</div>
);
}

0 comments on commit c069560

Please sign in to comment.