Skip to content
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 #359

Merged
merged 1 commit into from
Dec 10, 2024
Merged

fix #359

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
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, []);
mehdi-torabiv marked this conversation as resolved.
Show resolved Hide resolved
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);
}
};
mehdi-torabiv marked this conversation as resolved.
Show resolved Hide resolved

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]);
mehdi-torabiv marked this conversation as resolved.
Show resolved Hide resolved

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
Loading