2017-06-18 19:56:11 -05:00
|
|
|
import bityConfig from 'config/bity';
|
2017-07-31 18:14:30 -05:00
|
|
|
import { checkHttpStatus, parseJSON } from './utils';
|
2017-06-11 20:01:27 -05:00
|
|
|
|
2017-07-03 19:08:35 -05:00
|
|
|
export function getAllRates() {
|
|
|
|
const mappedRates = {};
|
2017-09-24 19:06:28 -07:00
|
|
|
return _getAllRates().then((bityRates) => {
|
|
|
|
bityRates.objects.forEach((each) => {
|
2017-07-03 19:08:35 -05:00
|
|
|
const pairName = each.pair;
|
|
|
|
mappedRates[pairName] = parseFloat(each.rate_we_sell);
|
2017-06-19 00:39:07 -05:00
|
|
|
});
|
2017-07-03 19:08:35 -05:00
|
|
|
return mappedRates;
|
|
|
|
});
|
2017-07-31 18:14:30 -05: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);
|
|
|
|
}
|
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
export function getOrderStatus(orderId: string) {
|
2017-07-31 18:14:30 -05:00
|
|
|
return fetch(`${bityConfig.serverURL}/status`, {
|
|
|
|
method: 'POST',
|
|
|
|
body: JSON.stringify({
|
2017-09-24 19:06:28 -07:00
|
|
|
orderid: orderId
|
2017-07-31 18:14:30 -05:00
|
|
|
}),
|
|
|
|
headers: bityConfig.postConfig.headers
|
|
|
|
})
|
|
|
|
.then(checkHttpStatus)
|
|
|
|
.then(parseJSON);
|
2017-07-03 19:08:35 -05:00
|
|
|
}
|
2017-06-11 20:01:27 -05:00
|
|
|
|
2017-07-03 19:08:35 -05:00
|
|
|
function _getAllRates() {
|
2017-09-05 15:07:28 -05:00
|
|
|
return fetch(`${bityConfig.bityURL}/v1/rate2/`)
|
2017-07-31 18:14:30 -05:00
|
|
|
.then(checkHttpStatus)
|
|
|
|
.then(parseJSON);
|
2017-09-24 19:06:28 -07:00
|
|
|
}
|