Merge pull request #3425 from ethcore/jg-tokenreg-decimals
Swap TokenReg dapp from base to decimals
This commit is contained in:
commit
d98c6fb717
@ -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,
|
||||
|
@ -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));
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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' />
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user