Skip to content

Commit fcc5751

Browse files
authored
Merge pull request #2163 from MyCryptoHQ/fixit/small-chronologic-tweaks
Fixit/small chronologic tweaks
2 parents 488acb0 + 65c0219 commit fcc5751

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

common/containers/Tabs/ScheduleTransaction/components/Fields/TimeBounty/TimeBountyField.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class TimeBountyFieldClass extends Component<Props, State> {
9999
</div>
100100
</label>
101101
</div>
102-
<a href="#" onClick={this.toggleAdvanced} className="TimeBountyField-advanced-toggle">
102+
<a onClick={this.toggleAdvanced} className="TimeBountyField-advanced-toggle">
103103
{advanced ? `- ${translateRaw('TRANS_SIMPLE')}` : `+ ${translateRaw('TRANS_ADVANCED')}`}
104104
</a>
105105
</>

common/features/schedule/selectors.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import BN from 'bn.js';
22

33
import { Wei } from 'libs/units';
4-
import { gasPriceValidator, gasLimitValidator, timeBountyValidator } from 'libs/validators';
4+
import {
5+
gasPriceValidator,
6+
gasLimitValidator,
7+
timeBountyValidator,
8+
isValidNumberOrDecimal
9+
} from 'libs/validators';
510
import { EAC_SCHEDULING_CONFIG } from 'libs/scheduling';
611
import { AppState } from 'features/reducers';
712
import * as helpers from './helpers';
@@ -117,6 +122,8 @@ export const isValidCurrentWindowSize = (state: AppState) => {
117122

118123
return (
119124
currentWindowSize &&
125+
currentWindowSize.raw &&
126+
isValidNumberOrDecimal(currentWindowSize.raw) &&
120127
currentWindowSize.value &&
121128
currentWindowSize.value.gt(new BN(0)) &&
122129
currentWindowSize.value.bitLength() <= 256

common/libs/validators.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,33 @@ export const validDecimal = (input: string, decimal: number) => {
156156
return decimalLength <= decimal;
157157
};
158158

159+
/**
160+
* @desc
161+
* NOTE: Do not use this for anything related to Ether units.
162+
* This is strictly for ensuring a text entry only contains 0-9 and/or a decimal point.
163+
*/
164+
export const isValidNumberOrDecimal = (input: number | string): boolean => {
165+
const convertedInput = input.toString();
166+
const parsedInput = parseFloat(convertedInput);
167+
const digits = '.0123456789';
168+
169+
// Input contains no numbers.
170+
if (!parsedInput) {
171+
return false;
172+
}
173+
174+
// Input contains one number and other characters.
175+
if (convertedInput.split('').some(character => !digits.includes(character))) {
176+
return false;
177+
}
178+
179+
const isValid = convertedInput.includes('.')
180+
? validDecimal(convertedInput, Infinity)
181+
: validPositiveNumber(parsedInput);
182+
183+
return isValid;
184+
};
185+
159186
export function isPositiveIntegerOrZero(num: number): boolean {
160187
if (isNaN(num) || !isFinite(num)) {
161188
return false;

0 commit comments

Comments
 (0)