Skip to content

Commit

Permalink
Introduce Gib Button
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemans committed Dec 15, 2023
1 parent d1ca3e3 commit a2aeefd
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
74 changes: 74 additions & 0 deletions components/DonatePoints.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<div>
<h2>Give tokens to buildor</h2>
<p className="text-right">
{isLoading && 'Loading...'}
{nb > 1000 ? (
<button
onClick={() => {
write();
}}
className="w-1/3 text-xs px-2 py-3 bg-ens-light-blue-bright hover:bg-ens-light-blue-primary text-white font-bold text-center rounded-lg active:bg-ens-light-blue-active"
>
Gib smol amount
</button>
) : (
<span>nvm u broke, sowy</span>
)}
</p>
</div>
);
};
4 changes: 4 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -57,6 +58,9 @@ export const App = () => {
<div>
<YourBalance />
</div>
<div>
<DonatePoints />
</div>
<a
href="https://app.uniswap.org/swap"
target="_blank"
Expand Down

0 comments on commit a2aeefd

Please sign in to comment.