mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-12 20:14:12 +00:00
a66337ac0a
### Re-implements: * min/max validators on initial currency swap selection * polling of order status * timer that persists across refreshes via localStorage (computed based on `createdTime` and `validFor` amount) * swap persists across refreshes once order is created. * various type refactors ### New additions: * *SimpleButton* (can be PRd separately on request) * clear loading state after order create (via SimpleButton and font-awesome) * buffers for non-BTC swaps (bity does not actually accept 0.01 BTC worth of ETH as they claim they do in their JSON response, so a magic number of 10% is added to the minimum).
66 lines
1.6 KiB
JavaScript
66 lines
1.6 KiB
JavaScript
// @flow
|
|
import bityConfig from 'config/bity';
|
|
import { checkHttpStatus, parseJSON } from './utils';
|
|
import { combineAndUpper } from 'utils/formatters';
|
|
|
|
function findRateFromBityRateList(rateObjects, pairName: string) {
|
|
return rateObjects.find(x => x.pair === pairName);
|
|
}
|
|
|
|
function _getRate(bityRates, originKind: string, destinationKind: string) {
|
|
const pairName = combineAndUpper(originKind, destinationKind);
|
|
const rateObjects = bityRates.objects;
|
|
return findRateFromBityRateList(rateObjects, pairName);
|
|
}
|
|
|
|
export function getAllRates() {
|
|
const mappedRates = {};
|
|
return _getAllRates().then(bityRates => {
|
|
bityRates.objects.forEach(each => {
|
|
const pairName = each.pair;
|
|
mappedRates[pairName] = parseFloat(each.rate_we_sell);
|
|
});
|
|
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);
|
|
}
|
|
|
|
function _getAllRates() {
|
|
return fetch(`${bityConfig.bityAPI}/v1/rate2/`)
|
|
.then(checkHttpStatus)
|
|
.then(parseJSON);
|
|
}
|
|
|
|
function requestOrderStatus() {}
|