Indicate more clearly that it takes SOL to add a token to your wallet

This commit is contained in:
nishadsingh1 2020-08-08 17:41:49 +08:00 committed by GitHub
parent 584684b4f2
commit 2d2e221c37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -12,6 +12,7 @@ import { useUpdateTokenName } from '../utils/tokens/names';
import { useAsyncData } from '../utils/fetch-loop'; import { useAsyncData } from '../utils/fetch-loop';
import LoadingIndicator from './LoadingIndicator'; import LoadingIndicator from './LoadingIndicator';
import { useSendTransaction } from '../utils/notifications'; import { useSendTransaction } from '../utils/notifications';
import { useBalanceInfo } from '../utils/wallet';
const feeFormat = new Intl.NumberFormat(undefined, { const feeFormat = new Intl.NumberFormat(undefined, {
minimumFractionDigits: 6, minimumFractionDigits: 6,
@ -30,6 +31,10 @@ export default function AddTokenDialog({ open, onClose }) {
let [tokenName, setTokenName] = useState(''); let [tokenName, setTokenName] = useState('');
let [tokenSymbol, setTokenSymbol] = useState(''); let [tokenSymbol, setTokenSymbol] = useState('');
let [sendTransaction, sending] = useSendTransaction(); let [sendTransaction, sending] = useSendTransaction();
let balanceInfo = useBalanceInfo(wallet.account.publicKey);
let { amount } = balanceInfo || {};
let noSol = amount === 0;
function onSubmit() { function onSubmit() {
let mint = new PublicKey(mintAddress); let mint = new PublicKey(mintAddress);
@ -81,8 +86,8 @@ export default function AddTokenDialog({ open, onClose }) {
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>
<Button onClick={onClose}>Cancel</Button> <Button onClick={onClose}>Cancel</Button>
<Button type="submit" color="primary" disabled={sending}> <Button type="submit" color="primary" disabled={sending || noSol}>
Add {noSol ? 'Requires SOL Balance' : 'Add'}
</Button> </Button>
</DialogActions> </DialogActions>
</DialogForm> </DialogForm>