diff --git a/allowlists/getAllowListRecordsForAddressByClaimed.tsx b/allowlists/getAllowListRecordsForAddressByClaimed.tsx index bc70ddd6..78c83bc7 100644 --- a/allowlists/getAllowListRecordsForAddressByClaimed.tsx +++ b/allowlists/getAllowListRecordsForAddressByClaimed.tsx @@ -42,10 +42,18 @@ export async function getAllowListRecordsForAddressByClaimed( address: string, claimed: boolean, ) { - const res = await request(HYPERCERTS_API_URL_GRAPH, query, { - address, - claimed, - }); + const res = await request( + HYPERCERTS_API_URL_GRAPH, + query, + { + address, + claimed, + }, + new Headers({ + "Cache-Control": "no-cache", + Pragma: "no-cache", + }), + ); const allowlistRecords = res.allowlistRecords.data; if (!allowlistRecords) { diff --git a/app/profile/[address]/page.tsx b/app/profile/[address]/page.tsx index 45a41194..5f8e196a 100644 --- a/app/profile/[address]/page.tsx +++ b/app/profile/[address]/page.tsx @@ -8,8 +8,9 @@ import { HypercertsTabContent } from "@/app/profile/[address]/hypercerts-tab-con import { CollectionsTabContent } from "@/app/profile/[address]/collections-tab-content"; import { MarketplaceTabContent } from "@/app/profile/[address]/marketplace-tab-content"; import { BlueprintsTabContent } from "@/app/profile/[address]/blueprint-tab-content"; - import { ContractAccountBanner } from "@/components/profile/contract-accounts-banner"; +import { ProfileAccountSwitcher } from "@/components/profile/account-switcher"; + export default function ProfilePage({ params, searchParams, @@ -24,6 +25,7 @@ export default function ProfilePage({ return (
+

Profile diff --git a/components/profile/account-switcher.tsx b/components/profile/account-switcher.tsx new file mode 100644 index 00000000..021ad252 --- /dev/null +++ b/components/profile/account-switcher.tsx @@ -0,0 +1,41 @@ +"use client"; + +import { useAccount } from "wagmi"; +import { useEffect } from "react"; +import { useRouter } from "next/navigation"; + +import { useAccountStore } from "@/lib/account-store"; +import { useSafeAccounts } from "@/hooks/useSafeAccounts"; + +export function ProfileAccountSwitcher({ address }: { address: string }) { + const { address: connectedAddress } = useAccount(); + const { safeAccounts } = useSafeAccounts(); + const router = useRouter(); + const selectedAccount = useAccountStore((state) => state.selectedAccount); + + useEffect(() => { + if (!selectedAccount || !connectedAddress) return; + + const currentAddress = address.toLowerCase(); + const accounts = [ + { type: "eoa", address: connectedAddress }, + ...safeAccounts, + ]; + + // Find current account index + const currentIndex = accounts.findIndex( + (account) => account.address.toLowerCase() === currentAddress, + ); + + // If current address matches the connected address or a safe address the user is a signer on, + // and it's not the selected account, redirect to the selected account + if ( + currentIndex !== -1 && + currentAddress !== selectedAccount.address.toLowerCase() + ) { + router.push(`/profile/${selectedAccount.address}`); + } + }, [selectedAccount, address, connectedAddress, safeAccounts, router]); + + return null; +} diff --git a/components/profile/contract-accounts-banner.tsx b/components/profile/contract-accounts-banner.tsx index 28c5113d..43b3efdc 100644 --- a/components/profile/contract-accounts-banner.tsx +++ b/components/profile/contract-accounts-banner.tsx @@ -1,11 +1,9 @@ -"use client"; +import { isContract } from "@/lib/isContract"; -import { useIsContract } from "@/hooks/useIsContract"; +export async function ContractAccountBanner({ address }: { address: string }) { + const isContractAddress = await isContract(address); -export function ContractAccountBanner({ address }: { address: string }) { - const { isContract, isLoading } = useIsContract(address); - - if (!isContract || isLoading) return null; + if (!isContractAddress) return null; return (
diff --git a/lib/isContract.ts b/lib/isContract.ts new file mode 100644 index 00000000..c4e79bf9 --- /dev/null +++ b/lib/isContract.ts @@ -0,0 +1,27 @@ +import { ChainFactory } from "./chainFactory"; +import { EvmClientFactory } from "./evmClient"; +import { unstable_cache } from "next/cache"; + +export const isContract = unstable_cache( + async (address: string) => { + const supportedChains = ChainFactory.getSupportedChains(); + const clients = supportedChains.map((chainId) => + EvmClientFactory.createClient(chainId), + ); + + const results = await Promise.allSettled( + clients.map((client) => + client.getCode({ address: address as `0x${string}` }), + ), + ); + + return results.some( + (result) => + result.status === "fulfilled" && + result.value !== undefined && + result.value !== "0x", + ); + }, + ["isContract"], + { revalidate: 604800 }, // 1 week +);