From a2aeefdb2e08108f46d2ab9f622b018e01b0e431 Mon Sep 17 00:00:00 2001 From: Luc Date: Fri, 15 Dec 2023 15:38:38 +0000 Subject: [PATCH] Introduce Gib Button --- components/DonatePoints.tsx | 74 +++++++++++++++++++++++++++++++++++++ src/App.tsx | 4 ++ 2 files changed, 78 insertions(+) create mode 100644 components/DonatePoints.tsx 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 = () => {
+
+ +