mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-02-09 01:33:37 +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;
|
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) {
|
|
||||||
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 _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 {
|
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]]',
|
||||||
|
@ -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 (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user