Skip to content

Commit

Permalink
Merge pull request breez#686 from rustaceanrob/sort-fiats
Browse files Browse the repository at this point in the history
enhancement: sort fiat currencies in API by name, add docs
  • Loading branch information
roeierez authored Dec 13, 2023
2 parents 47c6e87 + 5e7903e commit 8b8d672
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion libs/sdk-core/src/breez_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,12 +593,13 @@ impl BreezServices {
Ok(response)
}

/// Fetch live rates of fiat currencies
/// Fetch live rates of fiat currencies, sorted by name
pub async fn fetch_fiat_rates(&self) -> SdkResult<Vec<Rate>> {
self.fiat_api.fetch_fiat_rates().await
}

/// List all supported fiat currencies for which there is a known exchange rate.
/// List is sorted by the canonical name of the currency
pub async fn list_fiat_currencies(&self) -> SdkResult<Vec<FiatCurrency>> {
self.fiat_api.list_fiat_currencies().await
}
Expand Down
8 changes: 5 additions & 3 deletions libs/sdk-core/src/fiat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ impl FiatAPI for BreezServer {
fiat_currency_list.push(convert_to_fiat_currency_with_id(key, value));
}
}
fiat_currency_list.sort_by(|a, b| a.info.name.cmp(&b.info.name));
Ok(fiat_currency_list)
}

Expand All @@ -92,9 +93,10 @@ impl FiatAPI for BreezServer {
.map_err(|e| SdkError::ServiceConnectivity {
err: format!("Fetch rates request failed: {e}"),
})?;
Ok(response
.into_inner()
.rates

let mut rates = response.into_inner().rates;
rates.sort_by(|a, b| a.coin.cmp(&b.coin));
Ok(rates
.into_iter()
.map(|r| Rate {
coin: r.coin,
Expand Down

0 comments on commit 8b8d672

Please sign in to comment.