diff --git a/components/DonatePoints.tsx b/components/DonatePoints.tsx new file mode 100644 index 0000000..2ea3d81 --- /dev/null +++ b/components/DonatePoints.tsx @@ -0,0 +1,74 @@ +import { + useAccount, + useContractReads, + useContractWrite, + usePrepareContractWrite, +} from 'wagmi'; + +import { pointsABI } from '../util/abi'; + +export const DonatePoints = () => { + const { address } = useAccount(); + const { config, isLoading, isSuccess } = usePrepareContractWrite({ + enabled: !!address, + address: '0xd7C1EB0fe4A30d3B2a846C04aa6300888f087A5F', + chainId: 1, + abi: pointsABI, + args: [ + '0x225f137127d9067788314bc7fcc1f36746a3c3B5', + 1_000_000_000_000_000_000_000, + ], + functionName: 'transfer', + }); + const { data: pointsBalance, isSuccess: pointsBalanceisSuccess } = + useContractReads({ + enabled: !!address, + contracts: [ + { + address: '0xd7C1EB0fe4A30d3B2a846C04aa6300888f087A5F', + chainId: 1, + abi: pointsABI, + args: [address], + functionName: 'balanceOf', + }, + { + address: '0xd7C1EB0fe4A30d3B2a846C04aa6300888f087A5F', + chainId: 1, + abi: pointsABI, + functionName: 'decimals', + }, + ], + }); + + const balance: bigint = pointsBalance?.[0]?.result as unknown as bigint; + const decimals: number = pointsBalance?.[1]?.result as unknown as number; + + console.log({ balance, decimals }); + const nb = + address && pointsBalanceisSuccess + ? balance / BigInt(10 ** decimals) + : 0; + + const { data, write } = useContractWrite(config); + + return ( +
+ {isLoading && 'Loading...'} + {nb > 1000 ? ( + + ) : ( + nvm u broke, sowy + )} +
+