Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Swap TokenReg dapp from base to decimals #3425

Merged
merged 1 commit into from
Nov 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions js/src/dapps/tokenreg/Actions/Register/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion js/src/dapps/tokenreg/Actions/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
18 changes: 18 additions & 0 deletions js/src/dapps/tokenreg/Inputs/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ 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';

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',
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions js/src/dapps/tokenreg/Tokens/Token/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' />
);
}

Expand Down