2017-07-08 02:00:09 +00:00
|
|
|
// @flow
|
2017-06-19 00:56:11 +00:00
|
|
|
import bityConfig from 'config/bity';
|
2017-07-31 23:14:30 +00:00
|
|
|
import { checkHttpStatus, parseJSON } from './utils';
|
|
|
|
import { combineAndUpper } from 'utils/formatters';
|
2017-06-12 01:01:27 +00:00
|
|
|
|
2017-07-31 23:14:30 +00:00
|
|
|
function findRateFromBityRateList(rateObjects, pairName: string) {
|
2017-07-04 00:08:35 +00:00
|
|
|
return rateObjects.find(x => x.pair === pairName);
|
|
|
|
}
|
2017-06-12 01:01:27 +00:00
|
|
|
|
2017-07-31 23:14:30 +00:00
|
|
|
function _getRate(bityRates, originKind: string, destinationKind: string) {
|
|
|
|
const pairName = combineAndUpper(originKind, destinationKind);
|
2017-07-08 02:00:09 +00:00
|
|
|
const rateObjects = bityRates.objects;
|
2017-07-04 00:08:35 +00:00
|
|
|
return findRateFromBityRateList(rateObjects, pairName);
|
|
|
|
}
|
2017-06-12 01:01:27 +00:00
|
|
|
|
2017-07-04 00:08:35 +00:00
|
|
|
export function getAllRates() {
|
|
|
|
const mappedRates = {};
|
|
|
|
return _getAllRates().then(bityRates => {
|
2017-07-08 02:00:09 +00:00
|
|
|
bityRates.objects.forEach(each => {
|
2017-07-04 00:08:35 +00:00
|
|
|
const pairName = each.pair;
|
|
|
|
mappedRates[pairName] = parseFloat(each.rate_we_sell);
|
2017-06-19 05:39:07 +00:00
|
|
|
});
|
2017-07-04 00:08:35 +00:00
|
|
|
return mappedRates;
|
|
|
|
});
|
2017-07-31 23:14:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-07-04 00:08:35 +00:00
|
|
|
}
|
2017-06-12 01:01:27 +00:00
|
|
|
|
2017-07-04 00:08:35 +00:00
|
|
|
function _getAllRates() {
|
2017-07-31 23:14:30 +00:00
|
|
|
return fetch(`${bityConfig.bityAPI}/v1/rate2/`)
|
|
|
|
.then(checkHttpStatus)
|
|
|
|
.then(parseJSON);
|
2017-06-12 01:01:27 +00:00
|
|
|
}
|
2017-07-04 00:08:35 +00:00
|
|
|
|
2017-07-31 23:14:30 +00:00
|
|
|
function requestOrderStatus() {}
|