Error toast in suggest button!
This commit is contained in:
		@@ -15,6 +15,7 @@ import Flex from "../Flex";
 | 
			
		||||
import { TxJson } from "./json";
 | 
			
		||||
import { TxUI } from "./ui";
 | 
			
		||||
import { default as _estimateFee } from "../../utils/estimateFee";
 | 
			
		||||
import toast from 'react-hot-toast';
 | 
			
		||||
 | 
			
		||||
export interface TransactionProps {
 | 
			
		||||
  header: string;
 | 
			
		||||
@@ -147,18 +148,23 @@ const Transaction: FC<TransactionProps> = ({
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  const estimateFee = useCallback(
 | 
			
		||||
    async (st?: TransactionState) => {
 | 
			
		||||
    async (st?: TransactionState, opts?: { silent?: boolean }) => {
 | 
			
		||||
      const state = st || txState;
 | 
			
		||||
      const ptx = prepareOptions(state);
 | 
			
		||||
      const account = accounts.find(
 | 
			
		||||
        acc => acc.address === state.selectedAccount?.value
 | 
			
		||||
      );
 | 
			
		||||
      if (!account) return;
 | 
			
		||||
      if (!account) {
 | 
			
		||||
        if (!opts?.silent) {
 | 
			
		||||
          toast.error("Please select account from the list.")
 | 
			
		||||
        }
 | 
			
		||||
        return
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
      ptx.Account = account.address;
 | 
			
		||||
      ptx.Sequence = account.sequence;
 | 
			
		||||
 | 
			
		||||
      const res = await _estimateFee(ptx, account, { silent: true });
 | 
			
		||||
      const res = await _estimateFee(ptx, account, opts);
 | 
			
		||||
      const fee = res?.base_fee;
 | 
			
		||||
      setState({ estimatedFee: fee });
 | 
			
		||||
      return fee;
 | 
			
		||||
 
 | 
			
		||||
@@ -21,7 +21,7 @@ interface UIProps {
 | 
			
		||||
    pTx?: Partial<TransactionState> | undefined
 | 
			
		||||
  ) => TransactionState | undefined;
 | 
			
		||||
  state: TransactionState;
 | 
			
		||||
  estimateFee?: (state?: TransactionState) => Promise<string | undefined>;
 | 
			
		||||
  estimateFee?: (...arg: any) => Promise<string | undefined>;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export const TxUI: FC<UIProps> = ({
 | 
			
		||||
@@ -85,10 +85,10 @@ export const TxUI: FC<UIProps> = ({
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  const handleEstimateFee = useCallback(
 | 
			
		||||
    async (state?: TransactionState) => {
 | 
			
		||||
    async (state?: TransactionState, silent?: boolean) => {
 | 
			
		||||
      setFeeLoading(true);
 | 
			
		||||
 | 
			
		||||
      const fee = await estimateFee?.(state);
 | 
			
		||||
      const fee = await estimateFee?.(state, { silent });
 | 
			
		||||
      if (fee) handleSetField("Fee", fee, state?.txFields);
 | 
			
		||||
 | 
			
		||||
      setFeeLoading(false);
 | 
			
		||||
@@ -101,7 +101,7 @@ export const TxUI: FC<UIProps> = ({
 | 
			
		||||
 | 
			
		||||
    const newState = resetOptions(tt.value);
 | 
			
		||||
 | 
			
		||||
    handleEstimateFee(newState);
 | 
			
		||||
    handleEstimateFee(newState, true);
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  const specialFields = ["TransactionType", "Account", "Destination"];
 | 
			
		||||
 
 | 
			
		||||
@@ -1,13 +1,15 @@
 | 
			
		||||
import toast from 'react-hot-toast';
 | 
			
		||||
import { derive, sign } from "xrpl-accountlib"
 | 
			
		||||
import state, { IAccount } from "../state"
 | 
			
		||||
 | 
			
		||||
const estimateFee = async (tx: Record<string, unknown>, account: IAccount, opts: { silent?: boolean } = {}): Promise<null | { base_fee: string, median_fee: string; minimum_fee: string; open_ledger_fee: string; }> => {
 | 
			
		||||
  const copyTx = JSON.parse(JSON.stringify(tx))
 | 
			
		||||
  delete copyTx['SigningPubKey']
 | 
			
		||||
  if (!copyTx.Fee) {
 | 
			
		||||
    copyTx.Fee = '1000'
 | 
			
		||||
  }
 | 
			
		||||
  try {
 | 
			
		||||
    const copyTx = JSON.parse(JSON.stringify(tx))
 | 
			
		||||
    delete copyTx['SigningPubKey']
 | 
			
		||||
    if (!copyTx.Fee) {
 | 
			
		||||
      copyTx.Fee = '1000'
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    const keypair = derive.familySeed(account.secret)
 | 
			
		||||
    const { signedTransaction } = sign(copyTx, keypair);
 | 
			
		||||
 | 
			
		||||
@@ -17,8 +19,10 @@ const estimateFee = async (tx: Record<string, unknown>, account: IAccount, opts:
 | 
			
		||||
    }
 | 
			
		||||
    return null
 | 
			
		||||
  } catch (err) {
 | 
			
		||||
    if (!opts.silent)
 | 
			
		||||
      console.log(err)
 | 
			
		||||
    if (!opts.silent) {
 | 
			
		||||
      console.error(err)
 | 
			
		||||
      toast.error("Cannot estimate fee.") // ? Some better msg
 | 
			
		||||
    }
 | 
			
		||||
    return null
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user