-
Notifications
You must be signed in to change notification settings - Fork 72
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
fix: domain navigation #1001
fix: domain navigation #1001
Changes from 3 commits
589097d
aadcd72
346cfbc
a71c12b
1d40ddb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
import React, { useCallback, useEffect, useState } from "react"; | ||
import React, { useCallback, useEffect, useMemo, useState } from "react"; | ||
import homeStyles from "../../styles/Home.module.css"; | ||
import styles from "../../styles/components/identitiesV1.module.css"; | ||
import { useRouter } from "next/router"; | ||
import { NextPage } from "next"; | ||
import IdentityWarnings from "../../components/identities/identityWarnings"; | ||
import IdentityCard from "../../components/identities/identityCard"; | ||
import IdentityActions from "../../components/identities/actions/identityActions"; | ||
import { useAccount } from "@starknet-react/core"; | ||
import { | ||
useAccount, | ||
useConnect, | ||
useSendTransaction, | ||
} from "@starknet-react/core"; | ||
import IdentityPageSkeleton from "../../components/identities/skeletons/identityPageSkeleton"; | ||
import UpdateProfilePic from "../../components/identities/updateProfilePic"; | ||
import TxConfirmationModal from "../../components/UI/txConfirmationModal"; | ||
|
@@ -16,6 +20,11 @@ import { formatHexString } from "../../utils/stringService"; | |
import { getDomainData } from "@/utils/cacheDomainData"; | ||
import { useSearchParams } from "next/navigation"; | ||
import IdentityActionsSkeleton from "@/components/identities/skeletons/identityActionsSkeleton"; | ||
import { hexToDecimal } from "@/utils/feltService"; | ||
import AddButton from "@/components/UI/AddButtonIdentities"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can remove this import, it is not used |
||
import WalletConnect from "@/components/UI/walletConnect"; | ||
import { Connector } from "starknetkit"; | ||
import { FaPlus } from "react-icons/fa"; | ||
|
||
const TokenIdPage: NextPage = () => { | ||
const router = useRouter(); | ||
|
@@ -34,6 +43,23 @@ const TokenIdPage: NextPage = () => { | |
const [minting, setMinting] = useState(false); | ||
const searchParams = useSearchParams(); | ||
const mintingInUrl = searchParams.get("minting") === "true"; | ||
const { connectAsync, connectors } = useConnect(); | ||
const [ownedIdentities, setOwnedIdentities] = useState<FullId[]>([]); | ||
const randomTokenId: number = Math.floor(Math.random() * 1000000000000); | ||
const [showWalletConnectModal, setShowWalletConnectModal] = | ||
useState<boolean>(false); | ||
|
||
const callData = useMemo(() => { | ||
return { | ||
contractAddress: process.env.NEXT_PUBLIC_IDENTITY_CONTRACT as string, | ||
entrypoint: "mint", | ||
calldata: [randomTokenId.toString()], | ||
}; | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
const { sendAsync: execute } = useSendTransaction({ | ||
calls: [callData], | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for transaction execution. The - function mint() {
- execute();
+ async function mint() {
+ try {
+ await execute();
+ } catch (error) {
+ console.error('Failed to execute mint transaction:', error);
+ // Consider showing an error notification to the user
+ }
}
|
||
|
||
useEffect(() => { | ||
if (mintingInUrl) setMinting(true); | ||
|
@@ -126,6 +152,30 @@ const TokenIdPage: NextPage = () => { | |
} | ||
}, [tokenId, refreshData]); | ||
|
||
function mint() { | ||
execute(); | ||
} | ||
useEffect(() => { | ||
if (address) { | ||
// Our Indexer | ||
fetch( | ||
`${ | ||
process.env.NEXT_PUBLIC_SERVER_LINK | ||
}/addr_to_full_ids?addr=${hexToDecimal(address)}` | ||
) | ||
.then((response) => response.json()) | ||
.then((data) => { | ||
setOwnedIdentities(data.full_ids); | ||
}); | ||
} | ||
}, [address, router.asPath]); | ||
Marchand-Nicolas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const connectWallet = async (connector: Connector) => { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
await connectAsync({ connector }); | ||
localStorage.setItem("SID-connectedWallet", connector.id); | ||
localStorage.setItem("SID-lastUsedConnector", connector.id); | ||
}; | ||
Marchand-Nicolas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return ( | ||
<> | ||
<div className={styles.screen}> | ||
|
@@ -136,33 +186,67 @@ const TokenIdPage: NextPage = () => { | |
<div className={styles.backButton}> | ||
<BackButton onClick={() => window.history.back()} /> | ||
</div> | ||
<div className={styles.containerIdentity}> | ||
<> | ||
<div className={styles.identityBox}> | ||
<IdentityCard | ||
identity={identity} | ||
tokenId={tokenId} | ||
isOwner={isOwner} | ||
onPPClick={() => setIsUpdatingPp(true)} | ||
ppImageUrl={ppImageUrl} | ||
/> | ||
{!hideActions ? ( | ||
<IdentityActions | ||
isOwner={isOwner} | ||
tokenId={tokenId} | ||
isIdentityADomain={isIdentityADomain} | ||
<div className="flex-col flex md:flex-row gap-5 md:gap-8 md:pl-5 mb-6"> | ||
<div | ||
className={`${ | ||
!hideActions ? "lg:mx-0" : "lg:ml-20 border" | ||
} mx-auto mt-5 md:mt-0 md:mx-0 bg-[#FFFFFF] w-[90%] md:w-[217px] shadow-sm rounded-2xl h-[319px] md:h-[533px] md:p-5 relative text-center border border-[#4545451A]`} | ||
> | ||
<div className="h-[280px] md:h-[480px] overflow-y-auto"> | ||
{ownedIdentities.map((domain, index) => ( | ||
<button | ||
className={`${ | ||
domain.id === router.query.tokenId | ||
? "text-[#402D28] hover:text-[#CDCCCC]" | ||
: " text-[#CDCCCC] hover:text-[#402D28]" | ||
}font-medium text-lg leading-5 cursor-pointer border-[#CDCCCC] border-b md:border-none md:py-0 py-6 md:my-3 block w-full`} | ||
key={index} | ||
onClick={() => router.push(`/identities/${domain.id}`)} | ||
> | ||
{domain.domain ? domain.domain : domain.id} | ||
</button> | ||
))} | ||
</div> | ||
<button | ||
className="bottom-4 w-full justify-center text-center items-center font-quickZap font-normal flex gap-2" | ||
onClick={ | ||
address | ||
? () => mint() | ||
: () => setShowWalletConnectModal(true) | ||
} | ||
> | ||
<FaPlus /> | ||
ADD IDENTITIES | ||
</button> | ||
</div> | ||
<div className={styles.containerIdentity}> | ||
<> | ||
<div className={styles.identityBox}> | ||
<IdentityCard | ||
identity={identity} | ||
hideActionsHandler={hideActionsHandler} | ||
tokenId={tokenId} | ||
isOwner={isOwner} | ||
onPPClick={() => setIsUpdatingPp(true)} | ||
ppImageUrl={ppImageUrl} | ||
/> | ||
) : ( | ||
minting && <IdentityActionsSkeleton /> | ||
)} | ||
</div> | ||
<IdentityWarnings | ||
isIdentityADomain={isIdentityADomain} | ||
identity={identity} | ||
/> | ||
</> | ||
{!hideActions ? ( | ||
<IdentityActions | ||
isOwner={isOwner} | ||
tokenId={tokenId} | ||
isIdentityADomain={isIdentityADomain} | ||
identity={identity} | ||
hideActionsHandler={hideActionsHandler} | ||
/> | ||
) : ( | ||
minting && <IdentityActionsSkeleton /> | ||
)} | ||
</div> | ||
<IdentityWarnings | ||
isIdentityADomain={isIdentityADomain} | ||
identity={identity} | ||
/> | ||
</> | ||
</div> | ||
</div> | ||
</div> | ||
) : ( | ||
|
@@ -180,6 +264,12 @@ const TokenIdPage: NextPage = () => { | |
closeModal={() => setIsTxModalOpen(false)} | ||
title="Your new profile picture is being set !" | ||
/> | ||
<WalletConnect | ||
closeModal={() => setShowWalletConnectModal(false)} | ||
open={showWalletConnectModal} | ||
connectors={connectors as Connector[]} | ||
connectWallet={connectWallet} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of redirecting the user, wrap your code from
pages/identities/[tokenId].tsx
in a component you can reuse in both files