mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-24 17:28:10 +00:00
Merge pull request #62 from satoshilabs/fix/address-validation
fixed address validation
This commit is contained in:
commit
34e2915593
@ -13,6 +13,7 @@ import { initialState } from 'reducers/SendFormReducer';
|
|||||||
import { findToken } from 'reducers/TokensReducer';
|
import { findToken } from 'reducers/TokensReducer';
|
||||||
import { findDevice, getPendingAmount, getPendingNonce } from 'reducers/utils';
|
import { findDevice, getPendingAmount, getPendingNonce } from 'reducers/utils';
|
||||||
import * as stateUtils from 'reducers/utils';
|
import * as stateUtils from 'reducers/utils';
|
||||||
|
import { validateAddress } from 'utils/ethUtils';
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
Dispatch,
|
Dispatch,
|
||||||
@ -345,34 +346,21 @@ export const validation = (props: Props): void => {
|
|||||||
if (state.untouched) return;
|
if (state.untouched) return;
|
||||||
// valid address
|
// valid address
|
||||||
if (state.touched.address) {
|
if (state.touched.address) {
|
||||||
/* if (state.address.length < 1) {
|
const addressError = validateAddress(state.address);
|
||||||
errors.address = 'Address is not set';
|
if (addressError) {
|
||||||
} else if (!EthereumjsUtil.isValidAddress(state.address)) {
|
errors.address = addressError;
|
||||||
errors.address = 'Address is not valid';
|
}
|
||||||
} else {
|
|
||||||
// address warning or info are set in addressValidation ThunkAction
|
// address warning or info may be set in addressValidation ThunkAction
|
||||||
// do not override this
|
// do not override them
|
||||||
if (state.warnings.address) {
|
if (state.warnings.address) {
|
||||||
warnings.address = state.warnings.address;
|
warnings.address = state.warnings.address;
|
||||||
} else if (state.infos.address) {
|
|
||||||
infos.address = state.infos.address;
|
|
||||||
}
|
}
|
||||||
} */
|
|
||||||
|
|
||||||
/* eslint (no-lonely-if) */
|
|
||||||
if (state.address.length < 1) {
|
|
||||||
errors.address = 'Address is not set';
|
|
||||||
} else if (!EthereumjsUtil.isValidAddress(state.address)) {
|
|
||||||
errors.address = 'Address is not valid';
|
|
||||||
} else if (state.warnings.address) {
|
|
||||||
// address warning or info are set in addressValidation ThunkAction
|
|
||||||
// do not override this
|
|
||||||
warnings.address = state.warnings.address;
|
|
||||||
if (state.infos.address) {
|
if (state.infos.address) {
|
||||||
infos.address = state.infos.address;
|
infos.address = state.infos.address;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// valid amount
|
// valid amount
|
||||||
// https://stackoverflow.com/a/42701461
|
// https://stackoverflow.com/a/42701461
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/* @flow */
|
/* @flow */
|
||||||
|
|
||||||
import BigNumber from 'bignumber.js';
|
import BigNumber from 'bignumber.js';
|
||||||
|
import EthereumjsUtil from 'ethereumjs-util';
|
||||||
|
|
||||||
export const decimalToHex = (dec: number): string => new BigNumber(dec).toString(16);
|
export const decimalToHex = (dec: number): string => new BigNumber(dec).toString(16);
|
||||||
|
|
||||||
@ -29,3 +30,15 @@ export const strip = (str: string): string => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const calcGasPrice = (price: BigNumber, limit: string): string => price.times(limit).toString();
|
export const calcGasPrice = (price: BigNumber, limit: string): string => price.times(limit).toString();
|
||||||
|
|
||||||
|
export const validateAddress = (address: string): ?string => {
|
||||||
|
const hasUpperCase = new RegExp('^(.*[A-Z].*)$');
|
||||||
|
if (address.length < 1) {
|
||||||
|
return 'Address is not set';
|
||||||
|
} else if (!EthereumjsUtil.isValidAddress(address)) {
|
||||||
|
return 'Address is not valid';
|
||||||
|
} else if (address.match(hasUpperCase) && !EthereumjsUtil.isValidChecksumAddress(address)) {
|
||||||
|
return 'Address is not a valid checksum';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user