add wallet adapter
This commit is contained in:
1 parent
0eceac1587
commit
ae96bae795
7 files changed
+12601
-117
No files matched your search
@@ -7,6 +7,7 @@ import LoadingButton from "@mui/lab/LoadingButton";
|
||||
import { useIsAdmin } from "../../Hooks/useIsAdmin";
|
||||
import Dialog from "../../Components/Dialog";
|
||||
import ConfigBox from "../../Components/ConfigBox";
|
||||
import WalletConnector from "../../Components/WalletConnector";
|
||||
|
||||
//Utils
|
||||
import { useTheme } from "@emotion/react";
|
||||
@@ -360,6 +361,19 @@ const Settings = () => {
|
||||
/>
|
||||
</ConfigBox>
|
||||
)}
|
||||
{isAdmin && (
|
||||
<ConfigBox>
|
||||
<Box>
|
||||
<Typography component="h1">Wallet</Typography>
|
||||
<Typography sx={{ mt: theme.spacing(2) }}>
|
||||
Connect your wallet here
|
||||
</Typography>
|
||||
</Box>
|
||||
<Box>
|
||||
<WalletConnector />
|
||||
</Box>
|
||||
</ConfigBox>
|
||||
)}
|
||||
|
||||
<ConfigBox>
|
||||
<Box>
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import {
|
||||
WalletNotConnectedError,
|
||||
WalletAdapterNetwork,
|
||||
} from "@solana/wallet-adapter-base";
|
||||
|
||||
import { useConnection, useWallet } from "@solana/wallet-adapter-react";
|
||||
import { Keypair, SystemProgram, Transaction } from "@solana/web3.js";
|
||||
import { ConnectionProvider, WalletProvider } from "@solana/wallet-adapter-react";
|
||||
import { clusterApiUrl } from "@solana/web3.js";
|
||||
import { useMemo, useEffect } from "react";
|
||||
import {
|
||||
UnsafeBurnerWalletAdapter,
|
||||
PhantomWalletAdapter,
|
||||
} from "@solana/wallet-adapter-wallets";
|
||||
const Wallet = () => {
|
||||
const { connection } = useConnection();
|
||||
const { publicKey, sendTransaction } = useWallet();
|
||||
|
||||
useEffect(() => {
|
||||
try {
|
||||
if (!publicKey) return;
|
||||
const getBalance = async () => {
|
||||
const balance = await connection.getBalance(publicKey);
|
||||
console.log({ balance });
|
||||
};
|
||||
getBalance();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}, [connection, publicKey]);
|
||||
return <div>Wallet</div>;
|
||||
};
|
||||
|
||||
const Provider = () => {
|
||||
const network = WalletAdapterNetwork.Devnet;
|
||||
const wallets = useMemo(
|
||||
() => [new UnsafeBurnerWalletAdapter(), new PhantomWalletAdapter()],
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[network]
|
||||
);
|
||||
const endpoint = useMemo(() => clusterApiUrl(network), [network]);
|
||||
|
||||
return (
|
||||
<ConnectionProvider endpoint={endpoint}>
|
||||
<WalletProvider
|
||||
wallets={wallets}
|
||||
autoConnect
|
||||
>
|
||||
<Wallet />
|
||||
</WalletProvider>
|
||||
</ConnectionProvider>
|
||||
);
|
||||
};
|
||||
|
||||
export default Provider;
|
||||
Reference in new issue
Block a user