mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-02-02 14:23:42 +00:00
Bity: refactor and remove unnecessary class
This commit is contained in:
parent
62150fb63b
commit
513b4c67b9
@ -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() {}
|
||||
|
@ -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]]',
|
||||
|
@ -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 (
|
||||
|
Loading…
x
Reference in New Issue
Block a user