MyCrypto/common/api/bity.ts
Eddie Wang 980366694c RPC Error Handling (#384)
* create ensureOkResponse and check against RPC responses

* Merge with develop branch

* added single unit test

* main nodes added

* getBalance method

* remove console.log

* minor conflict fix - readd polyfill to integration test

* added two more method tests

* seperate rpcnode from extended classes

* fixes etherscan

* added all tests

* revert files with only formatting changes

* remove console.logs - still need to update snapshot before tests will pass

* updated snapshot due to RpcNode fixes for Infura and Etherscan nodes

* added RpcNodeTest config so we don't rely on constants in code

* undo formatting changes

* Multiple fixes to error handling tokens.

* Fixed TSC errors

* Minor styling edit - change async func to promise

* changed shape of tokenBalances

* change balance type back to stricter TokenValue type

* remove package.json change and include test for error state.

* minor change removing unneeded line of code

* added longer timeout for api

* update snapshot
2017-11-29 23:35:17 -06:00

52 lines
1.1 KiB
TypeScript

import bityConfig from 'config/bity';
import { checkHttpStatus, parseJSON } from './utils';
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: new Headers(bityConfig.postConfig.headers)
})
.then(checkHttpStatus)
.then(parseJSON);
}
export function getOrderStatus(orderId: string) {
return fetch(`${bityConfig.serverURL}/status`, {
method: 'POST',
body: JSON.stringify({
orderid: orderId
}),
headers: new Headers(bityConfig.postConfig.headers)
})
.then(checkHttpStatus)
.then(parseJSON);
}
function _getAllRates() {
return fetch(`${bityConfig.bityURL}/v1/rate2/`)
.then(checkHttpStatus)
.then(parseJSON);
}