Skip to content

Commit 926faae

Browse files
authored
Merge pull request #500 from hypercerts-org/dev
chore: new release
2 parents 8983d77 + 0849cd4 commit 926faae

File tree

6 files changed

+96
-14
lines changed

6 files changed

+96
-14
lines changed

allowlists/getAllowListRecordsForAddressByClaimed.tsx

+12-4
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,18 @@ export async function getAllowListRecordsForAddressByClaimed(
4242
address: string,
4343
claimed: boolean,
4444
) {
45-
const res = await request(HYPERCERTS_API_URL_GRAPH, query, {
46-
address,
47-
claimed,
48-
});
45+
const res = await request(
46+
HYPERCERTS_API_URL_GRAPH,
47+
query,
48+
{
49+
address,
50+
claimed,
51+
},
52+
new Headers({
53+
"Cache-Control": "no-cache",
54+
Pragma: "no-cache",
55+
}),
56+
);
4957

5058
const allowlistRecords = res.allowlistRecords.data;
5159
if (!allowlistRecords) {

app/profile/[address]/page.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import { HypercertsTabContent } from "@/app/profile/[address]/hypercerts-tab-con
88
import { CollectionsTabContent } from "@/app/profile/[address]/collections-tab-content";
99
import { MarketplaceTabContent } from "@/app/profile/[address]/marketplace-tab-content";
1010
import { BlueprintsTabContent } from "@/app/profile/[address]/blueprint-tab-content";
11-
1211
import { ContractAccountBanner } from "@/components/profile/contract-accounts-banner";
12+
import { ProfileAccountSwitcher } from "@/components/profile/account-switcher";
13+
1314
export default function ProfilePage({
1415
params,
1516
searchParams,
@@ -24,6 +25,7 @@ export default function ProfilePage({
2425
return (
2526
<section className="flex flex-col gap-2">
2627
<ContractAccountBanner address={address} />
28+
<ProfileAccountSwitcher address={address} />
2729
<section className="flex flex-wrap gap-2 items-center">
2830
<h1 className="font-serif text-3xl lg:text-5xl tracking-tight">
2931
Profile
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"use client";
2+
3+
import { useAccount } from "wagmi";
4+
import { useEffect } from "react";
5+
import { useRouter } from "next/navigation";
6+
7+
import { useAccountStore } from "@/lib/account-store";
8+
import { useSafeAccounts } from "@/hooks/useSafeAccounts";
9+
10+
export function ProfileAccountSwitcher({ address }: { address: string }) {
11+
const { address: connectedAddress } = useAccount();
12+
const { safeAccounts } = useSafeAccounts();
13+
const router = useRouter();
14+
const selectedAccount = useAccountStore((state) => state.selectedAccount);
15+
16+
useEffect(() => {
17+
if (!selectedAccount || !connectedAddress) return;
18+
19+
const currentAddress = address.toLowerCase();
20+
const accounts = [
21+
{ type: "eoa", address: connectedAddress },
22+
...safeAccounts,
23+
];
24+
25+
// Find current account index
26+
const currentIndex = accounts.findIndex(
27+
(account) => account.address.toLowerCase() === currentAddress,
28+
);
29+
30+
// If current address matches the connected address or a safe address the user is a signer on,
31+
// and it's not the selected account, redirect to the selected account
32+
if (
33+
currentIndex !== -1 &&
34+
currentAddress !== selectedAccount.address.toLowerCase()
35+
) {
36+
router.push(`/profile/${selectedAccount.address}`);
37+
}
38+
}, [selectedAccount, address, connectedAddress, safeAccounts, router]);
39+
40+
return null;
41+
}

components/profile/contract-accounts-banner.tsx

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
"use client";
1+
import { isContract } from "@/lib/isContract";
22

3-
import { useIsContract } from "@/hooks/useIsContract";
3+
export async function ContractAccountBanner({ address }: { address: string }) {
4+
const isContractAddress = await isContract(address);
45

5-
export function ContractAccountBanner({ address }: { address: string }) {
6-
const { isContract, isLoading } = useIsContract(address);
7-
8-
if (!isContract || isLoading) return null;
6+
if (!isContractAddress) return null;
97

108
return (
119
<div className="bg-yellow-50 border-l-4 border-yellow-400 p-4 mb-4">

hooks/use-hypercert-client.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@ import { useEffect, useState } from "react";
44
import { useAccount, useWalletClient } from "wagmi";
55
import { ENVIRONMENT, SUPPORTED_CHAINS } from "@/configs/constants";
66
import { EvmClientFactory } from "@/lib/evmClient";
7+
import { PublicClient } from "viem";
78

89
export const useHypercertClient = () => {
910
const { data: walletClient } = useWalletClient();
1011
const { isConnected } = useAccount();
1112
const [client, setClient] = useState<HypercertClient>();
1213

13-
const publicClient = walletClient?.chain.id
14-
? EvmClientFactory.createClient(walletClient.chain.id)
15-
: undefined;
14+
let publicClient: PublicClient | undefined;
15+
try {
16+
publicClient = walletClient?.chain.id
17+
? EvmClientFactory.createClient(walletClient.chain.id)
18+
: undefined;
19+
} catch (error) {
20+
console.error(`Error creating public client: ${error}`);
21+
}
1622

1723
useEffect(() => {
1824
if (!walletClient || !isConnected) {

lib/isContract.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { ChainFactory } from "./chainFactory";
2+
import { EvmClientFactory } from "./evmClient";
3+
import { unstable_cache } from "next/cache";
4+
5+
export const isContract = unstable_cache(
6+
async (address: string) => {
7+
const supportedChains = ChainFactory.getSupportedChains();
8+
const clients = supportedChains.map((chainId) =>
9+
EvmClientFactory.createClient(chainId),
10+
);
11+
12+
const results = await Promise.allSettled(
13+
clients.map((client) =>
14+
client.getCode({ address: address as `0x${string}` }),
15+
),
16+
);
17+
18+
return results.some(
19+
(result) =>
20+
result.status === "fulfilled" &&
21+
result.value !== undefined &&
22+
result.value !== "0x",
23+
);
24+
},
25+
["isContract"],
26+
{ revalidate: 604800 }, // 1 week
27+
);

0 commit comments

Comments
 (0)