mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-13 11:09:20 +01:00
FIX: Update use of CoinDesk API (#7678)
This commit is contained in:
parent
18a187b120
commit
4cdd952f90
10 changed files with 36 additions and 24 deletions
|
@ -56,7 +56,8 @@ object MarketAPI {
|
|||
"CoinGecko" -> "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=${endPointKey.lowercase()}"
|
||||
"BNR" -> "https://www.bnr.ro/nbrfxrates.xml"
|
||||
"Kraken" -> "https://api.kraken.com/0/public/Ticker?pair=XXBTZ${endPointKey.uppercase()}"
|
||||
else -> "https://api.coindesk.com/v1/bpi/currentprice/$endPointKey.json"
|
||||
"CoinDesk" -> "https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=${endPointKey.uppercase()}"
|
||||
else -> "https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=${endPointKey.uppercase()}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -73,6 +74,10 @@ object MarketAPI {
|
|||
"coinpaprika" -> json.getJSONObject("quotes").getJSONObject("INR").getString("price")
|
||||
"Coinbase" -> json.getJSONObject("data").getString("amount")
|
||||
"Kraken" -> json.getJSONObject("result").getJSONObject("XXBTZ${endPointKey.uppercase()}").getJSONArray("c").getString(0)
|
||||
"CoinDesk" -> {
|
||||
val rate = json.optDouble(endPointKey.uppercase(), -1.0)
|
||||
if (rate < 0) null else rate.toString()
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
|
|
@ -56,7 +56,7 @@
|
|||
<TextView
|
||||
android:id="@+id/price_value"
|
||||
style="@style/WidgetTextPrimary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
android:layout_marginEnd="8dp"
|
||||
|
@ -67,6 +67,7 @@
|
|||
android:autoSizeTextType="uniform"
|
||||
android:duplicateParentState="false"
|
||||
android:editable="false"
|
||||
android:gravity="end"
|
||||
android:lines="1"
|
||||
android:text="Loading..."
|
||||
android:textSize="24sp"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:initialLayout="@layout/widget_layout"
|
||||
android:minWidth="160dp"
|
||||
android:minWidth="170dp"
|
||||
android:minHeight="100dp"
|
||||
android:updatePeriodMillis="0"
|
||||
android:widgetCategory="home_screen"
|
||||
|
|
|
@ -1474,7 +1474,6 @@
|
|||
INFOPLIST_KEY_WKCompanionAppBundleIdentifier = io.bluewallet.bluewallet;
|
||||
INFOPLIST_KEY_WKExtensionDelegateClassName = "$(PRODUCT_BUNDLE_IDENTIFIER).ExtensionDelegate";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 15.6;
|
||||
"IPHONEOS_DEPLOYMENT_TARGET[sdk=macosx*]" = 15.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
|
@ -1533,7 +1532,6 @@
|
|||
INFOPLIST_KEY_WKCompanionAppBundleIdentifier = io.bluewallet.bluewallet;
|
||||
INFOPLIST_KEY_WKExtensionDelegateClassName = "$(PRODUCT_BUNDLE_IDENTIFIER).ExtensionDelegate";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 15.6;
|
||||
"IPHONEOS_DEPLOYMENT_TARGET[sdk=macosx*]" = 15.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
|
|
|
@ -1352,7 +1352,7 @@ PODS:
|
|||
- react-native-tcp-socket (6.2.0):
|
||||
- CocoaAsyncSocket
|
||||
- React-Core
|
||||
- react-native-true-sheet (2.0.4):
|
||||
- react-native-true-sheet (2.0.0):
|
||||
- DoubleConversion
|
||||
- glog
|
||||
- hermes-engine
|
||||
|
@ -2285,7 +2285,7 @@ SPEC CHECKSUMS:
|
|||
react-native-screen-capture: 7b6121f529681ed2fde36cdedadd0bb39e9a3796
|
||||
react-native-secure-key-store: eb45b44bdec3f48e9be5cdfca0f49ddf64892ea6
|
||||
react-native-tcp-socket: 61379457d7e702e83e28c213b6e085ac079e480f
|
||||
react-native-true-sheet: 56b251601d36b092964eb59a6916f4ad0a6fbed0
|
||||
react-native-true-sheet: 15f8d1bfbf2aceca472b9ba585b4116041d20f34
|
||||
React-nativeconfig: 67fa7a63ea288cb5b1d0dd2deaf240405fec164f
|
||||
React-NativeModulesApple: 34b7a4d7441a4ee78d18109ff107c1ccf7c074a9
|
||||
React-perflogger: d1149037ac466ad2141d4ae541ca16cb73b2343b
|
||||
|
|
|
@ -30,8 +30,8 @@ class MarketAPI {
|
|||
return "https://www.bnr.ro/nbrfxrates.xml"
|
||||
case "Kraken":
|
||||
return "https://api.kraken.com/0/public/Ticker?pair=XXBTZ\(endPointKey.uppercased())"
|
||||
default:
|
||||
return "https://api.coindesk.com/v1/bpi/currentprice/\(endPointKey).json"
|
||||
default: // CoinDesk
|
||||
return "https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=\(endPointKey)"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,8 +131,14 @@ class MarketAPI {
|
|||
throw CurrencyError(errorDescription: "Data formatting error for source: \(source)")
|
||||
}
|
||||
}
|
||||
default:
|
||||
throw CurrencyError(errorDescription: "Unsupported data source \(source)")
|
||||
default: // CoinDesk
|
||||
if let rateDouble = json[endPointKey] as? Double {
|
||||
let lastUpdatedString = ISO8601DateFormatter().string(from: Date())
|
||||
latestRateDataStore = WidgetDataStore(rate: String(rateDouble), lastUpdate: lastUpdatedString, rateDouble: rateDouble)
|
||||
return latestRateDataStore
|
||||
} else {
|
||||
throw CurrencyError(errorDescription: "Data formatting error for source: \(source)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { fetch } from '../util/fetch';
|
||||
import untypedFiatUnit from './fiatUnits.json';
|
||||
|
||||
export const FiatUnitSource = {
|
||||
|
@ -15,7 +16,8 @@ export const FiatUnitSource = {
|
|||
|
||||
const handleError = (source: string, ticker: string, error: Error) => {
|
||||
throw new Error(
|
||||
`Could not update rate for ${ticker} from ${source}: ${error.message}. ` + `Make sure the network you're on has access to ${source}.`,
|
||||
`Could not update rate for ${ticker} from ${source}\n: ${error.message}. ` +
|
||||
`\nMake sure the network you're on has access to ${source}.`,
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -34,11 +36,7 @@ interface CoinbaseResponse {
|
|||
}
|
||||
|
||||
interface CoinDeskResponse {
|
||||
bpi: {
|
||||
[ticker: string]: {
|
||||
rate_float: number;
|
||||
};
|
||||
};
|
||||
[ticker: string]: number;
|
||||
}
|
||||
|
||||
interface CoinGeckoResponse {
|
||||
|
@ -96,8 +94,10 @@ const RateExtractors = {
|
|||
|
||||
CoinDesk: async (ticker: string): Promise<number> => {
|
||||
try {
|
||||
const json = (await fetchRate(`https://api.coindesk.com/v1/bpi/currentprice/${ticker}.json`)) as CoinDeskResponse;
|
||||
const rate = Number(json?.bpi?.[ticker]?.rate_float);
|
||||
const json = (await fetchRate(
|
||||
`https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=${ticker.toUpperCase()}`,
|
||||
)) as CoinDeskResponse;
|
||||
const rate = json?.[ticker.toUpperCase()];
|
||||
if (!(rate >= 0)) throw new Error('Invalid data received');
|
||||
return rate;
|
||||
} catch (error: any) {
|
||||
|
|
7
package-lock.json
generated
7
package-lock.json
generated
|
@ -14,7 +14,7 @@
|
|||
"@bugsnag/react-native": "8.2.0",
|
||||
"@bugsnag/source-maps": "2.3.3",
|
||||
"@keystonehq/bc-ur-registry": "0.7.0",
|
||||
"@lodev09/react-native-true-sheet": "github:BlueWallet/react-native-true-sheet#49ba54e",
|
||||
"@lodev09/react-native-true-sheet": "github:BlueWallet/react-native-true-sheet#5945184a2fea9fe5ba8f5cfcdb20e3fc5eed6e37",
|
||||
"@ngraveio/bc-ur": "1.1.13",
|
||||
"@noble/secp256k1": "1.6.3",
|
||||
"@react-native-async-storage/async-storage": "2.1.0",
|
||||
|
@ -4693,8 +4693,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@lodev09/react-native-true-sheet": {
|
||||
"version": "2.0.4",
|
||||
"resolved": "git+ssh://git@github.com/BlueWallet/react-native-true-sheet.git#49ba54ed2a40671a887b03c9253670df7adfab29",
|
||||
"version": "2.0.0",
|
||||
"resolved": "git+ssh://git@github.com/BlueWallet/react-native-true-sheet.git#5945184a2fea9fe5ba8f5cfcdb20e3fc5eed6e37",
|
||||
"integrity": "sha512-JoMgC3w8Xgzvb4zHRnBdycBDuhz1O8MuKh9LE3QJjCElcm8x0n3asHzrt+XaLs3XfVrvq/LNyIMQSSYtvvhFKA==",
|
||||
"license": "MIT",
|
||||
"workspaces": [
|
||||
"example",
|
||||
|
|
|
@ -82,7 +82,7 @@
|
|||
"@bugsnag/react-native": "8.2.0",
|
||||
"@bugsnag/source-maps": "2.3.3",
|
||||
"@keystonehq/bc-ur-registry": "0.7.0",
|
||||
"@lodev09/react-native-true-sheet": "github:BlueWallet/react-native-true-sheet#49ba54e",
|
||||
"@lodev09/react-native-true-sheet": "github:BlueWallet/react-native-true-sheet#5945184a2fea9fe5ba8f5cfcdb20e3fc5eed6e37",
|
||||
"@ngraveio/bc-ur": "1.1.13",
|
||||
"@noble/secp256k1": "1.6.3",
|
||||
"@react-native-async-storage/async-storage": "2.1.0",
|
||||
|
|
|
@ -118,7 +118,8 @@ const Currency: React.FC = () => {
|
|||
<FlatList
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
automaticallyAdjustContentInsets
|
||||
keyExtractor={(_item, index) => `${index}`}
|
||||
automaticallyAdjustKeyboardInsets
|
||||
keyExtractor={item => item.endPointKey}
|
||||
data={data}
|
||||
initialNumToRender={30}
|
||||
renderItem={renderItem}
|
||||
|
|
Loading…
Add table
Reference in a new issue