MyCrypto/common/api/bity.js

66 lines
1.6 KiB
JavaScript
Raw Normal View History

// @flow
2017-06-18 17:56:11 -07:00
import bityConfig from 'config/bity';
import { checkHttpStatus, parseJSON } from './utils';
// import { combineAndUpper } from 'utils/formatters';
2017-06-11 18:01:27 -07:00
// function findRateFromBityRateList(rateObjects, pairName: string) {
// return rateObjects.find(x => x.pair === pairName);
// }
2017-06-11 18:01:27 -07:00
// function _getRate(bityRates, originKind: string, destinationKind: string) {
// const pairName = combineAndUpper(originKind, destinationKind);
// const rateObjects = bityRates.objects;
// return findRateFromBityRateList(rateObjects, pairName);
// }
2017-06-11 18:01:27 -07:00
export function getAllRates() {
const mappedRates = {};
return _getAllRates().then(bityRates => {
bityRates.objects.forEach(each => {
const pairName = each.pair;
mappedRates[pairName] = parseFloat(each.rate_we_sell);
2017-06-18 22:39:07 -07:00
});
return mappedRates;
});
}
export function postOrder(
amount: number,
destAddress: string,
mode: number,
pair: string
) {
return fetch(`${bityConfig.serverURL}/order`, {
method: 'post',
body: JSON.stringify({
amount,
destAddress,
mode,
pair
}),
headers: bityConfig.postConfig.headers
})
.then(checkHttpStatus)
.then(parseJSON);
}
export function getOrderStatus(orderid: string) {
return fetch(`${bityConfig.serverURL}/status`, {
method: 'POST',
body: JSON.stringify({
orderid
}),
headers: bityConfig.postConfig.headers
})
.then(checkHttpStatus)
.then(parseJSON);
}
2017-06-11 18:01:27 -07:00
function _getAllRates() {
return fetch(`${bityConfig.bityAPI}/v1/rate2/`)
.then(checkHttpStatus)
.then(parseJSON);
2017-06-11 18:01:27 -07:00
}
// function requestOrderStatus() {}