mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-27 10:48:22 +00:00
add gas price and nonce l10n
This commit is contained in:
parent
5000ea65e4
commit
baee0855c5
@ -357,21 +357,33 @@ export const gasLimitValidation = ($state: State): PayloadAction<State> => (
|
||||
/*
|
||||
* Gas price value validation
|
||||
*/
|
||||
export const gasPriceValidation = ($state: State): PayloadAction<State> => (): State => {
|
||||
export const gasPriceValidation = ($state: State): PayloadAction<State> => (
|
||||
dispatch: Dispatch,
|
||||
getState: GetState
|
||||
): State => {
|
||||
const state = { ...$state };
|
||||
if (!state.touched.gasPrice) return state;
|
||||
|
||||
// get react-intl imperative api
|
||||
const { language, messages } = getState().wallet;
|
||||
const intlProvider = new IntlProvider({ language, messages });
|
||||
const { intl } = intlProvider.getChildContext();
|
||||
|
||||
const { gasPrice } = state;
|
||||
if (gasPrice.length < 1) {
|
||||
state.errors.gasPrice = 'Gas price is not set';
|
||||
// state.errors.gasPrice = 'Gas price is not set';
|
||||
state.errors.gasPrice = intl.formatMessage(l10nMessages.TR_GAS_PRICE_IS_NOT_SET);
|
||||
} else if (gasPrice.length > 0 && !validators.isNumber(gasPrice)) {
|
||||
state.errors.gasPrice = 'Gas price is not a number';
|
||||
// state.errors.gasPrice = 'Gas price is not a number';
|
||||
state.errors.gasPrice = intl.formatMessage(l10nMessages.TR_GAS_PRICE_IS_NOT_A_NUMBER);
|
||||
} else {
|
||||
const gp: BigNumber = new BigNumber(gasPrice);
|
||||
if (gp.isGreaterThan(1000)) {
|
||||
state.warnings.gasPrice = 'Gas price is too high';
|
||||
// state.warnings.gasPrice = 'Gas price is too high';
|
||||
state.warnings.gasPrice = intl.formatMessage(l10nMessages.TR_GAS_PRICE_IS_TOO_HIGH);
|
||||
} else if (gp.isLessThanOrEqualTo('0')) {
|
||||
state.errors.gasPrice = 'Gas price is too low';
|
||||
// state.errors.gasPrice = 'Gas price is too low';
|
||||
state.errors.gasPrice = intl.formatMessage(l10nMessages.TR_GAS_PRICE_IS_TOO_LOW);
|
||||
}
|
||||
}
|
||||
return state;
|
||||
@ -387,33 +399,56 @@ export const nonceValidation = ($state: State): PayloadAction<State> => (
|
||||
const state = { ...$state };
|
||||
if (!state.touched.nonce) return state;
|
||||
|
||||
// get react-intl imperative api
|
||||
const { language, messages } = getState().wallet;
|
||||
const intlProvider = new IntlProvider({ language, messages });
|
||||
const { intl } = intlProvider.getChildContext();
|
||||
|
||||
const { account } = getState().selectedAccount;
|
||||
if (!account || account.networkType !== 'ethereum') return state;
|
||||
|
||||
const { nonce } = state;
|
||||
if (nonce.length < 1) {
|
||||
state.errors.nonce = 'Nonce is not set';
|
||||
// state.errors.nonce = 'Nonce is not set';
|
||||
state.errors.nonce = intl.formatMessage(l10nMessages.TR_NONCE_IS_NOT_SET);
|
||||
} else if (!validators.isAbs(nonce)) {
|
||||
state.errors.nonce = 'Nonce is not a valid number';
|
||||
// state.errors.nonce = 'Nonce is not a valid number';
|
||||
state.errors.nonce = intl.formatMessage(l10nMessages.TR_NONCE_IS_NOT_A_NUMBER);
|
||||
} else {
|
||||
const n: BigNumber = new BigNumber(nonce);
|
||||
if (n.isLessThan(account.nonce)) {
|
||||
state.warnings.nonce = 'Nonce is lower than recommended';
|
||||
// state.warnings.nonce = 'Nonce is lower than recommended';
|
||||
state.warnings.nonce = intl.formatMessage(
|
||||
l10nMessages.TR_NONCE_IS_LOWER_THAN_RECOMMENDED
|
||||
);
|
||||
} else if (n.isGreaterThan(account.nonce)) {
|
||||
state.warnings.nonce = 'Nonce is greater than recommended';
|
||||
// state.warnings.nonce = 'Nonce is greater than recommended';
|
||||
state.warnings.nonce = intl.formatMessage(
|
||||
l10nMessages.TR_NONCE_IS_GREATER_THAN_RECOMMENDED
|
||||
);
|
||||
}
|
||||
}
|
||||
return state;
|
||||
};
|
||||
|
||||
/*
|
||||
* Gas price value validation
|
||||
* Data validation
|
||||
*/
|
||||
export const dataValidation = ($state: State): PayloadAction<State> => (): State => {
|
||||
export const dataValidation = ($state: State): PayloadAction<State> => (
|
||||
dispatch: Dispatch,
|
||||
getState: GetState
|
||||
): State => {
|
||||
const state = { ...$state };
|
||||
if (!state.touched.data || state.data.length === 0) return state;
|
||||
|
||||
// get react-intl imperative api
|
||||
const { language, messages } = getState().wallet;
|
||||
const intlProvider = new IntlProvider({ language, messages });
|
||||
const { intl } = intlProvider.getChildContext();
|
||||
|
||||
if (!ethUtils.isHex(state.data)) {
|
||||
state.errors.data = 'Data is not valid hexadecimal';
|
||||
// state.errors.data = 'Data is not valid hexadecimal';
|
||||
state.errors.data = intl.formatMessage(l10nMessages.TR_DATA_IS_NOT_VALID_HEX);
|
||||
}
|
||||
return state;
|
||||
};
|
||||
|
@ -55,6 +55,42 @@ const definedMessages: Messages = defineMessages({
|
||||
id: 'TR_GAS_LIMIT_IS_BELOW_RECOMMENDED',
|
||||
defaultMessage: 'Gas limit is below recommended',
|
||||
},
|
||||
TR_GAS_PRICE_IS_NOT_A_NUMBER: {
|
||||
id: 'TR_GAS_PRICE_IS_NOT_A_NUMBER',
|
||||
defaultMessage: 'Gas price is not a number',
|
||||
},
|
||||
TR_GAS_PRICE_IS_NOT_SET: {
|
||||
id: 'TR_GAS_PRICE_IS_NOT_SET',
|
||||
defaultMessage: 'Gas price is not set',
|
||||
},
|
||||
TR_GAS_PRICE_IS_TOO_LOW: {
|
||||
id: 'TR_GAS_PRICE_IS_TOO_LOW',
|
||||
defaultMessage: 'Gas price is too low',
|
||||
},
|
||||
TR_GAS_PRICE_IS_TOO_HIGH: {
|
||||
id: 'TR_GAS_PRICE_IS_TOO_HIGH',
|
||||
defaultMessage: 'Gas price is too high',
|
||||
},
|
||||
TR_NONCE_IS_NOT_A_NUMBER: {
|
||||
id: 'TR_NONCE_IS_NOT_A_NUMBER',
|
||||
defaultMessage: 'Nonce is not a valid number',
|
||||
},
|
||||
TR_NONCE_IS_NOT_SET: {
|
||||
id: 'TR_NONCE_IS_NOT_SET',
|
||||
defaultMessage: 'Nonce is not set',
|
||||
},
|
||||
TR_NONCE_IS_GREATER_THAN_RECOMMENDED: {
|
||||
id: 'TR_NONCE_IS_GREATER_THAN_RECOMMENDED',
|
||||
defaultMessage: 'Nonce is greater than recommended',
|
||||
},
|
||||
TR_NONCE_IS_LOWER_THAN_RECOMMENDED: {
|
||||
id: 'TR_NONCE_IS_LOWER_THAN_RECOMMENDED',
|
||||
defaultMessage: 'Nonce is lower than recommended',
|
||||
},
|
||||
TR_DATA_IS_NOT_VALID_HEX: {
|
||||
id: 'TR_DATA_IS_NOT_VALID_HEX',
|
||||
defaultMessage: 'Data is not valid hexadecimal',
|
||||
},
|
||||
});
|
||||
|
||||
export default definedMessages;
|
||||
|
Loading…
Reference in New Issue
Block a user