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';
|
2017-06-12 01:01:27 +00:00
|
|
|
|
2017-07-04 00:08:35 +00:00
|
|
|
export function getAllRates() {
|
|
|
|
const mappedRates = {};
|
2017-11-30 05:35:17 +00:00
|
|
|
return _getAllRates().then(bityRates => {
|
|
|
|
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
|
|
|
|
}),
|
2017-11-30 05:35:17 +00:00
|
|
|
headers: new Headers(bityConfig.postConfig.headers)
|
2017-07-31 23:14:30 +00:00
|
|
|
})
|
|
|
|
.then(checkHttpStatus)
|
|
|
|
.then(parseJSON);
|
|
|
|
}
|
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
export function getOrderStatus(orderId: string) {
|
2017-07-31 23:14:30 +00:00
|
|
|
return fetch(`${bityConfig.serverURL}/status`, {
|
|
|
|
method: 'POST',
|
|
|
|
body: JSON.stringify({
|
2017-09-25 02:06:28 +00:00
|
|
|
orderid: orderId
|
2017-07-31 23:14:30 +00:00
|
|
|
}),
|
2017-11-30 05:35:17 +00:00
|
|
|
headers: new Headers(bityConfig.postConfig.headers)
|
2017-07-31 23:14:30 +00:00
|
|
|
})
|
|
|
|
.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-09-05 20:07:28 +00:00
|
|
|
return fetch(`${bityConfig.bityURL}/v1/rate2/`)
|
2017-07-31 23:14:30 +00:00
|
|
|
.then(checkHttpStatus)
|
|
|
|
.then(parseJSON);
|
2017-11-30 05:35:17 +00:00
|
|
|
}
|