mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-24 09:18:09 +00:00
parent
33ba41e865
commit
5995568e19
@ -397,7 +397,7 @@ const estimateGasPrice = (): AsyncAction => async (dispatch: Dispatch, getState:
|
|||||||
}
|
}
|
||||||
|
|
||||||
const requestedData = state.data;
|
const requestedData = state.data;
|
||||||
const re = /^[0-9A-Fa-f]+$/g; // TODO: allow "0x" prefix
|
const re = /^(0x|0X)?[0-9A-Fa-f]+$/g;
|
||||||
if (!re.test(requestedData)) {
|
if (!re.test(requestedData)) {
|
||||||
// stop "calculatingGasLimit" process
|
// stop "calculatingGasLimit" process
|
||||||
dispatch(onGasLimitChange(requestedData.length > 0 ? state.gasLimit : network.defaultGasLimit.toString()));
|
dispatch(onGasLimitChange(requestedData.length > 0 ? state.gasLimit : network.defaultGasLimit.toString()));
|
||||||
|
@ -19,7 +19,7 @@ const NUMBER_RE: RegExp = new RegExp('^(0|0\\.([0-9]+)?|[1-9][0-9]*\\.?([0-9]+)?
|
|||||||
const UPPERCASE_RE = new RegExp('^(.*[A-Z].*)$');
|
const UPPERCASE_RE = new RegExp('^(.*[A-Z].*)$');
|
||||||
const ABS_RE = new RegExp('^[0-9]+$');
|
const ABS_RE = new RegExp('^[0-9]+$');
|
||||||
const ETH_18_RE = new RegExp('^(0|0\\.([0-9]{0,18})?|[1-9][0-9]*\\.?([0-9]{0,18})?|\\.[0-9]{0,18})$');
|
const ETH_18_RE = new RegExp('^(0|0\\.([0-9]{0,18})?|[1-9][0-9]*\\.?([0-9]{0,18})?|\\.[0-9]{0,18})$');
|
||||||
const HEX_RE = new RegExp('^[0-9A-Fa-f]+$');
|
const HEX_RE = new RegExp('^(0x|0X)?[0-9A-Fa-f]+$');
|
||||||
const dynamicRegexp = (decimals: number): RegExp => {
|
const dynamicRegexp = (decimals: number): RegExp => {
|
||||||
if (decimals > 0) {
|
if (decimals > 0) {
|
||||||
return new RegExp(`^(0|0\\.([0-9]{0,${decimals}})?|[1-9][0-9]*\\.?([0-9]{0,${decimals}})?|\\.[0-9]{1,${decimals}})$`);
|
return new RegExp(`^(0|0\\.([0-9]{0,${decimals}})?|[1-9][0-9]*\\.?([0-9]{0,${decimals}})?|\\.[0-9]{1,${decimals}})$`);
|
||||||
|
@ -5,6 +5,7 @@ import EthereumjsUnits from 'ethereumjs-units';
|
|||||||
import BigNumber from 'bignumber.js';
|
import BigNumber from 'bignumber.js';
|
||||||
import { toHex } from 'web3-utils'; // eslint-disable-line import/no-extraneous-dependencies
|
import { toHex } from 'web3-utils'; // eslint-disable-line import/no-extraneous-dependencies
|
||||||
import { initWeb3 } from 'actions/Web3Actions';
|
import { initWeb3 } from 'actions/Web3Actions';
|
||||||
|
import * as ethUtils from 'utils/ethUtils';
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
Dispatch,
|
Dispatch,
|
||||||
@ -29,10 +30,9 @@ type EthereumTxRequest = {
|
|||||||
export const prepareEthereumTx = (tx: EthereumTxRequest): PromiseAction<EthereumTransaction> => async (dispatch: Dispatch): Promise<EthereumTransaction> => {
|
export const prepareEthereumTx = (tx: EthereumTxRequest): PromiseAction<EthereumTransaction> => async (dispatch: Dispatch): Promise<EthereumTransaction> => {
|
||||||
const instance = await dispatch(initWeb3(tx.network));
|
const instance = await dispatch(initWeb3(tx.network));
|
||||||
const { token } = tx;
|
const { token } = tx;
|
||||||
let data: string = `0x${tx.data}`; // TODO: check if already prefixed
|
let data: string = ethUtils.sanitizeHex(tx.data); // TODO: check if already prefixed
|
||||||
let value: string = toHex(EthereumjsUnits.convert(tx.amount, 'ether', 'wei'));
|
let value: string = toHex(EthereumjsUnits.convert(tx.amount, 'ether', 'wei'));
|
||||||
let to: string = tx.to; // eslint-disable-line prefer-destructuring
|
let to: string = tx.to; // eslint-disable-line prefer-destructuring
|
||||||
|
|
||||||
if (token) {
|
if (token) {
|
||||||
// smart contract transaction
|
// smart contract transaction
|
||||||
const contract = instance.erc20.clone();
|
const contract = instance.erc20.clone();
|
||||||
|
@ -7,6 +7,7 @@ import EthereumjsUnits from 'ethereumjs-units';
|
|||||||
import type { EstimateGasOptions } from 'web3';
|
import type { EstimateGasOptions } from 'web3';
|
||||||
import * as WEB3 from 'actions/constants/web3';
|
import * as WEB3 from 'actions/constants/web3';
|
||||||
import * as PENDING from 'actions/constants/pendingTx';
|
import * as PENDING from 'actions/constants/pendingTx';
|
||||||
|
import * as ethUtils from 'utils/ethUtils';
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
Dispatch,
|
Dispatch,
|
||||||
@ -272,8 +273,7 @@ export const updateGasPrice = (network: string): PromiseAction<void> => async (d
|
|||||||
|
|
||||||
export const estimateGasLimit = (network: string, $options: EstimateGasOptions): PromiseAction<string> => async (dispatch: Dispatch): Promise<string> => {
|
export const estimateGasLimit = (network: string, $options: EstimateGasOptions): PromiseAction<string> => async (dispatch: Dispatch): Promise<string> => {
|
||||||
const instance = await dispatch(initWeb3(network));
|
const instance = await dispatch(initWeb3(network));
|
||||||
// TODO: allow data starting with 0x ...
|
const data = ethUtils.sanitizeHex($options.data);
|
||||||
const data = `0x${$options.data.length % 2 === 0 ? $options.data : `0${$options.data}`}`;
|
|
||||||
const options = {
|
const options = {
|
||||||
...$options,
|
...$options,
|
||||||
to: '0x0000000000000000000000000000000000000000',
|
to: '0x0000000000000000000000000000000000000000',
|
||||||
|
@ -7,15 +7,14 @@ export const decimalToHex = (dec: number): string => new BigNumber(dec).toString
|
|||||||
|
|
||||||
export const padLeftEven = (hex: string): string => (hex.length % 2 !== 0 ? `0${hex}` : hex);
|
export const padLeftEven = (hex: string): string => (hex.length % 2 !== 0 ? `0${hex}` : hex);
|
||||||
|
|
||||||
export const sanitizeHex = ($hex: number | string): ?string => {
|
export const sanitizeHex = ($hex: string): string => {
|
||||||
if (typeof $hex !== 'string') return null;
|
const hex = $hex.toLowerCase().substring(0, 2) === '0x' ? $hex.substring(2) : $hex;
|
||||||
const hex = $hex.substring(0, 2) === '0x' ? $hex.substring(2) : $hex;
|
|
||||||
if (hex === '') return '';
|
if (hex === '') return '';
|
||||||
return `0x${padLeftEven(hex)}`;
|
return `0x${padLeftEven(hex)}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const hexToDecimal = (hex: number): string => {
|
export const hexToDecimal = (hex: number): string => {
|
||||||
const sanitized: ?string = sanitizeHex(hex);
|
const sanitized: ?string = sanitizeHex(hex.toString());
|
||||||
return !sanitized ? 'null' : new BigNumber(sanitized).toString();
|
return !sanitized ? 'null' : new BigNumber(sanitized).toString();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user