Swap from base to decimals

This commit is contained in:
Jaco Greeff 2016-11-14 15:16:57 +01:00
parent d1848117ef
commit 48b2252029
4 changed files with 27 additions and 8 deletions

View File

@ -21,7 +21,7 @@ import { Dialog, FlatButton } from 'material-ui';
import AccountSelector from '../../Accounts/AccountSelector';
import InputText from '../../Inputs/Text';
import { TOKEN_ADDRESS_TYPE, TLA_TYPE, UINT_TYPE, STRING_TYPE } from '../../Inputs/validation';
import { TOKEN_ADDRESS_TYPE, TLA_TYPE, DECIMAL_TYPE, STRING_TYPE } from '../../Inputs/validation';
import styles from '../actions.css';
@ -41,11 +41,11 @@ const initState = {
floatingLabelText: 'Token TLA',
hintText: 'The token short name (3 characters)'
},
base: {
decimals: {
...defaultField,
type: UINT_TYPE,
floatingLabelText: 'Token Base',
hintText: 'The token precision'
type: DECIMAL_TYPE,
floatingLabelText: 'Token Decimals',
hintText: 'The number of decimals (0-18)'
},
name: {
...defaultField,

View File

@ -47,7 +47,8 @@ export const registerToken = (tokenData) => (dispatch, getState) => {
const contractInstance = state.status.contract.instance;
const fee = state.status.contract.fee;
const { address, base, name, tla } = tokenData;
const { address, decimals, name, tla } = tokenData;
const base = Math.pow(10, decimals);
dispatch(setRegisterSending(true));

View File

@ -32,6 +32,7 @@ export const SIMPLE_TOKEN_ADDRESS_TYPE = 'SIMPLE_TOKEN_ADDRESS_TYPE';
export const TLA_TYPE = 'TLA_TYPE';
export const SIMPLE_TLA_TYPE = 'SIMPLE_TLA_TYPE';
export const UINT_TYPE = 'UINT_TYPE';
export const DECIMAL_TYPE = 'DECIMAL_TYPE';
export const STRING_TYPE = 'STRING_TYPE';
export const HEX_TYPE = 'HEX_TYPE';
export const URL_TYPE = 'URL_TYPE';
@ -39,6 +40,7 @@ export const URL_TYPE = 'URL_TYPE';
export const ERRORS = {
invalidTLA: 'The TLA should be 3 characters long',
invalidUint: 'Please enter a non-negative integer',
invalidDecimal: 'Please enter a value between 0 and 18',
invalidString: 'Please enter at least a character',
invalidAccount: 'Please select an account to transact with',
invalidRecipient: 'Please select an account to send to',
@ -152,6 +154,21 @@ const validateUint = (uint) => {
};
};
const validateDecimal = (decimal) => {
if (!/^\d+$/.test(decimal) || parseInt(decimal) < 0 || parseInt(decimal) > 18) {
return {
error: ERRORS.invalidDecimal,
valid: false
};
}
return {
value: parseInt(decimal),
error: null,
valid: true
};
};
const validateString = (string) => {
if (string.toString().length === 0) {
return {
@ -204,6 +221,7 @@ export const validate = (value, type, contract) => {
if (type === TLA_TYPE) return validateTLA(value, contract);
if (type === SIMPLE_TLA_TYPE) return validateTLA(value, contract, true);
if (type === UINT_TYPE) return validateUint(value);
if (type === DECIMAL_TYPE) return validateDecimal(value);
if (type === STRING_TYPE) return validateString(value);
if (type === HEX_TYPE) return validateHex(value);
if (type === URL_TYPE) return validateURL(value);

View File

@ -152,8 +152,8 @@ export default class Token extends Component {
if (!base || base < 0) return null;
return (
<Chip
value={ base.toString() }
label='Base' />
value={ Math.log10(base).toString() }
label='Decimals' />
);
}