OSDN Git Service

Toggle the btm Amount unit box on Advanced Transaction page Accordingly.
authorZhiting Lin <zlin035@uottawa.ca>
Tue, 13 Mar 2018 06:37:59 +0000 (14:37 +0800)
committerZhiting Lin <zlin035@uottawa.ca>
Tue, 13 Mar 2018 06:37:59 +0000 (14:37 +0800)
src/features/shared/components/AmountUnitField/AmountUnitField.jsx
src/features/transactions/components/New/FormActionItem.jsx
src/features/transactions/components/New/New.jsx

index 8dfe118..c828db4 100644 (file)
@@ -1,7 +1,7 @@
 import React from 'react'
 import styles from './AmountUnitField.scss'
 import { DropdownButton, MenuItem } from 'react-bootstrap'
-import { converIntToDec, addZeroToDecimalPosition } from 'utility/buildInOutDisplay'
+import { converIntToDec, addZeroToDecimalPosition, formatBTMAmount, parseBTMAmount } from 'utility/buildInOutDisplay'
 import { FieldLabel } from 'features/shared/components'
 import pick from 'lodash/pick'
 
@@ -80,7 +80,7 @@ class AmountUnitField extends React.Component {
     if (this.props.fieldProps.onChange) {
       // Notify the normalized value
       this.props.fieldProps.onChange(
-        this.props.normalize(value, this.state.pos )
+        parseBTMAmount(value, this.state.pos )
       )
     }
   }
@@ -96,7 +96,7 @@ class AmountUnitField extends React.Component {
           {<input className='form-control'
             type={this.state.type}
             {...fieldProps}
-            value={this.props.format(this.state.value, this.state.pos)}
+            value={formatBTMAmount(this.state.value, this.state.pos)}
             onBlur={this.handleBlur}
             onChange={this.handleChange}
           />}
index 2f15e35..f174dcd 100644 (file)
@@ -1,5 +1,5 @@
 import React from 'react'
-import { ErrorBanner, HiddenField, Autocomplete, JsonField, TextField, ObjectSelectorField } from 'features/shared/components'
+import { ErrorBanner, HiddenField, Autocomplete, JsonField, TextField, ObjectSelectorField, AmountUnitField } from 'features/shared/components'
 import styles from './FormActionItem.scss'
 
 const ISSUE_KEY = 'issue'
@@ -73,6 +73,9 @@ export default class ActionItem extends React.Component {
       this.props.remove(this.props.index)
     }
 
+    const btmAmounUnitVisible = (assetAlias.value === 'btm' ||
+      assetId.value === 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff' )
+
     const classNames = [styles.main]
     if (type.error) classNames.push(styles.error)
 
@@ -115,9 +118,12 @@ export default class ActionItem extends React.Component {
             }}
           />}
 
-        {visible.amount &&
+        {visible.amount && !btmAmounUnitVisible &&
           <TextField title='Amount' fieldProps={amount} />}
 
+        {visible.amount && btmAmounUnitVisible &&
+          <AmountUnitField title='Amount' fieldProps={amount} />}
+
         {visible.password && false &&
           <TextField title='Password' placeholder='Password' fieldProps={password} autoFocus={false} type={'password'} />
         }
index 5529402..8bd3bc5 100644 (file)
@@ -5,7 +5,7 @@ import ActionItem from './FormActionItem'
 import React from 'react'
 import styles from './New.scss'
 import balanceActions from 'features/balances/actions'
-import { normalizeBTMAmountUnit, formatBTMAmount, parseBTMAmount } from 'utility/buildInOutDisplay'
+import { normalizeBTMAmountUnit } from 'utility/buildInOutDisplay'
 
 const rangeOptions = [
   {
@@ -219,13 +219,7 @@ class Form extends React.Component {
             <TextField title='Address' fieldProps={normalTransaction.address}/>
             {!showBtmAmountUnit && <TextField title='Amount' fieldProps={normalTransaction.amount}
             />}
-            {showBtmAmountUnit && <AmountUnitField
-              title='Amount'
-              fieldProps={{
-                ...normalTransaction.amount,
-              }}
-              format={formatBTMAmount}
-              normalize={parseBTMAmount}
+            {showBtmAmountUnit && <AmountUnitField title='Amount' fieldProps={normalTransaction.amount}
             />}
           </div>