Skip to content

Commit

Permalink
setting up dns
Browse files Browse the repository at this point in the history
  • Loading branch information
tkorkmazeth committed Oct 4, 2024
1 parent a49d769 commit 40b5045
Showing 1 changed file with 66 additions and 53 deletions.
119 changes: 66 additions & 53 deletions src/components/RequestAirdrop.tsx
Original file line number Diff line number Diff line change
@@ -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 (

<div className="flex flex-row justify-center">
<div className="relative group items-center">
<div className="m-1 absolute -inset-0.5 bg-gradient-to-r from-indigo-500 to-fuchsia-500
rounded-lg blur opacity-20 group-hover:opacity-100 transition duration-1000 group-hover:duration-200 animate-tilt"></div>

<button
className="px-8 m-2 btn animate-pulse bg-gradient-to-br from-indigo-500 to-fuchsia-500 hover:from-white hover:to-purple-300 text-black"
onClick={onClick}
>
<span>Airdrop 1 </span>

</button>
</div>
</div>


);
};
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 (
<div className="flex flex-row justify-center">
<div className="relative group items-center">
<div
className="m-1 absolute -inset-0.5 bg-gradient-to-r from-indigo-500 to-fuchsia-500
rounded-lg blur opacity-20 group-hover:opacity-100 transition duration-1000 group-hover:duration-200 animate-tilt"
></div>

<button
className="px-8 m-2 btn animate-pulse bg-gradient-to-br from-indigo-500 to-fuchsia-500 hover:from-white hover:to-purple-300 text-black"
onClick={onClick}
>
<span>Recieve 1 Sol on Devnet</span>
</button>
</div>
</div>
);
};

0 comments on commit 40b5045

Please sign in to comment.