Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Feature/exchange rate providers #147

Merged

Conversation

michaelWuensch
Copy link
Contributor

Description

Added option to change exchange rate provider. (In Advanced Settings)
For now only Coinbase is added, but should be simple to add more providers now.
Separated exchange rate providers from monetary util into its own.
Replaced a lot of strings with constants.

Motivation and Context

Address issue #104

How Has This Been Tested?

On my S9

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the Contribution document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@michaelWuensch michaelWuensch self-assigned this Nov 16, 2019
- fixed a bug that caused the exchange rate not to update directly after switching to coinbase.
- no longer request exchange rates when switching provider while second currency is a BTC unit
listExchangeRateProvider.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
PrefsUtil.edit().putString(PrefsUtil.EXCHANGE_RATE_PROVIDER, newValue.toString()).commit();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If setOnPreferenceChangeListener is invoked, doesn't it imply that the value already has been changed and this line changes it again?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I want to update the exchange rates when changing the provider.
If I don't have that line here, it will update the exchange rates before the provider is switched and therefore fetching the rates from the wrong provider.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or in other words: The value is not changed until true is returned. That's why I have to do it earlier.

* @param response a JSON response that comes from Blockchain.info
* @return
*/
public JSONObject parseBlockchainInfoResponse(JSONObject response) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe an easier way to parse the Json would be by using Gson.
see e.g. https://stackoverflow.com/questions/38636254/how-to-convert-json-to-java-object-using-gson
But works as well as we do it now 👍

Iterator<String> iter = rates.keys();
while (iter.hasNext()) {
String rateCode = iter.next();
if (AppUtil.getInstance(mContext).getCurrencyNameFromCurrencyCode(rateCode) == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, not sure but this loads every iteration the whole json list from resources. Maybe a little cost expensive.
Would be nice if we can load the list once and then use it.

@michaelWuensch michaelWuensch merged commit d7d131e into LN-Zap:master Nov 23, 2019
@michaelWuensch michaelWuensch deleted the feature/ExchangeRateProviders branch November 23, 2019 23:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants