From 513b4c67b9f7ecd16cf25d49f94060d26cb2b4cd Mon Sep 17 00:00:00 2001 From: Daniel Ternyak Date: Mon, 3 Jul 2017 19:08:35 -0500 Subject: [PATCH] Bity: refactor and remove unnecessary class --- common/api/bity.js | 94 ++++++++++++++-------------- common/config/bity.js | 2 +- common/containers/Tabs/Swap/index.js | 11 ++-- 3 files changed, 53 insertions(+), 54 deletions(-) diff --git a/common/api/bity.js b/common/api/bity.js index cf3a7f9e..cbc92c27 100644 --- a/common/api/bity.js +++ b/common/api/bity.js @@ -12,51 +12,51 @@ export function combineAndUpper() { return newString; } -export default class Bity { - findRateFromBityRateList(rateObjects, pairName) { - return rateObjects.find(x => x.pair === pairName); - } - - _getRate(bityRates, origin, destination) { - const pairName = combineAndUpper(origin, destination); - const rateObjects = bityRates.data.objects; - return this.findRateFromBityRateList(rateObjects, pairName); - } - - /** - * Gives you multiple rates from Bitys API without making multiple API calls - * @param arrayOfOriginAndDestinationDicts - [{origin: 'BTC', destination: 'ETH'}, {origin: 'BTC', destination: 'REP}] - */ - getMultipleRates(arrayOfOriginAndDestinationDicts) { - const mappedRates = {}; - return this.requestAllRates().then(bityRates => { - arrayOfOriginAndDestinationDicts.forEach(each => { - const origin = each.origin; - const destination = each.destination; - const pairName = combineAndUpper(origin, destination); - const rate = this._getRate(bityRates, origin, destination); - mappedRates[pairName] = parseFloat(rate.rate_we_sell); - }); - return mappedRates; - }); - // TODO - catch errors - } - - getAllRates() { - const mappedRates = {}; - return this.requestAllRates().then(bityRates => { - bityRates.data.objects.forEach(each => { - const pairName = each.pair; - mappedRates[pairName] = parseFloat(each.rate_we_sell); - }); - return mappedRates; - }); - // TODO - catch errors - } - - requestAllRates() { - const path = '/v1/rate2/'; - const bityURL = bityConfig.bityAPI + path; - return axios.get(bityURL); - } +function findRateFromBityRateList(rateObjects, pairName) { + return rateObjects.find(x => x.pair === pairName); } + +function _getRate(bityRates, origin, destination) { + const pairName = combineAndUpper(origin, destination); + const rateObjects = bityRates.data.objects; + return findRateFromBityRateList(rateObjects, pairName); +} + +/** + * Gives you multiple rates from Bitys API without making multiple API calls + * @param arrayOfOriginAndDestinationDicts - [{origin: 'BTC', destination: 'ETH'}, {origin: 'BTC', destination: 'REP}] + */ +function getMultipleRates(arrayOfOriginAndDestinationDicts) { + const mappedRates = {}; + return _getAllRates().then(bityRates => { + arrayOfOriginAndDestinationDicts.forEach(each => { + const origin = each.origin; + const destination = each.destination; + const pairName = combineAndUpper(origin, destination); + const rate = _getRate(bityRates, origin, destination); + mappedRates[pairName] = parseFloat(rate.rate_we_sell); + }); + return mappedRates; + }); + // TODO - catch errors +} + +export function getAllRates() { + const mappedRates = {}; + return _getAllRates().then(bityRates => { + bityRates.data.objects.forEach(each => { + const pairName = each.pair; + mappedRates[pairName] = parseFloat(each.rate_we_sell); + }); + return mappedRates; + }); + // TODO - catch errors +} + +function _getAllRates() { + const path = '/v1/rate2/'; + const bityURL = bityConfig.bityAPI + path; + return axios.get(bityURL); +} + +function requestStatus() {} diff --git a/common/config/bity.js b/common/config/bity.js index b3350f3d..5bd49720 100644 --- a/common/config/bity.js +++ b/common/config/bity.js @@ -1,5 +1,5 @@ export default { - SERVERURL: 'https://myetherapi.com', + serverURL: 'https://bity.myetherapi.com', bityAPI: 'https://bity.com/api', decimals: 6, ethExplorer: 'https://etherscan.io/tx/[[txHash]]', diff --git a/common/containers/Tabs/Swap/index.js b/common/containers/Tabs/Swap/index.js index 76da12ec..192438db 100644 --- a/common/containers/Tabs/Swap/index.js +++ b/common/containers/Tabs/Swap/index.js @@ -7,14 +7,12 @@ import SwapProgress from './components/swapProgress'; import OnGoingSwapInformation from './components/onGoingSwapInformation'; import { connect } from 'react-redux'; import * as swapActions from 'actions/swap'; - import PropTypes from 'prop-types'; -import Bity from 'api/bity'; +import { getAllRates } from 'api/bity'; class Swap extends Component { constructor(props) { super(props); - this.bity = new Bity(); } static propTypes = { @@ -48,7 +46,7 @@ class Swap extends Component { !bityRates.BTCETH || !bityRates.BTCREP ) { - this.bity.getAllRates().then(data => { + getAllRates().then(data => { this.props.updateBityRatesSwap(data); }); } @@ -112,12 +110,13 @@ class Swap extends Component { // from bity referenceNumber: referenceNumber, timeRemaining: timeRemaining, - originAmount, originKind, destinationKind, destinationAmount, - restartSwap + restartSwap, + numberOfConfirmations: 3, + activeStep: 2 }; return (