zcash-android-wallet-sdk icon indicating copy to clipboard operation
zcash-android-wallet-sdk copied to clipboard

Provide Zatoshi -> USD fiat currency formatting

Open HonzaR opened this issue 2 years ago • 1 comments

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.

HonzaR avatar Jun 21 '22 12:06 HonzaR

I think there are two use cases:

  • Current currency amount (e.g. looking at your balance on the home screen)
  • Historical currency amount (e.g. looking at a historical transaction)

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

  • Synchronizer should probably be responsible for keeping fresh currency conversions. It could be something like a Flow that is updated whenever new conversion values are available.
  • A different API might be needed for explicit historical lookups. Ideally, we'd also cache values since these would be mostly correlated to the user's transaction history.

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.

ccjernigan avatar Jun 21 '22 13:06 ccjernigan