Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-torabiv committed Dec 10, 2024
1 parent 5c0b264 commit cf5d643
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 27 deletions.
7 changes: 2 additions & 5 deletions src/pages/reputation-score/[...score].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -176,4 +173,4 @@ const ScorePage = () => {
);
};

export default ScorePage;
export default withRoles(ScorePage, []);
63 changes: 41 additions & 22 deletions src/pages/reputation-score/mint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ function Mint() {
address,
conf.APP_DEVELOPER_PUBLIC_ADDRESS as `0x${string}`
);

setUserProfile(result);
setLoading(false);
} catch (error) {
Expand Down Expand Up @@ -168,7 +169,6 @@ const AttestationSection: React.FC<AttestationSectionProps> = ({
isLoading,
userProfile,
}) => {

const handleNavigation = () => {
const url = 'https://app.logid.xyz/permissions';
window.open(url, '_blank');
Expand Down Expand Up @@ -246,7 +246,7 @@ const MintSection: React.FC<MintSectionProps> = ({

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',
Expand All @@ -259,10 +259,39 @@ const MintSection: React.FC<MintSectionProps> = ({
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 (
<Stack className='space-y-4'>
<Stack className='space-y-2 px-4 pb-[1rem] pt-4 md:px-10'>
Expand Down Expand Up @@ -315,26 +344,16 @@ const MintSection: React.FC<MintSectionProps> = ({
<Button
variant='contained'
color='primary'
onClick={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);
}
}}
disabled={isPending || !dynamicNFTModuleInfo?.metadata[0]?.tokenId}
onClick={handleMintNFT}
disabled={
isPending ||
isWaitingForReceiptConfirmation ||
!dynamicNFTModuleInfo?.metadata[0]?.tokenId
}
>
{isPending ? 'Minting...' : 'Mint Reputation Score'}
{isPending || isWaitingForReceiptConfirmation
? 'Minting...'
: 'Mint Reputation Score'}
</Button>
)}
</Stack>
Expand Down

0 comments on commit cf5d643

Please sign in to comment.