Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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,
};
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));
}
}