Bity: refactor and remove unnecessary class

This commit is contained in:
Daniel Ternyak 2017-07-03 19:08:35 -05:00
parent 62150fb63b
commit 513b4c67b9
3 changed files with 53 additions and 54 deletions

View File

@ -12,29 +12,28 @@ export function combineAndUpper() {
return newString; return newString;
} }
export default class Bity { function findRateFromBityRateList(rateObjects, pairName) {
findRateFromBityRateList(rateObjects, pairName) {
return rateObjects.find(x => x.pair === pairName); return rateObjects.find(x => x.pair === pairName);
} }
_getRate(bityRates, origin, destination) { function _getRate(bityRates, origin, destination) {
const pairName = combineAndUpper(origin, destination); const pairName = combineAndUpper(origin, destination);
const rateObjects = bityRates.data.objects; const rateObjects = bityRates.data.objects;
return this.findRateFromBityRateList(rateObjects, pairName); return findRateFromBityRateList(rateObjects, pairName);
} }
/** /**
* Gives you multiple rates from Bitys API without making multiple API calls * Gives you multiple rates from Bitys API without making multiple API calls
* @param arrayOfOriginAndDestinationDicts - [{origin: 'BTC', destination: 'ETH'}, {origin: 'BTC', destination: 'REP}] * @param arrayOfOriginAndDestinationDicts - [{origin: 'BTC', destination: 'ETH'}, {origin: 'BTC', destination: 'REP}]
*/ */
getMultipleRates(arrayOfOriginAndDestinationDicts) { function getMultipleRates(arrayOfOriginAndDestinationDicts) {
const mappedRates = {}; const mappedRates = {};
return this.requestAllRates().then(bityRates => { return _getAllRates().then(bityRates => {
arrayOfOriginAndDestinationDicts.forEach(each => { arrayOfOriginAndDestinationDicts.forEach(each => {
const origin = each.origin; const origin = each.origin;
const destination = each.destination; const destination = each.destination;
const pairName = combineAndUpper(origin, destination); const pairName = combineAndUpper(origin, destination);
const rate = this._getRate(bityRates, origin, destination); const rate = _getRate(bityRates, origin, destination);
mappedRates[pairName] = parseFloat(rate.rate_we_sell); mappedRates[pairName] = parseFloat(rate.rate_we_sell);
}); });
return mappedRates; return mappedRates;
@ -42,9 +41,9 @@ export default class Bity {
// TODO - catch errors // TODO - catch errors
} }
getAllRates() { export function getAllRates() {
const mappedRates = {}; const mappedRates = {};
return this.requestAllRates().then(bityRates => { return _getAllRates().then(bityRates => {
bityRates.data.objects.forEach(each => { bityRates.data.objects.forEach(each => {
const pairName = each.pair; const pairName = each.pair;
mappedRates[pairName] = parseFloat(each.rate_we_sell); mappedRates[pairName] = parseFloat(each.rate_we_sell);
@ -54,9 +53,10 @@ export default class Bity {
// TODO - catch errors // TODO - catch errors
} }
requestAllRates() { function _getAllRates() {
const path = '/v1/rate2/'; const path = '/v1/rate2/';
const bityURL = bityConfig.bityAPI + path; const bityURL = bityConfig.bityAPI + path;
return axios.get(bityURL); return axios.get(bityURL);
} }
}
function requestStatus() {}

View File

@ -1,5 +1,5 @@
export default { export default {
SERVERURL: 'https://myetherapi.com', serverURL: 'https://bity.myetherapi.com',
bityAPI: 'https://bity.com/api', bityAPI: 'https://bity.com/api',
decimals: 6, decimals: 6,
ethExplorer: 'https://etherscan.io/tx/[[txHash]]', ethExplorer: 'https://etherscan.io/tx/[[txHash]]',

View File

@ -7,14 +7,12 @@ import SwapProgress from './components/swapProgress';
import OnGoingSwapInformation from './components/onGoingSwapInformation'; import OnGoingSwapInformation from './components/onGoingSwapInformation';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import * as swapActions from 'actions/swap'; import * as swapActions from 'actions/swap';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import Bity from 'api/bity'; import { getAllRates } from 'api/bity';
class Swap extends Component { class Swap extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.bity = new Bity();
} }
static propTypes = { static propTypes = {
@ -48,7 +46,7 @@ class Swap extends Component {
!bityRates.BTCETH || !bityRates.BTCETH ||
!bityRates.BTCREP !bityRates.BTCREP
) { ) {
this.bity.getAllRates().then(data => { getAllRates().then(data => {
this.props.updateBityRatesSwap(data); this.props.updateBityRatesSwap(data);
}); });
} }
@ -112,12 +110,13 @@ class Swap extends Component {
// from bity // from bity
referenceNumber: referenceNumber, referenceNumber: referenceNumber,
timeRemaining: timeRemaining, timeRemaining: timeRemaining,
originAmount, originAmount,
originKind, originKind,
destinationKind, destinationKind,
destinationAmount, destinationAmount,
restartSwap restartSwap,
numberOfConfirmations: 3,
activeStep: 2
}; };
return ( return (