1 import React, { Component } from 'react'
2 import {reduxForm} from 'redux-form'
7 } from 'features/shared/components'
8 import { btmID } from 'utility/environment'
9 import { sum } from 'utility/math'
10 import { normalizeBTMAmountUnit, converIntToDec } from 'utility/buildInOutDisplay'
11 import styles from './ConfirmModal.scss'
12 import { Link } from 'react-router'
15 class ConfirmModal extends Component {
22 fields: { accountId, accountAlias, assetId, assetAlias, receivers, password, gasLevel },
33 const fee = Number(gasLevel.value * gas)
35 const totalAmount = sum(receivers, 'amount.value')
37 const Total = (assetAlias.value ==='BTM' ||assetId.value === btmID)?
38 (totalAmount + fee): totalAmount
40 let submitLabel = lang === 'zh' ? '提交交易' : 'Submit transaction'
42 const normalize = (value, asset) => {
43 if (asset === btmID || asset === 'BTM'){
44 return normalizeBTMAmountUnit(btmID, value, btmAmountUnit)
45 }else if( assetDecimal ){
46 return converIntToDec(value, assetDecimal)
52 const findAssetById = assetId.value && this.props.asset.find(i => i.id === assetId.value)
53 const findAssetByAlias = assetAlias.value && this.props.asset.find(i => i.alias === assetAlias.value)
55 const asset = assetAlias.value || ( findAssetById && findAssetById.alias ) || assetId.value
56 const assetIdLink = assetId.value || ( findAssetByAlias && findAssetByAlias.id )
58 const unit = <Link to={`/assets/${assetIdLink}`} className={styles.unit} target='_blank'>
59 {(asset !== btmID && asset !== 'BTM') && asset}
64 <h3>{lang ==='zh'?'确认交易':'Confirm Transaction'}</h3>
65 <table className={styles.table}>
68 <td className={styles.colLabel}>From</td>
69 <td> <span>{accountAlias.value || accountId.value}</span></td>
76 {receivers.map((receiver) =>
78 <td className={styles.colLabel}>To</td>
79 <td> <span>{receiver.address.value}</span> </td>
82 <td className={styles.colLabel}>{lang === 'zh'? '数量':'Amount'}</td>
83 <td> <code>{normalize(receiver.amount.value, asset)} {unit}</code> </td>
91 <td className={styles.colLabel}>{lang === 'zh'?'手续费':'Fee'}</td>
92 <td> <code>{normalizeBTMAmountUnit(btmID, fee, btmAmountUnit)}</code> </td>
96 <td className={styles.colLabel}>{lang === 'zh'? '交易总数' :'Total'}</td>
97 <td> <code>{normalize(Total, asset)} {unit}</code> </td>
102 <hr className={styles.hr}/>
104 <form onSubmit={handleSubmit}>
106 <label>{lang === 'zh' ? '密码' : 'Password'}</label>
108 placeholder={lang === 'zh' ? '请输入密码' : 'Please enter the password'}
109 fieldProps={password}
113 {error && error.message === 'PasswordWrong' &&
115 title='Error submitting form'
116 error='Your password is wrong, please check your password.' />}
118 <div className={styles.btnGroup}>
120 <button type='submit' className='btn btn-primary'
121 disabled={submitting}>
126 <SubmitIndicator className={styles.submitIndicator} />
129 <button type='button' className='btn btn-default' onClick={cancel}>
130 <i/> {lang ==='zh'? '返回' :'Cancel'}
140 const validate = values => {
142 if (!values.password) {
143 errors.password = 'Required'
148 export default reduxForm({
149 form: 'NormalTransactionForm',
155 'receivers[].amount',
156 'receivers[].address',
160 destroyOnUnmount: false,