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 ( +
+

Give tokens to buildor

+

+ {isLoading && 'Loading...'} + {nb > 1000 ? ( + + ) : ( + nvm u broke, sowy + )} +

+
+ ); +}; diff --git a/src/App.tsx b/src/App.tsx index 0b8c4bb..2d3e8dc 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -2,6 +2,7 @@ import { FiExternalLink } from 'react-icons/fi'; import { useAccount } from 'wagmi'; import { ConnectButton } from '../components/ConnectButton'; +import { DonatePoints } from '../components/DonatePoints'; import { MaxSupply } from '../components/MaxSupply'; import { YourBalance } from '../components/YourBalance'; @@ -57,6 +58,9 @@ export const App = () => {
+
+ +