Skip to content

chore: new release #500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions allowlists/getAllowListRecordsForAddressByClaimed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion app/profile/[address]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -24,6 +25,7 @@ export default function ProfilePage({
return (
<section className="flex flex-col gap-2">
<ContractAccountBanner address={address} />
<ProfileAccountSwitcher address={address} />
<section className="flex flex-wrap gap-2 items-center">
<h1 className="font-serif text-3xl lg:text-5xl tracking-tight">
Profile
Expand Down
41 changes: 41 additions & 0 deletions components/profile/account-switcher.tsx
Original file line number Diff line number Diff line change
@@ -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;
}
10 changes: 4 additions & 6 deletions components/profile/contract-accounts-banner.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<div className="bg-yellow-50 border-l-4 border-yellow-400 p-4 mb-4">
Expand Down
12 changes: 9 additions & 3 deletions hooks/use-hypercert-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ import { useEffect, useState } from "react";
import { useAccount, useWalletClient } from "wagmi";
import { ENVIRONMENT, SUPPORTED_CHAINS } from "@/configs/constants";
import { EvmClientFactory } from "@/lib/evmClient";
import { PublicClient } from "viem";

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

const publicClient = walletClient?.chain.id
? EvmClientFactory.createClient(walletClient.chain.id)
: undefined;
let publicClient: PublicClient | undefined;
try {
publicClient = walletClient?.chain.id
? EvmClientFactory.createClient(walletClient.chain.id)
: undefined;
} catch (error) {
console.error(`Error creating public client: ${error}`);
}

useEffect(() => {
if (!walletClient || !isConnected) {
Expand Down
27 changes: 27 additions & 0 deletions lib/isContract.ts
Original file line number Diff line number Diff line change
@@ -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
);
Loading