How to use the @zilliqa-js/util.units.fromQa function in @zilliqa-js/util

To help you get started, we’ve selected a few @zilliqa-js/util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Zilliqa / nucleus-wallet / src / components / account-info / index.tsx View on Github external
text={''}
                before={}
                onClick={run}
                disabled={isPending}
                className="mb-1 py-0 px-1"
              />
            
            {isPending ? (
              <div data-testid="container-loading">
                <small>Loading...</small>
              </div>
            ) : error ? (
              <div data-testid="container-error">{`Something went wrong: ${error.message}`}</div>
            ) : data ? (
              <div data-testid="container-data">
                <small>{`${units.fromQa(new BN(data as string), units.Units.Zil)} ZIL`}</small>
              </div>
            ) : (
              <div data-testid="container-no-data">No data</div>
            )}
          
        
      
    
  );
};
github Zilliqa / nucleus-wallet / src / components / send-form / index.tsx View on Github external
const [toAddress, setToAddress] = useState('');
  const [toAddressValid, setToAddressValid] = useState(false);
  const [toAddressInvalid, setToAddressInvalid] = useState(false);
  const [amount, setAmount] = useState('');

  const minGasProps = useAsyncFn({ promiseFn: getMinGasPrice });
  const minGasPriceInQa = minGasProps.data as string;
  const isUpdatingMinGasPrice = minGasProps.isPending;

  const minGasPriceInZil: string = units.fromQa(new BN(minGasPriceInQa), units.Units.Zil);

  const balanceProps = useAsyncFn({ promiseFn: getBalance });
  const balanceInQa = balanceProps.data as string;
  const isUpdatingBalance = balanceProps.isPending;

  const balanceInZil: string = units.fromQa(new BN(balanceInQa), units.Units.Zil);

  const mutationProps = useAsyncFn({
    deferFn: send
  });

  const confirm = () =&gt; {
    setIsDraft(true);
    setHasRun(false);
    setToAddress('');
    setToAddressValid(false);
    setToAddressInvalid(false);
    setAmount('');
  };

  const changeToAddress = (e: React.ChangeEvent): void =&gt; {
    e.preventDefault();
github zilpay / zil-pay / src / views / Popup.vue View on Github external
mounted() {
    this.upadteAllState();
    this.gasPrice = units.fromQa(
      new BN(this.CONFIRM_TX.gasPrice),
      units.Units.Li
    ).toString();
    this.gasLimit = this.CONFIRM_TX.gasLimit;
  }
}
github zilpay / zil-pay / src / filters / zil.js View on Github external
export function fromZil(value, isRound=false) {
  const amount = units.fromQa(new BN(value), units.Units.Zil);
  if (isRound) {
    return Math.round(+amount * 1000) / 1000;
  } else {
    return amount;
  }
}
github Zilliqa / nucleus-wallet / src / components / send-form / index.tsx View on Github external
const SendForm = ({ send, getBalance, getMinGasPrice }) => {
  const [hasRun, setHasRun] = useState(false);
  const [isDraft, setIsDraft] = useState(true);
  const [toAddress, setToAddress] = useState('');
  const [toAddressValid, setToAddressValid] = useState(false);
  const [toAddressInvalid, setToAddressInvalid] = useState(false);
  const [amount, setAmount] = useState('');

  const minGasProps = useAsyncFn({ promiseFn: getMinGasPrice });
  const minGasPriceInQa = minGasProps.data as string;
  const isUpdatingMinGasPrice = minGasProps.isPending;

  const minGasPriceInZil: string = units.fromQa(new BN(minGasPriceInQa), units.Units.Zil);

  const balanceProps = useAsyncFn({ promiseFn: getBalance });
  const balanceInQa = balanceProps.data as string;
  const isUpdatingBalance = balanceProps.isPending;

  const balanceInZil: string = units.fromQa(new BN(balanceInQa), units.Units.Zil);

  const mutationProps = useAsyncFn({
    deferFn: send
  });

  const confirm = () => {
    setIsDraft(true);
    setHasRun(false);
    setToAddress('');
    setToAddressValid(false);
github Zilliqa / nucleus-wallet / src / utils.ts View on Github external
export const formatSendAmountInZil = (
  amountInZil: string,
  balanceInZil: string,
  minGasPriceInZil: string
): string => {
  const amountInQaBN: BN = units.toQa(amountInZil, units.Units.Zil);
  const balanceInQaBN: BN = units.toQa(balanceInZil, units.Units.Zil);
  const minGasPriceInQaBN: BN = units.toQa(minGasPriceInZil, units.Units.Zil);

  const maxAmountInQaBN = balanceInQaBN.sub(minGasPriceInQaBN);

  if (amountInQaBN.lte(minGasPriceInQaBN)) {
    return units.fromQa(minGasPriceInQaBN, units.Units.Zil).toString();
  } else if (amountInQaBN.gt(maxAmountInQaBN)) {
    return units.fromQa(maxAmountInQaBN, units.Units.Zil).toString();
  } else {
    return units.fromQa(amountInQaBN, units.Units.Zil).toString();
  }
};
github Zilliqa / nucleus-wallet / src / utils.ts View on Github external
export const formatSendAmountInZil = (
  amountInZil: string,
  balanceInZil: string,
  minGasPriceInZil: string
): string => {
  const amountInQaBN: BN = units.toQa(amountInZil, units.Units.Zil);
  const balanceInQaBN: BN = units.toQa(balanceInZil, units.Units.Zil);
  const minGasPriceInQaBN: BN = units.toQa(minGasPriceInZil, units.Units.Zil);

  const maxAmountInQaBN = balanceInQaBN.sub(minGasPriceInQaBN);

  if (amountInQaBN.lte(minGasPriceInQaBN)) {
    return units.fromQa(minGasPriceInQaBN, units.Units.Zil).toString();
  } else if (amountInQaBN.gt(maxAmountInQaBN)) {
    return units.fromQa(maxAmountInQaBN, units.Units.Zil).toString();
  } else {
    return units.fromQa(amountInQaBN, units.Units.Zil).toString();
  }
};
github Zilliqa / nucleus-wallet / src / utils.ts View on Github external
amountInZil: string,
  balanceInZil: string,
  minGasPriceInZil: string
): string => {
  const amountInQaBN: BN = units.toQa(amountInZil, units.Units.Zil);
  const balanceInQaBN: BN = units.toQa(balanceInZil, units.Units.Zil);
  const minGasPriceInQaBN: BN = units.toQa(minGasPriceInZil, units.Units.Zil);

  const maxAmountInQaBN = balanceInQaBN.sub(minGasPriceInQaBN);

  if (amountInQaBN.lte(minGasPriceInQaBN)) {
    return units.fromQa(minGasPriceInQaBN, units.Units.Zil).toString();
  } else if (amountInQaBN.gt(maxAmountInQaBN)) {
    return units.fromQa(maxAmountInQaBN, units.Units.Zil).toString();
  } else {
    return units.fromQa(amountInQaBN, units.Units.Zil).toString();
  }
};