Don't require leading 0 in amount field (#1718)

Don't require leading 0 in amount field
This commit is contained in:
Seena Rowhani 2018-05-21 14:53:33 -04:00 committed by Daniel Ternyak
parent c2f79128bd
commit 7e605c4058
2 changed files with 21 additions and 3 deletions

View File

@ -32,8 +32,7 @@ export function* valueHandler(
const unit: string = yield select(getUnit);
const isEth = yield select(isEtherTransaction);
const validNum = isEth ? validNumber : validPositiveNumber;
if (!validNum(parseInt(payload, 10)) || !validDecimal(payload, decimal)) {
if (!validNum(Number(payload)) || !validDecimal(payload, decimal)) {
return yield put(setter({ raw: payload, value: null }));
}
const value = toTokenBase(payload, decimal);
@ -59,7 +58,7 @@ export function* reparseCurrentValue(value: IInput): SagaIterator {
const decimal = yield select(getDecimal);
const validNum = isEth ? validNumber : validPositiveNumber;
if (validNum(parseInt(value.raw, 10)) && validDecimal(value.raw, decimal)) {
if (validNum(Number(value.raw)) && validDecimal(value.raw, decimal)) {
return {
raw: value.raw,
value: toTokenBase(value.raw, decimal)

View File

@ -45,8 +45,10 @@ describe('valueHandler', () => {
setter
);
gen.invalidZeroToken = cloneableGenerator(valueHandler)(zeroAction, setTokenValue);
const value = toTokenBase(action.payload, decimal);
const zeroValue = toTokenBase(zeroAction.payload, decimal);
const unit = 'eth';
const isEth = true;
@ -76,6 +78,23 @@ describe('valueHandler', () => {
);
});
it('handles floats without lead zero', () => {
const leadZeroValue = {
decimal: 18,
action: {
payload: '.1'
}
};
const g = cloneableGenerator(valueHandler)(leadZeroValue.action as any, setter);
expect(g.next().value).toEqual(select(getDecimal));
expect(g.next(leadZeroValue.decimal).value).toEqual(select(getUnit));
expect(g.next(unit).value).toEqual(select(isEtherTransaction));
expect(g.next(isEth).value).not.toEqual(
put(setter({ raw: leadZeroValue.action.payload, value: null }))
);
});
it('should fail on invalid number or decimal and put null as value', () => {
expect(gen.invalidNumber.next(isEth).value).toEqual(
put(setter({ raw: failCases.invalidNumber.action.payload, value: null }))