From f2b8045c2173b6d4250dff804701ae38961a7b25 Mon Sep 17 00:00:00 2001
From: Daniel Ternyak <dternyak@gmail.com>
Date: Sun, 18 Jun 2017 19:56:11 -0500
Subject: [PATCH] address additional comments

---
 common/actions/swap.js                        |  7 +--
 common/api/bity.js                            | 22 +-------
 common/config/bity.js                         | 18 ++++++
 .../Tabs/Swap/components/wantToSwapMy.js      | 55 +++++++++++--------
 4 files changed, 54 insertions(+), 48 deletions(-)
 create mode 100644 common/config/bity.js

diff --git a/common/actions/swap.js b/common/actions/swap.js
index 1bdd4b83..c4825565 100644
--- a/common/actions/swap.js
+++ b/common/actions/swap.js
@@ -1,4 +1,3 @@
-// @flow
 export const SWAP_ORIGIN_KIND = 'SWAP_ORIGIN_KIND';
 export const SWAP_DESTINATION_KIND = 'SWAP_DESTINATION_KIND';
 export const SWAP_ORIGIN_AMOUNT = 'SWAP_ORIGIN_AMOUNT';
@@ -18,7 +17,7 @@ export const SWAP_DESTINATION_KIND_TO = (value) => {
         type: SWAP_DESTINATION_KIND,
         value
     }
-}
+};
 
 export const SWAP_ORIGIN_AMOUNT_TO = (value) => {
     return {
@@ -32,11 +31,11 @@ export const SWAP_DESTINATION_AMOUNT_TO = (value) => {
         type: SWAP_DESTINATION_AMOUNT,
         value
     }
-}
+};
 
 export const SWAP_UPDATE_BITY_RATES_TO = (value) => {
     return {
         type: SWAP_UPDATE_BITY_RATES,
         value
     }
-}
+};
diff --git a/common/api/bity.js b/common/api/bity.js
index 6b7f6b29..c9d1393c 100644
--- a/common/api/bity.js
+++ b/common/api/bity.js
@@ -1,4 +1,5 @@
 import axios from 'axios';
+import bityConfig from 'config/bity';
 
 // https://stackoverflow.com/questions/9828684/how-to-get-all-arguments-of-a-callback-function
 export function combineAndUpper() {
@@ -12,25 +13,6 @@ export function combineAndUpper() {
 }
 
 export default class Bity {
-    constructor() {
-        this.SERVERURL = 'https://myetherapi.com';
-        this.bityAPI = 'https://bity.com/api';
-        this.decimals = 6;
-        this.ethExplorer = 'https://etherscan.io/tx/[[txHash]]';
-        this.btcExplorer = 'https://blockchain.info/tx/[[txHash]]';
-        this.validStatus = ['RCVE', 'FILL', 'CONF', 'EXEC'];
-        this.invalidStatus = ['CANC'];
-        this.mainPairs = ['REP', 'ETH'];
-        this.min = 0.01;
-        this.max = 3;
-        this.priceLoaded = false;
-        this.postConfig = {
-            headers: {
-                'Content-Type': 'application/json; charset=UTF-8'
-            }
-        };
-    }
-
     findRateFromBityRateList(rateObjects, pairName) {
         return rateObjects.find(x => x.pair === pairName);
     }
@@ -76,7 +58,7 @@ export default class Bity {
 
     requestAllRates() {
         const path = '/v1/rate2/';
-        const bityURL = this.bityAPI + path;
+        const bityURL = bityConfig.bityAPI + path;
         return axios.get(bityURL)
     }
 }
diff --git a/common/config/bity.js b/common/config/bity.js
new file mode 100644
index 00000000..2c4b0632
--- /dev/null
+++ b/common/config/bity.js
@@ -0,0 +1,18 @@
+export default {
+    SERVERURL: 'https://myetherapi.com',
+    bityAPI: 'https://bity.com/api',
+    decimals: 6,
+    ethExplorer: 'https://etherscan.io/tx/[[txHash]]',
+    btcExplorer: 'https://blockchain.info/tx/[[txHash]]',
+    validStatus: ['RCVE', 'FILL', 'CONF', 'EXEC'],
+    invalidStatus: ['CANC'],
+    mainPairs: ['REP', 'ETH'],
+    min: 0.01,
+    max: 3,
+    priceLoaded: false,
+    postConfig: {
+        headers: {
+            'Content-Type': 'application/json; charse:UTF-8'
+        }
+    }
+}
diff --git a/common/containers/Tabs/Swap/components/wantToSwapMy.js b/common/containers/Tabs/Swap/components/wantToSwapMy.js
index 21158372..1a6481d1 100644
--- a/common/containers/Tabs/Swap/components/wantToSwapMy.js
+++ b/common/containers/Tabs/Swap/components/wantToSwapMy.js
@@ -7,6 +7,35 @@ function sleep(ms) {
     return new Promise(resolve => setTimeout(resolve, ms));
 }
 
+
+class CoinTypeDropDown extends Component {
+    constructor(props) {
+        super(props)
+    }
+
+    static propTypes = {
+        kind: PropTypes.any,
+        onChange: PropTypes.any,
+        kindOptions: PropTypes.any
+    };
+
+    render() {
+        return (<span className="dropdown">
+                      <select value={this.props.kind}
+                              className="btn btn-default"
+                              onChange={this.props.onChange.bind(this)}>
+                          {
+                              this.props.kindOptions.map((obj, i) => {
+                                  return <option value={obj} key={i}>{obj}</option>
+                              })
+                          }
+                        </select>
+                </span>)
+    }
+
+
+}
+
 export default class WantToSwapMy extends Component {
     constructor(props) {
         super(props)
@@ -91,25 +120,14 @@ export default class WantToSwapMy extends Component {
         return (
             <article className="swap-panel">
                 <h1>{translate('SWAP_init_1')}</h1>
-
                 <input
                     className={`form-control ${(this.props.originAmount !== '' && this.props.originAmount > 0) ? 'is-valid' : 'is-invalid'}`}
                     type="number"
                     placeholder="Amount"
                     onChange={(e) => this.onChangeOriginAmount(e.target.value)}
                     value={originAmount}/>
+                <CoinTypeDropDown type={originKind} onChange={this.onChangeOriginKind.bind(this)} kindOptions={originKindOptions}/>
 
-                <span className="dropdown">
-                  <select value={originKind}
-                          className="btn btn-default"
-                          onChange={this.onChangeOriginKind.bind(this)}>
-                      {
-                          originKindOptions.map((obj, i) => {
-                              return <option value={obj} key={i}>{obj}</option>
-                          })
-                      }
-                    </select>
-            </span>
                 <h1>{translate('SWAP_init_2')}</h1>
 
                 <input
@@ -118,18 +136,7 @@ export default class WantToSwapMy extends Component {
                     placeholder="Amount"
                     value={destinationAmount}
                     onChange={(e) => this.onChangeDestinationAmount(e.target.value)}/>
-
-                <span className="dropdown">
-                      <select value={destinationKind}
-                              className="btn btn-default"
-                              onChange={this.onChangeDestinationKind.bind(this)}>
-                          {
-                              destinationKindOptions.map((obj, i) => {
-                                  return <option value={obj} key={i}>{obj}</option>
-                              })
-                          }
-                        </select>
-                </span>
+                <CoinTypeDropDown type={destinationKind} onChange={this.onChangeDestinationKind.bind(this)} kindOptions={destinationKindOptions}/>
 
                 <div className="col-xs-12 clearfix text-center">
                     <a onClick={this.onClickStartSwap} className="btn btn-info btn-lg">