1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-27 18:58:08 +00:00

eslint ./src/utils

This commit is contained in:
Szymon Lesisz 2018-09-23 08:28:12 +02:00
parent f435b8669c
commit 1ea6d0be4c
3 changed files with 13 additions and 20 deletions

View File

@ -12,6 +12,7 @@
"jest": true
},
"rules": {
"import/prefer-default-export": 0,
"no-use-before-define": 0,
"no-plusplus": 0,
"class-methods-use-this": 0,

View File

@ -5,14 +5,11 @@ import EthereumjsUtil from 'ethereumjs-util';
export const decimalToHex = (dec: number): string => new BigNumber(dec).toString(16);
export const padLeftEven = (hex: string): string => {
hex = hex.length % 2 != 0 ? `0${hex}` : hex;
return hex;
};
export const padLeftEven = (hex: string): string => (hex.length % 2 !== 0 ? `0${hex}` : hex);
export const sanitizeHex = (hex: number | string): ?string => {
if (typeof hex !== 'string') return null;
hex = hex.substring(0, 2) === '0x' ? hex.substring(2) : hex;
export const sanitizeHex = ($hex: number | string): ?string => {
if (typeof $hex !== 'string') return null;
const hex = $hex.substring(0, 2) === '0x' ? $hex.substring(2) : $hex;
if (hex === '') return '';
return `0x${padLeftEven(hex)}`;
};
@ -35,10 +32,12 @@ 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)) {
}
if (!EthereumjsUtil.isValidAddress(address)) {
return 'Address is not valid';
} else if (address.match(hasUpperCase) && !EthereumjsUtil.isValidChecksumAddress(address)) {
}
if (address.match(hasUpperCase) && !EthereumjsUtil.isValidChecksumAddress(address)) {
return 'Address is not a valid checksum';
}
return null;
}
};

View File

@ -1,12 +1,5 @@
/* @flow */
// import root from 'window-or-global';
// import Promise from 'es6-promise';
export async function resolveAfter(msec: number, value?: any): Promise<any> {
await new Promise((resolve) => {
//root.setTimeout(resolve, msec, value);
window.setTimeout(resolve, msec, value);
});
}
export const resolveAfter = (msec: number, value?: any): Promise<any> => new Promise((resolve) => {
window.setTimeout(resolve, msec, value);
});