mirror of
https://github.com/aljazceru/breez-sdk-docs.git
synced 2025-12-17 13:54:20 +01:00
Remove GetFiatCurrenciesAndRates snippet
This commit is contained in:
@@ -29,11 +29,4 @@ public class FiatCurrenciesSnippets
|
||||
}
|
||||
// ANCHOR_END: fetch-fiat-rates
|
||||
}
|
||||
|
||||
public void GetFiatCurrenciesAndRates(BlockingBreezServices sdk)
|
||||
{
|
||||
// ANCHOR: get-fiat-currencies-and-rates
|
||||
// TODO
|
||||
// ANCHOR_END: get-fiat-currencies-and-rates
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,25 +16,3 @@ Future<Map<String, Rate>> fetchFiatRates(String lspId) async {
|
||||
// ANCHOR_END: fetch-fiat-rates
|
||||
return fiatRatesMap;
|
||||
}
|
||||
|
||||
Future<Map<FiatCurrency, Rate>> fiatCurrenciesAndRate() async {
|
||||
// ANCHOR: get-fiat-currencies-and-rates
|
||||
List<FiatCurrency> fiatCurrencies = await BreezSDK().listFiatCurrencies();
|
||||
Map<String, Rate> fiatRates = await BreezSDK().fetchFiatRates();
|
||||
|
||||
var sorted = fiatCurrencies.toList();
|
||||
sorted.sort((f1, f2) {
|
||||
return f1.id.compareTo(f2.id);
|
||||
});
|
||||
|
||||
Map<FiatCurrency, Rate> result = {};
|
||||
for (var currency in sorted) {
|
||||
var rate = fiatRates[currency.id];
|
||||
if (rate != null) {
|
||||
result[currency] = rate;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
// ANCHOR_END: get-fiat-currencies-and-rates
|
||||
}
|
||||
|
||||
@@ -19,9 +19,3 @@ func FetchFiatRates() {
|
||||
}
|
||||
// ANCHOR_END: fetch-fiat-rates
|
||||
}
|
||||
|
||||
func GetFiatCurrenciesAndRates() {
|
||||
// ANCHOR: get-fiat-currencies-and-rates
|
||||
// TODO
|
||||
// ANCHOR_END: get-fiat-currencies-and-rates
|
||||
}
|
||||
|
||||
@@ -22,32 +22,4 @@ class FiatCurrencies {
|
||||
}
|
||||
// ANCHOR_END: fetch-fiat-rates
|
||||
}
|
||||
|
||||
fun get_fiat_currencies_and_rates(sdk: BlockingBreezServices) {
|
||||
// ANCHOR: get-fiat-currencies-and-rates
|
||||
fun fiatCurrenciesAndRate(): Map<FiatCurrency, Rate> = try {
|
||||
val fiatCurrencies = sdk.listFiatCurrencies()
|
||||
val fiatRates = sdk.fetchFiatRates()
|
||||
|
||||
val ratesMap = mutableMapOf<String, Rate>()
|
||||
for (rate in fiatRates) {
|
||||
ratesMap[rate.coin.lowercase()] = rate
|
||||
}
|
||||
|
||||
val sorted = fiatCurrencies.sortedBy { it.info.name }
|
||||
val result = LinkedHashMap<FiatCurrency, Rate>()
|
||||
for (currency in sorted) {
|
||||
val rate = ratesMap[currency.id.lowercase()]
|
||||
if (rate != null) {
|
||||
result[currency] = rate
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
} catch (e: Throwable) {
|
||||
// Handle error
|
||||
emptyMap()
|
||||
}
|
||||
// ANCHOR_END: get-fiat-currencies-and-rates
|
||||
}
|
||||
}
|
||||
@@ -14,9 +14,3 @@ const exampleFetchRates = async () => {
|
||||
const fiatRates = await fetchFiatRates()
|
||||
// ANCHOR_END: fetch-fiat-rates
|
||||
}
|
||||
|
||||
const exampleListCurrenciesAndRates = async () => {
|
||||
// ANCHOR: get-fiat-currencies-and-rates
|
||||
// TODO
|
||||
// ANCHOR_END: get-fiat-currencies-and-rates
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
@@ -19,30 +18,3 @@ async fn get_current_rates(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_fiat_currencies_and_rates(
|
||||
sdk: Arc<BreezServices>,
|
||||
) -> Result<Vec<(FiatCurrency, Rate)>> {
|
||||
// ANCHOR: get-fiat-currencies-and-rates
|
||||
let supported_fiat_currencies = sdk.list_fiat_currencies().await?;
|
||||
let fiat_rates = sdk.fetch_fiat_rates().await?;
|
||||
|
||||
let mut rates_map: HashMap<String, Rate> = HashMap::new();
|
||||
for rate in fiat_rates {
|
||||
rates_map.insert(rate.coin.to_string().to_lowercase(), rate);
|
||||
}
|
||||
|
||||
let mut sorted = supported_fiat_currencies.clone();
|
||||
sorted.sort_by_key(|f| f.info.name.clone());
|
||||
|
||||
let mut result: Vec<(FiatCurrency, Rate)> = Vec::new();
|
||||
for currency in sorted {
|
||||
let rate = rates_map.get(¤cy.id.to_lowercase());
|
||||
if let Some(rate) = rate.cloned() {
|
||||
result.push((currency, rate));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
// ANCHOR_END: get-fiat-currencies-and-rates
|
||||
}
|
||||
|
||||
@@ -21,28 +21,3 @@ func getCurrentRates(sdk:BlockingBreezServices) -> [Rate]? {
|
||||
// ANCHOR_END: fetch-fiat-rates
|
||||
return fiatRates
|
||||
}
|
||||
|
||||
func getFiatCurrencyAndRates(sdk: BlockingBreezServices) -> [(FiatCurrency,Rate)]? {
|
||||
// ANCHOR: get-fiat-currencies-and-rates
|
||||
var ratesMap = [String:Rate]()
|
||||
if let supportedFiatCurrencies = try? sdk.listFiatCurrencies(), let fiatRates = try? sdk.fetchFiatRates() {
|
||||
for fiatRate in fiatRates {
|
||||
ratesMap[fiatRate.coin.lowercased()] = fiatRate
|
||||
}
|
||||
|
||||
let sorted = supportedFiatCurrencies.sorted(by: { f1, f2 in
|
||||
f1.id<f2.id
|
||||
})
|
||||
|
||||
var result = [(FiatCurrency,Rate)]()
|
||||
for currency in sorted {
|
||||
if let rate = ratesMap[currency.id.lowercased()] {
|
||||
result.append((currency, rate))
|
||||
}
|
||||
|
||||
}
|
||||
return result
|
||||
}
|
||||
// ANCHOR_END: get-fiat-currencies-and-rates
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Supporting fiat currencies
|
||||
|
||||
In order to list the available fiat currencies:
|
||||
You can get the full details of supported fiat currencies, such as symbols and localized names:
|
||||
|
||||
<custom-tabs category="lang">
|
||||
<div slot="title">Rust</div>
|
||||
@@ -68,7 +68,7 @@ In order to list the available fiat currencies:
|
||||
</section>
|
||||
</custom-tabs>
|
||||
|
||||
To get the current BTC rate for the currencies:
|
||||
To get the current BTC rate in the various supported fiat currencies:
|
||||
|
||||
<custom-tabs category="lang">
|
||||
<div slot="title">Rust</div>
|
||||
@@ -139,71 +139,3 @@ except Exception as error:
|
||||
```
|
||||
</section>
|
||||
</custom-tabs>
|
||||
|
||||
At the example project you can see these methods combined:
|
||||
|
||||
<custom-tabs category="lang">
|
||||
<div slot="title">Rust</div>
|
||||
<section>
|
||||
|
||||
```rust,ignore
|
||||
{{#include ../../snippets/rust/src/fiat_currencies.rs:get-fiat-currencies-and-rates}}
|
||||
```
|
||||
</section>
|
||||
|
||||
<div slot="title">Swift</div>
|
||||
<section>
|
||||
|
||||
```swift,ignore
|
||||
{{#include ../../snippets/swift/BreezSDKExamples/Sources/FiatCurrencies.swift:get-fiat-currencies-and-rates}}
|
||||
```
|
||||
</section>
|
||||
|
||||
<div slot="title">Kotlin</div>
|
||||
<section>
|
||||
|
||||
```kotlin,ignore
|
||||
{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/FiatCurrencies.kt:get-fiat-currencies-and-rates}}
|
||||
```
|
||||
</section>
|
||||
|
||||
<div slot="title">React Native</div>
|
||||
<section>
|
||||
|
||||
```typescript
|
||||
{{#include ../../snippets/react-native/fiat_currencies.ts:get-fiat-currencies-and-rates}}
|
||||
```
|
||||
</section>
|
||||
|
||||
<div slot="title">Dart</div>
|
||||
<section>
|
||||
|
||||
```dart,ignore
|
||||
{{#include ../../snippets/dart_snippets/lib/fiat_currencies.dart:get-fiat-currencies-and-rates}}
|
||||
```
|
||||
</section>
|
||||
|
||||
<div slot="title">Python</div>
|
||||
<section>
|
||||
|
||||
```python,ignore
|
||||
# TODO
|
||||
```
|
||||
</section>
|
||||
|
||||
<div slot="title">Go</div>
|
||||
<section>
|
||||
|
||||
```go,ignore
|
||||
{{#include ../../snippets/go/fiat_currencies.go:get-fiat-currencies-and-rates}}
|
||||
```
|
||||
</section>
|
||||
|
||||
<div slot="title">C#</div>
|
||||
<section>
|
||||
|
||||
```cs,ignore
|
||||
{{#include ../../snippets/csharp/FiatCurrencies.cs:get-fiat-currencies-and-rates}}
|
||||
```
|
||||
</section>
|
||||
</custom-tabs>
|
||||
Reference in New Issue
Block a user