Skip to content

Commit

Permalink
Merge pull request #2163 from MyCryptoHQ/fixit/small-chronologic-tweaks
Browse files Browse the repository at this point in the history
Fixit/small chronologic tweaks
  • Loading branch information
ConnorBryan authored Sep 14, 2018
2 parents 488acb0 + 65c0219 commit fcc5751
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class TimeBountyFieldClass extends Component<Props, State> {
</div>
</label>
</div>
<a href="#" onClick={this.toggleAdvanced} className="TimeBountyField-advanced-toggle">
<a onClick={this.toggleAdvanced} className="TimeBountyField-advanced-toggle">
{advanced ? `- ${translateRaw('TRANS_SIMPLE')}` : `+ ${translateRaw('TRANS_ADVANCED')}`}
</a>
</>
Expand Down
9 changes: 8 additions & 1 deletion common/features/schedule/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import BN from 'bn.js';

import { Wei } from 'libs/units';
import { gasPriceValidator, gasLimitValidator, timeBountyValidator } from 'libs/validators';
import {
gasPriceValidator,
gasLimitValidator,
timeBountyValidator,
isValidNumberOrDecimal
} from 'libs/validators';
import { EAC_SCHEDULING_CONFIG } from 'libs/scheduling';
import { AppState } from 'features/reducers';
import * as helpers from './helpers';
Expand Down Expand Up @@ -117,6 +122,8 @@ export const isValidCurrentWindowSize = (state: AppState) => {

return (
currentWindowSize &&
currentWindowSize.raw &&
isValidNumberOrDecimal(currentWindowSize.raw) &&
currentWindowSize.value &&
currentWindowSize.value.gt(new BN(0)) &&
currentWindowSize.value.bitLength() <= 256
Expand Down
27 changes: 27 additions & 0 deletions common/libs/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,33 @@ export const validDecimal = (input: string, decimal: number) => {
return decimalLength <= decimal;
};

/**
* @desc
* NOTE: Do not use this for anything related to Ether units.
* This is strictly for ensuring a text entry only contains 0-9 and/or a decimal point.
*/
export const isValidNumberOrDecimal = (input: number | string): boolean => {
const convertedInput = input.toString();
const parsedInput = parseFloat(convertedInput);
const digits = '.0123456789';

// Input contains no numbers.
if (!parsedInput) {
return false;
}

// Input contains one number and other characters.
if (convertedInput.split('').some(character => !digits.includes(character))) {
return false;
}

const isValid = convertedInput.includes('.')
? validDecimal(convertedInput, Infinity)
: validPositiveNumber(parsedInput);

return isValid;
};

export function isPositiveIntegerOrZero(num: number): boolean {
if (isNaN(num) || !isFinite(num)) {
return false;
Expand Down

0 comments on commit fcc5751

Please sign in to comment.