From cf5d6431eff12ae915a2761e1852be3ff1a0c1e8 Mon Sep 17 00:00:00 2001 From: mehditorabiv Date: Tue, 10 Dec 2024 11:48:25 +0300 Subject: [PATCH] fix --- src/pages/reputation-score/[...score].tsx | 7 +-- src/pages/reputation-score/mint.tsx | 63 +++++++++++++++-------- 2 files changed, 43 insertions(+), 27 deletions(-) diff --git a/src/pages/reputation-score/[...score].tsx b/src/pages/reputation-score/[...score].tsx index 965c2cb7..27f8b945 100644 --- a/src/pages/reputation-score/[...score].tsx +++ b/src/pages/reputation-score/[...score].tsx @@ -10,6 +10,7 @@ import TcBoxContainer from '@/components/shared/TcBox/TcBoxContainer'; import useAppStore from '@/store/useStore'; import { useSnackbar } from '@/context/SnackbarContext'; +import { withRoles } from '@/utils/withRoles'; const ScorePage = () => { const { showMessage } = useSnackbar(); @@ -41,19 +42,15 @@ const ScorePage = () => { const fetchReputationScore = async () => { setLoading(true); try { - console.log('Fetching reputation score for:', { tokenId, address }); - const score = await retrieveReputationScore({ tokenId, address, }); - console.log('Reputation Score Retrieved:', score); setReputationScore(score.reputationScore ?? 0); setCommunityName(score.communityName); } catch (error) { console.error('Error fetching reputation score:', error); - showMessage('Failed to load reputation score.', 'error'); } finally { setLoading(false); } @@ -176,4 +173,4 @@ const ScorePage = () => { ); }; -export default ScorePage; +export default withRoles(ScorePage, []); diff --git a/src/pages/reputation-score/mint.tsx b/src/pages/reputation-score/mint.tsx index bed43bb6..147a05aa 100644 --- a/src/pages/reputation-score/mint.tsx +++ b/src/pages/reputation-score/mint.tsx @@ -73,6 +73,7 @@ function Mint() { address, conf.APP_DEVELOPER_PUBLIC_ADDRESS as `0x${string}` ); + setUserProfile(result); setLoading(false); } catch (error) { @@ -168,7 +169,6 @@ const AttestationSection: React.FC = ({ isLoading, userProfile, }) => { - const handleNavigation = () => { const url = 'https://app.logid.xyz/permissions'; window.open(url, '_blank'); @@ -246,7 +246,7 @@ const MintSection: React.FC = ({ const { address } = useAccount(); const { dynamicNFTModuleInfo } = useAppStore(); - const { data: hasMinted } = useReadContract({ + const { data: hasMinted, refetch } = useReadContract({ address: engagementContract?.address as `0x${string}`, abi: engagementContract?.abi as Abi, functionName: 'balanceOf', @@ -259,10 +259,39 @@ const MintSection: React.FC = ({ isPending, } = useWriteContract(); - const { isPending: isWaiting } = useWaitForTransactionReceipt({ + const handleMintNFT = async () => { + try { + await writeContractAsync({ + address: engagementContract?.address as `0x${string}`, + abi: engagementContract?.abi as Abi, + functionName: 'mint', + args: [address, dynamicNFTModuleInfo.metadata[0].tokenId, 1, '0x0'], + }); + } catch (error: any) { + console.error('Mint failed:', error); + } + }; + + const { + data: receipt, + isSuccess, + isError, + isFetching: isWaitingForReceiptConfirmation, + } = useWaitForTransactionReceipt({ hash: transactionHash, }); + useEffect(() => { + if (receipt && isSuccess) { + showMessage( + 'Your Reputation NFT has been successfully minted!', + 'success' + ); + + refetch(); + } + }, [receipt, isSuccess, isError]); + return ( @@ -315,26 +344,16 @@ const MintSection: React.FC = ({ )}