mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-26 08:55:56 +01:00
REF: refactored frisbee to fetch in currency.js
This commit is contained in:
parent
82f88286af
commit
f9576dfc9b
5 changed files with 54 additions and 24 deletions
|
@ -62,6 +62,7 @@ async function updateExchangeRate() {
|
|||
try {
|
||||
rate = await getFiatRate(preferredFiatCurrency.endPointKey);
|
||||
} catch (Err) {
|
||||
console.warn(Err.message);
|
||||
const lastSavedExchangeRate = JSON.parse(await AsyncStorage.getItem(EXCHANGE_RATES));
|
||||
exchangeRates['BTC_' + preferredFiatCurrency.endPointKey] = lastSavedExchangeRate['BTC_' + preferredFiatCurrency.endPointKey] * 1;
|
||||
return;
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import Frisbee from 'frisbee';
|
||||
import untypedFiatUnit from './fiatUnits.json';
|
||||
|
||||
export const FiatUnitSource = {
|
||||
|
@ -10,13 +9,10 @@ export const FiatUnitSource = {
|
|||
|
||||
const RateExtractors = {
|
||||
CoinDesk: async (ticker: string): Promise<number> => {
|
||||
const api = new Frisbee({ baseURI: 'https://api.coindesk.com' });
|
||||
const res = await api.get(`/v1/bpi/currentprice/${ticker}.json`);
|
||||
if (res.err) throw new Error(`Could not update rate for ${ticker}: ${res.err}`);
|
||||
|
||||
let json;
|
||||
try {
|
||||
json = typeof res.body === 'string' ? JSON.parse(res.body) : res.body;
|
||||
const res = await fetch(`https://api.coindesk.com/v1/bpi/currentprice/${ticker}.json`);
|
||||
json = await res.json();
|
||||
} catch (e) {
|
||||
throw new Error(`Could not update rate for ${ticker}: ${e.message}`);
|
||||
}
|
||||
|
@ -27,14 +23,12 @@ const RateExtractors = {
|
|||
if (!(rate >= 0)) throw new Error(`Could not update rate for ${ticker}: data is wrong`);
|
||||
return rate;
|
||||
},
|
||||
Yadio: async (ticker: string): Promise<number> => {
|
||||
const api = new Frisbee({ baseURI: 'https://api.yadio.io/json' });
|
||||
const res = await api.get(`/${ticker}`);
|
||||
if (res.err) throw new Error(`Could not update rate for ${ticker}: ${res.err}`);
|
||||
|
||||
Yadio: async (ticker: string): Promise<number> => {
|
||||
let json;
|
||||
try {
|
||||
json = typeof res.body === 'string' ? JSON.parse(res.body) : res.body;
|
||||
const res = await fetch(`https://api.yadio.io/json/${ticker}`);
|
||||
json = await res.json();
|
||||
} catch (e) {
|
||||
throw new Error(`Could not update rate for ${ticker}: ${e.message}`);
|
||||
}
|
||||
|
@ -45,14 +39,12 @@ const RateExtractors = {
|
|||
if (!(rate >= 0)) throw new Error(`Could not update rate for ${ticker}: data is wrong`);
|
||||
return rate;
|
||||
},
|
||||
BitcoinduLiban: async (ticker: string): Promise<number> => {
|
||||
const api = new Frisbee({ baseURI: 'https://bitcoinduliban.org' });
|
||||
const res = await api.get('/api.php?key=lbpusd');
|
||||
if (res.err) throw new Error(`Could not update rate for ${ticker}: ${res.err}`);
|
||||
|
||||
BitcoinduLiban: async (ticker: string): Promise<number> => {
|
||||
let json;
|
||||
try {
|
||||
json = typeof res.body === 'string' ? JSON.parse(res.body) : res.body;
|
||||
const res = await fetch('https://bitcoinduliban.org/api.php?key=lbpusd');
|
||||
json = await res.json();
|
||||
} catch (e) {
|
||||
throw new Error(`Could not update rate for ${ticker}: ${e.message}`);
|
||||
}
|
||||
|
@ -63,14 +55,12 @@ const RateExtractors = {
|
|||
if (!(rate >= 0)) throw new Error(`Could not update rate for ${ticker}: data is wrong`);
|
||||
return rate;
|
||||
},
|
||||
Exir: async (ticker: string): Promise<number> => {
|
||||
const api = new Frisbee({ baseURI: 'https://api.exir.io' });
|
||||
const res = await api.get('/v1/ticker?symbol=btc-irt');
|
||||
if (res.err) throw new Error(`Could not update rate for ${ticker}: ${res.err}`);
|
||||
|
||||
Exir: async (ticker: string): Promise<number> => {
|
||||
let json;
|
||||
try {
|
||||
json = typeof res.body === 'string' ? JSON.parse(res.body) : res.body;
|
||||
const res = await fetch('https://api.exir.io/v1/ticker?symbol=btc-irt');
|
||||
json = await res.json();
|
||||
} catch (e) {
|
||||
throw new Error(`Could not update rate for ${ticker}: ${e.message}`);
|
||||
}
|
||||
|
|
43
package-lock.json
generated
43
package-lock.json
generated
|
@ -3390,6 +3390,11 @@
|
|||
"resolved": "https://registry.npmjs.org/mime/-/mime-2.5.2.tgz",
|
||||
"integrity": "sha512-tqkh47FzKeCPD2PUiPB6pkbMzsCasjxAfC62/Wap5qrUWcb+sFasXUC5I3gYM5iBM8v/Qpn4UK0x+j0iHyFPDg=="
|
||||
},
|
||||
"node-fetch": {
|
||||
"version": "2.6.2",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.2.tgz",
|
||||
"integrity": "sha512-aLoxToI6RfZ+0NOjmWAgn9+LEd30YCkJKFSyWacNZdEKTit/ZMcKjGkTRo8uWEsnIb/hfKecNPEbln02PdWbcA=="
|
||||
},
|
||||
"shell-quote": {
|
||||
"version": "1.6.1",
|
||||
"resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.6.1.tgz",
|
||||
|
@ -6823,6 +6828,13 @@
|
|||
"integrity": "sha512-1eAtFWdIubi6T4XPy6ei9iUFoKpUkIF971QLN8lIvvvwueI65+Nw5haMNKUwfJxabqlIIDODJKGrQ66gxC0PbQ==",
|
||||
"requires": {
|
||||
"node-fetch": "2.6.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"node-fetch": {
|
||||
"version": "2.6.1",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
|
||||
"integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"cross-spawn": {
|
||||
|
@ -15458,6 +15470,11 @@
|
|||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||
},
|
||||
"node-fetch": {
|
||||
"version": "2.6.2",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.2.tgz",
|
||||
"integrity": "sha512-aLoxToI6RfZ+0NOjmWAgn9+LEd30YCkJKFSyWacNZdEKTit/ZMcKjGkTRo8uWEsnIb/hfKecNPEbln02PdWbcA=="
|
||||
},
|
||||
"p-locate": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz",
|
||||
|
@ -16268,9 +16285,10 @@
|
|||
}
|
||||
},
|
||||
"node-fetch": {
|
||||
"version": "2.6.1",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
|
||||
"integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw=="
|
||||
"version": "2.6.2",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.2.tgz",
|
||||
"integrity": "sha512-aLoxToI6RfZ+0NOjmWAgn9+LEd30YCkJKFSyWacNZdEKTit/ZMcKjGkTRo8uWEsnIb/hfKecNPEbln02PdWbcA==",
|
||||
"dev": true
|
||||
},
|
||||
"node-int64": {
|
||||
"version": "0.4.0",
|
||||
|
@ -18283,6 +18301,13 @@
|
|||
"node-fetch": "^2.6.0",
|
||||
"open": "^6.2.0",
|
||||
"shell-quote": "1.6.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"node-fetch": {
|
||||
"version": "2.6.2",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.2.tgz",
|
||||
"integrity": "sha512-aLoxToI6RfZ+0NOjmWAgn9+LEd30YCkJKFSyWacNZdEKTit/ZMcKjGkTRo8uWEsnIb/hfKecNPEbln02PdWbcA=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"@react-native-community/cli-types": {
|
||||
|
@ -18614,6 +18639,11 @@
|
|||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-2.1.0.tgz",
|
||||
"integrity": "sha512-Q89Z26KAfA3lpPGhbF6XMfYAm3jIV3avViy6KOJ2JLzFbeWHOvPQUu5aSJIWXap3gDZC2y1eF5HXEPI2wGqgvw=="
|
||||
},
|
||||
"node-fetch": {
|
||||
"version": "2.6.2",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.2.tgz",
|
||||
"integrity": "sha512-aLoxToI6RfZ+0NOjmWAgn9+LEd30YCkJKFSyWacNZdEKTit/ZMcKjGkTRo8uWEsnIb/hfKecNPEbln02PdWbcA=="
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -18624,6 +18654,13 @@
|
|||
"requires": {
|
||||
"abort-controller": "^3.0.0",
|
||||
"node-fetch": "^2.6.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"node-fetch": {
|
||||
"version": "2.6.2",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.2.tgz",
|
||||
"integrity": "sha512-aLoxToI6RfZ+0NOjmWAgn9+LEd30YCkJKFSyWacNZdEKTit/ZMcKjGkTRo8uWEsnIb/hfKecNPEbln02PdWbcA=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"recast": {
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
"eslint-plugin-react": "^7.23.2",
|
||||
"eslint-plugin-standard": "^4.1.0",
|
||||
"jest": "^26.1.0",
|
||||
"node-fetch": "^2.6.2",
|
||||
"prettier": "^2.2.1",
|
||||
"react-test-renderer": "17.0.1",
|
||||
"typescript": "^4.3.5"
|
||||
|
|
|
@ -4,6 +4,7 @@ import mockClipboard from '@react-native-clipboard/clipboard/jest/clipboard-mock
|
|||
|
||||
global.net = require('net'); // needed by Electrum client. For RN it is proviced in shim.js
|
||||
global.tls = require('tls'); // needed by Electrum client. For RN it is proviced in shim.js
|
||||
global.fetch = require('node-fetch');
|
||||
|
||||
jest.mock('@react-native-clipboard/clipboard', () => mockClipboard);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue