mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-01-19 05:45:15 +01:00
FIX: Bug: CNY price is wrong #5705
This commit is contained in:
parent
d90de3efab
commit
2fbf8b42c9
@ -37,6 +37,8 @@ class WidgetAPI {
|
||||
urlString = "https://api.wazirx.com/api/v2/tickers/btcinr"
|
||||
case "Bitstamp":
|
||||
urlString = "https://www.bitstamp.net/api/v2/ticker/btc\(endPointKey.lowercased())"
|
||||
case "Coinbase":
|
||||
urlString = "https://api.coinbase.com/v2/prices/BTC-\(endPointKey.uppercased())/buy"
|
||||
case "CoinGecko":
|
||||
urlString = "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=\(endPointKey.lowercased())"
|
||||
default:
|
||||
@ -95,6 +97,13 @@ class WidgetAPI {
|
||||
else { break }
|
||||
let lastUpdatedString = ISO8601DateFormatter().string(from: Date())
|
||||
latestRateDataStore = WidgetDataStore(rate: rateString, lastUpdate: lastUpdatedString, rateDouble: rateDouble)
|
||||
case "Coinbase":
|
||||
guard let data = json["data"] as? Dictionary<String, Any>,
|
||||
let rateString = data["amount"] as? String,
|
||||
let rateDouble = Double(rateString)
|
||||
else { break }
|
||||
let lastUpdatedString = ISO8601DateFormatter().string(from: Date())
|
||||
latestRateDataStore = WidgetDataStore(rate: rateString, lastUpdate: lastUpdatedString, rateDouble: rateDouble)
|
||||
default:
|
||||
guard let bpi = json["bpi"] as? Dictionary<String, Any>,
|
||||
let preferredCurrency = bpi[endPointKey] as? Dictionary<String, Any>,
|
||||
|
@ -1,6 +1,7 @@
|
||||
import untypedFiatUnit from './fiatUnits.json';
|
||||
|
||||
export const FiatUnitSource = {
|
||||
Coinbase: 'Coinbase',
|
||||
CoinDesk: 'CoinDesk',
|
||||
CoinGecko: 'CoinGecko',
|
||||
Yadio: 'Yadio',
|
||||
@ -11,6 +12,21 @@ export const FiatUnitSource = {
|
||||
} as const;
|
||||
|
||||
const RateExtractors = {
|
||||
Coinbase: async (ticker: string): Promise<number> => {
|
||||
let json;
|
||||
try {
|
||||
const res = await fetch(`https://api.coinbase.com/v2/prices/BTC-${ticker.toUpperCase()}/buy`);
|
||||
json = await res.json();
|
||||
} catch (e: any) {
|
||||
throw new Error(`Could not update rate for ${ticker}: ${e.message}`);
|
||||
}
|
||||
let rate = json?.data?.amount;
|
||||
if (!rate) throw new Error(`Could not update rate for ${ticker}: data is wrong`);
|
||||
|
||||
rate = Number(rate);
|
||||
if (!(rate >= 0)) throw new Error(`Could not update rate for ${ticker}: data is wrong`);
|
||||
return rate;
|
||||
},
|
||||
CoinDesk: async (ticker: string): Promise<number> => {
|
||||
let json;
|
||||
try {
|
||||
|
@ -68,7 +68,7 @@
|
||||
"CNY": {
|
||||
"endPointKey": "CNY",
|
||||
"locale": "zh-CN",
|
||||
"source": "CoinDesk",
|
||||
"source": "Coinbase",
|
||||
"symbol": "¥"
|
||||
},
|
||||
"COP": {
|
||||
|
Loading…
Reference in New Issue
Block a user