Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "number-precision in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'number-precision' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

disableEventActionsIfNecessary = () => {
    if (!this.event) return;
    const { status, centralizedOracle, isOpenResultSetting, consensusThreshold } = this.event;
    const { wallet } = this.app;
    const currentWalletNbot = wallet.currentWalletAddress ? wallet.currentWalletAddress.nbot : -1; // when no wallet, still can click on action buttons

    this.buttonDisabled = false;
    this.warningType = '';
    this.eventWarningMessageId = '';
    this.error = INIT.error;

    // Trying to vote over the consensus threshold - currently not way to trigger
    const amountNum = Number(this.amount);
    if (status === ARBITRATION && this.amount && this.selectedOptionIdx >= 0) {
      const maxVote = NP.minus(consensusThreshold, this.selectedOption.amount);
      if (amountNum > maxVote) {
        this.buttonDisabled = true;
        this.error.amount = 'oracle.maxVoteText';
        return;
      }
    }

    // Has not reached betting start time
    if (status === PRE_BETTING) {
      this.buttonDisabled = true;
      this.warningType = EventWarningType.INFO;
      this.eventWarningMessageId = 'oracle.betStartTimeDisabledText';
      return;
    }

    // Has not reached result setting start time
if (!this.event) return;
    const { status, centralizedOracle, resultSetStartTime, isOpenResultSetting, consensusThreshold } = this.event;
    const { global: { syncBlockTime }, wallet } = this.app;
    const currBlockTime = moment.unix(syncBlockTime);
    const currentWalletNbot = wallet.currentWalletAddress ? wallet.currentWalletAddress.nbot : 0;
    const notEnoughNbot = currentWalletNbot < maxTransactionFee;

    this.buttonDisabled = false;
    this.warningType = '';
    this.eventWarningMessageId = '';
    this.error = INIT.error;

    // Trying to vote over the consensus threshold - currently not way to trigger
    const amountNum = Number(this.amount);
    if (status === ARBITRATION && this.amount && this.selectedOptionIdx >= 0) {
      const maxVote = NP.minus(consensusThreshold, this.selectedOption.amount);
      if (amountNum > maxVote) {
        this.buttonDisabled = true;
        this.error.amount = 'oracle.maxVoteText';
        return;
      }
    }

    // Has not reached betting start time
    if (status === BETTING
      && currBlockTime.isBefore(moment.unix(this.event.betStartTime))) {
      this.buttonDisabled = true;
      this.warningType = EventWarningType.INFO;
      this.eventWarningMessageId = 'oracle.betStartTimeDisabledText';
      return;
    }
handleAmountBlur = ({ target: { value } }) => {
    let { phase, amount, consensusThreshold, onAmountChange } = this.props; // eslint-disable-line
    if (phase === Phases.VOTING) {
      [amount, consensusThreshold] = [parseFloat(amount, 10), parseFloat(consensusThreshold, 10)];
      if (amount + Number(value) > consensusThreshold) {
        const val = toFixed(NP.minus(consensusThreshold, amount));
        onAmountChange(val);
      }
    }
  }
}

    // Did not enter an amount
    if ((isBettingPhase || isVotingPhase) && (voteAmount <= 0 || Number.isNaN(voteAmount))) {
      return {
        disabled: true,
        id: 'oracle.enterAmountDisabledText',
        message: 'Please entered a valid amount.',
        warningType: EventWarningType.INFO,
      };
    }

    // Trying to vote over the consensus threshold
    const optionAmount = oracle.amounts[currentOptionIdx];
    const maxVote = token === Token.BOT && status === OracleStatus.VOTING
      ? NP.minus(oracle.consensusThreshold, optionAmount) : 0;
    if (token === Token.BOT
      && status === OracleStatus.VOTING
      && currentOptionIdx >= 0
      && voteAmount > maxVote) {
      return {
        disabled: true,
        id: 'oracle.maxVoteText',
        message: 'You can only vote up to the Consensus Threshold for any one outcome. Current max vote is {amount} BOT.',
        values: { amount: toFixed(maxVote) },
        warningTypeClass: EventWarningType.ERROR,
      };
    }

    return {
      disabled: false,
    };
let bn;
  if (isNaN(Number(number))) {
    bn = toBN(number, 16);
  } else {
    const toStringNumber = String(number);
    const splitArr = toStringNumber.split('.');
    const integerPart = splitArr[0];
    bn = toBN(integerPart);
  }

  const conversionBN = toBN(SATOSHI_CONVERSION);
  const integerPart = bn.div(conversionBN).toNumber();
  const decimalPartBN = bn.sub(conversionBN.mul(toBN(integerPart)));
  const decimalPart = NP.divide(decimalPartBN.toNumber(), SATOSHI_CONVERSION);
  return NP.plus(integerPart, decimalPart);
}
}

  let bn;
  if (isNaN(Number(number))) {
    bn = toBN(number, 16);
  } else {
    const toStringNumber = String(number);
    const splitArr = toStringNumber.split('.');
    const integerPart = splitArr[0];
    bn = toBN(integerPart);
  }

  const conversionBN = toBN(SATOSHI_CONVERSION);
  const integerPart = bn.div(conversionBN).toNumber();
  const decimalPartBN = bn.sub(conversionBN.mul(toBN(integerPart)));
  const decimalPart = NP.divide(decimalPartBN.toNumber(), SATOSHI_CONVERSION);
  return NP.plus(integerPart, decimalPart);
}
export function decimalToSatoshi(number) {
  if (!number) {
    return number;
  }
  const toStringNumber = Number(number).toFixed(8);
  const splitArr = toStringNumber.split('.');
  const integerPart = splitArr[0];
  const decimalPart = splitArr.length > 1 ? NP.times(Number(`.${splitArr[1]}`), SATOSHI_CONVERSION) : 0;
  const conversionBN = toBN(SATOSHI_CONVERSION);
  return toBN(integerPart).mul(conversionBN).add(toBN(decimalPart)).toString(10);
}
fixAmount = () => {
    if (this.event.status !== ARBITRATION) return;

    const inputAmount = parseFloat(this.amount, 10);
    const consensusThreshold = parseFloat(this.event.consensusThreshold, 10);
    if (inputAmount + Number(this.selectedOption.amount) > consensusThreshold) {
      this.amount = String(toFixed(NP.minus(
        consensusThreshold,
        Number(this.selectedOption.amount)
      )));
    }
  }
@computed get remainingConsensusThreshold() {
    const consensusThreshold = parseFloat(this.event.consensusThreshold, 10);
    return toFixed(NP.minus(
      consensusThreshold,
      Number(this.selectedOption.amount)
    ), true);
  }
fixAmount = () => {
    if (this.event.status !== ARBITRATION) return;

    const inputAmount = parseFloat(this.amount, 10);
    const consensusThreshold = parseFloat(this.event.consensusThreshold, 10);
    if (inputAmount + Number(this.selectedOption.amount) > consensusThreshold) {
      this.amount = String(NP.minus(
        consensusThreshold,
        Number(this.selectedOption.amount)
      ).toFixed(8));
    }
  }

Is your System Free of Underlying Vulnerabilities?
Find Out Now