diff --git a/src/components/RequestAirdrop.tsx b/src/components/RequestAirdrop.tsx index 686b979..105fc63 100644 --- a/src/components/RequestAirdrop.tsx +++ b/src/components/RequestAirdrop.tsx @@ -1,57 +1,70 @@ -import { useConnection, useWallet } from '@solana/wallet-adapter-react'; -import { LAMPORTS_PER_SOL, TransactionSignature } from '@solana/web3.js'; -import { FC, useCallback } from 'react'; +import { useConnection, useWallet } from "@solana/wallet-adapter-react"; +import { LAMPORTS_PER_SOL, TransactionSignature } from "@solana/web3.js"; +import { FC, useCallback } from "react"; import { notify } from "../utils/notifications"; -import useUserSOLBalanceStore from '../stores/useUserSOLBalanceStore'; +import useUserSOLBalanceStore from "../stores/useUserSOLBalanceStore"; export const RequestAirdrop: FC = () => { - const { connection } = useConnection(); - const { publicKey } = useWallet(); - const { getUserSOLBalance } = useUserSOLBalanceStore(); - - const onClick = useCallback(async () => { - if (!publicKey) { - console.log('error', 'Wallet not connected!'); - notify({ type: 'error', message: 'error', description: 'Wallet not connected!' }); - return; - } - - let signature: TransactionSignature = ''; - - try { - signature = await connection.requestAirdrop(publicKey, LAMPORTS_PER_SOL); - - // Get the lates block hash to use on our transaction and confirmation - let latestBlockhash = await connection.getLatestBlockhash() - await connection.confirmTransaction({ signature, ...latestBlockhash }, 'confirmed'); - - notify({ type: 'success', message: 'Airdrop successful!', txid: signature }); - - getUserSOLBalance(publicKey, connection); - } catch (error: any) { - notify({ type: 'error', message: `Airdrop failed!`, description: error?.message, txid: signature }); - console.log('error', `Airdrop failed! ${error?.message}`, signature); - } - }, [publicKey, connection, getUserSOLBalance]); - - return ( - -