2017-12-11 17:44:53 +00:00
|
|
|
import bityConfig, { WhitelistedCoins } from 'config/bity';
|
|
|
|
import { checkHttpStatus, parseJSON, filter } from './utils';
|
|
|
|
|
|
|
|
const isCryptoPair = (from: string, to: string, arr: WhitelistedCoins[]) => {
|
|
|
|
return filter(from, arr) && filter(to, arr);
|
|
|
|
};
|
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;
|
2017-12-11 17:44:53 +00:00
|
|
|
const from = { id: pairName.substring(0, 3) };
|
|
|
|
const to = { id: pairName.substring(3, 6) };
|
|
|
|
// Check if rate exists= && check if the pair only crypto to crypto, not crypto to fiat, or any other combination
|
|
|
|
if (parseFloat(each.rate_we_sell) && isCryptoPair(from.id, to.id, ['BTC', 'ETH', 'REP'])) {
|
|
|
|
mappedRates[pairName] = {
|
|
|
|
id: pairName,
|
|
|
|
options: [from, to],
|
|
|
|
rate: 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
|
|
|
}
|
|
|
|
|
2017-12-11 17:44:53 +00:00
|
|
|
export function postOrder(amount: number, destAddress: string, mode: number, pair: string) {
|
2017-07-31 23:14:30 +00:00
|
|
|
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
|
|
|
}
|