/
NewAssetInfo.jsx
145 lines (129 loc) · 4.25 KB
/
NewAssetInfo.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import React from 'react'
import { FormContainer, FormSection, TextField, RadioField, SelectField } from 'features/shared/components'
import { reduxForm } from 'redux-form'
import {withNamespaces} from 'react-i18next'
import styles from './New.scss'
const rangeOptions = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16].map(val => ({label: val, value: val}))
class NewAssetInfo extends React.Component {
constructor(props) {
super(props)
this.addReceiverItem = this.addReceiverItem.bind(this)
this.removeReceiverItem = this.removeReceiverItem.bind(this)
}
addReceiverItem() {
this.props.fields.description.addField()
}
removeReceiverItem(index) {
const receiver = this.props.fields.description
receiver.removeField(index)
}
render() {
const {
fields: { alias, symbol,decimals,reissue, description},
error,
handleSubmit,
submitting,
t
} = this.props
const options = [
{label:t('form.reissueTrue') , value: 'true'},
{label:t('form.reissueFalse') , value: 'false'}
]
return(
<FormContainer
error={error}
label= { t('asset.new') }
onSubmit={handleSubmit}
submitting={submitting}
submitLabel={t('commonWords.next')}
>
<FormSection title={t('asset.information')}>
<TextField title={t('form.alias')} placeholder={t('asset.aliasLengthError')} fieldProps={alias} autoFocus={true} />
<TextField title={t('form.symbol')} placeholder={t('asset.symbolPlaceholder')} fieldProps={symbol} />
<SelectField options={rangeOptions}
title={t('form.decimals')}
hint={t('asset.decimalPlaceholder')}
skipEmpty={true}
fieldProps={decimals} />
<RadioField title={t('form.reissueTitle')} options={options} fieldProps={reissue} />
<label >{t('asset.additionInfo')}</label>
<div className={styles.panel}>
{description.map((descript, index) =>
<div className={styles.subjectField}>
<TextField title={t('asset.additionInfoKey')} fieldProps={descript.key}/>
<TextField title={t('asset.additionInfoValue')} fieldProps={descript.value}/>
<button
className='btn btn-danger btn-xs'
tabIndex='-1'
type='button'
onClick={() => this.removeReceiverItem(index)}
>
{t('commonWords.remove')}
</button>
</div>
)}
<button
type='button'
className='btn btn-default'
onClick={this.addReceiverItem}
>
{t('commonWords.addField')}
</button>
</div>
</FormSection>
</FormContainer>
)
}
}
const validate = (values, props) => {
const errors = { description:{} }
const t = props.t
if (!values.alias) {
errors.alias = t('asset.aliasError')
} else if (values.alias.length > 30){
errors.alias = t('asset.aliasLengthError')
}
if (!values.symbol) {
errors.symbol = t('asset.symbolError')
} else if (!values.symbol.isUpperCase()){
errors.symbol = t('asset.symbolCaseError')
}
if (!values.decimals) {
errors.decimals = t('asset.decimalsError')
} else if (!/^\d+$/.test(values.decimals)){
errors.decimals = t('asset.decimalsTypeError')
} else if( values.decimals> 16 || values.decimals<0){
errors.decimals = t('asset.decimalsRangeError')
}
values.description.forEach((descr, index) => {
if (!values.description[index].value) {
errors.description[index] = {...errors.description[index], value: t('asset.additionInfoValueError')}
}
if (!values.description[index].key) {
errors.description[index] = {...errors.description[index], key: t('asset.additionInfoKeyError')}
}
})
return errors
}
const fields = [
'alias',
'symbol',
'decimals',
'reissue',
'description[].key',
'description[].value',
'quorum'
]
export default withNamespaces('translations') (
reduxForm({
form: 'newAssetForm',
fields,
validate,
destroyOnUnmount: false,
initialValues: {
decimals: 8,
reissue: 'false',
quorum: 1,
}
})(NewAssetInfo)
)