Electric-Coin-Company / zcash-android-wallet-sdk

Native Android SDK for Zcash
MIT License
5 stars 9 forks source link

Provide Zatoshi -> USD fiat currency formatting #578

Closed HonzaR closed 2 weeks ago

HonzaR commented 2 years ago

Is your feature request related to a problem? Please describe.

Assuming we have a conversion rate as implemented in #614, we need methods that take an amount in Zatoshi and creates a properly formatted fiat currency amount.

This can be mostly ported over from the Secant app.

  1. We already have a function for converting ZEC to USD, which requires USD price for 1 ZEC: convertZecToUsd(zecPrice: BigDecimal) But the SDK does not seem to provide the zecPrice.

  2. Then, we'd also like to have a function for formatting conversion result of ZEC to USD as a String, like we already have for Zatoshi to ZEC:

convertZatoshiToZecString()

Describe the solution you'd like

For request number 2 the solution could be something like this:

fun Zatoshi.toUsdString() = value
   .convertZatoshiToZec()
   .convertZecToUsd(BigDecimal(100))
   .toUsdString()  

Additional context

The solution should be part of CurrencyFormatter.kt.

ccjernigan commented 2 years ago

I think there are two use cases:

Currency conversion will require a web service API call, and we'll need to likely expose an APIs for each of those use cases.

In the future, we might also want to support different currencies.

So building upon the API suggestion, we might need two additional model objects. One to represent the currency to be converted, and another representing a snapshot of a conversion at a point in time.