Skip to content

Commit

Permalink
working
Browse files Browse the repository at this point in the history
  • Loading branch information
ZYJLiu committed May 10, 2022
1 parent 677f113 commit dfbdd75
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
38 changes: 20 additions & 18 deletions components/BalanceDisplay.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import { useConnection, useWallet } from '@solana/wallet-adapter-react';
import { LAMPORTS_PER_SOL } from '@solana/web3.js';
import {FC, useEffect, useState } from 'react'
import { useConnection, useWallet } from "@solana/wallet-adapter-react";
import { LAMPORTS_PER_SOL } from "@solana/web3.js";
import { FC, useEffect, useState } from "react";

export const BalanceDisplay: FC = () => {
const [balance, setBalance] = useState(0);
const { connection } = useConnection();
const { publicKey } = useWallet();
const [balance, setBalance] = useState(0);
const { connection } = useConnection();
const { publicKey } = useWallet();

useEffect(() => {
if (!connection || !publicKey) { return }
useEffect(() => {
if (!connection || !publicKey) {
return;
}

connection.getAccountInfo(publicKey).then(info => {
setBalance(info.lamports);
})
}, [connection, publicKey])
connection.getAccountInfo(publicKey).then((info) => {
setBalance(info.lamports);
});
}, [connection, publicKey]);

return (
<div>
<p>{publicKey ? `Balance: ${balance / LAMPORTS_PER_SOL}` : ''}</p>
</div>
)
}
return (
<div>
<p>{publicKey ? `SOL Balance: ${balance / LAMPORTS_PER_SOL}` : ""}</p>
</div>
);
};
3 changes: 1 addition & 2 deletions components/CreateTokenAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const CreateTokenAccountForm: FC = () => {

return (
<div>
<br />
{publicKey ? (
<form onSubmit={createTokenAccount} className={styles.form}>
<label htmlFor="owner">Token Mint:</label>
Expand All @@ -68,7 +69,6 @@ export const CreateTokenAccountForm: FC = () => {
placeholder="Enter Token Mint"
required
/>
<br />
<label htmlFor="owner">Token Account Owner:</label>
<input
id="owner"
Expand All @@ -77,7 +77,6 @@ export const CreateTokenAccountForm: FC = () => {
placeholder="Enter Token Account Owner PublicKey"
required
/>
<br />
<button type="submit" className={styles.formButton}>
Create Token Account
</button>
Expand Down
3 changes: 1 addition & 2 deletions components/MintToForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const MintToForm: FC = () => {

return (
<div>
<br />
{publicKey ? (
<form onSubmit={mintTo} className={styles.form}>
<label htmlFor="mint">Token Mint:</label>
Expand All @@ -69,7 +70,6 @@ export const MintToForm: FC = () => {
placeholder="Enter Token Mint"
required
/>
<br />
<label htmlFor="recipient">Recipient:</label>
<input
id="recipient"
Expand All @@ -78,7 +78,6 @@ export const MintToForm: FC = () => {
placeholder="Enter Recipient PublicKey"
required
/>
<br />
<label htmlFor="amount">Amount Tokens to Mint:</label>
<input
id="amount"
Expand Down

0 comments on commit dfbdd75

Please sign in to comment.