Skip to content

fix: stuck currency code & cleanup obsolete currencies - #1187

Merged
HashEngineering merged 13 commits into
masterfrom
fix-currency-code
Aug 22, 2023
Merged

HashEngineering merged 13 commits into
masterfrom
fix-currency-code

Conversation

@Syn-McJ

@Syn-McJ Syn-McJ commented Aug 18, 2023

Copy link
Copy Markdown
Member

When the user opens Receive screen, the currency code is set, and changing it from the settings won't have an effect until relaunch.
Additionally, we need to filter out obsolete currencies and not save them in the database.

Issue being fixed or feature implemented

  • Selected currency code is moved from Configuration to the WalletUIConfig datastore.
  • A bunch of refactoring related to the above change - e.g. observing local currency instead of just fetching it.
  • Clean up obsolete currencies during the migration from shared prefs to datastore.
  • Move currency detection from the activity to the viewModel.
  • Replace the old Currency Picker in the settings with the new dialog version.

Related PR's and Dependencies

Screenshots / Videos

How Has This Been Tested?

  • QA (Mobile Team)

Checklist:

  • I have performed a self-review of my own code and added comments where necessary
  • I have added or updated relevant unit/integration/functional/e2e tests

@Syn-McJ Syn-McJ self-assigned this Aug 18, 2023
Comment on lines +103 to +110
val sharedPreferences = context.getSharedPreferences(sharedPreferencesName, Context.MODE_PRIVATE)
val currentValue = sharedPreferences.getString(WalletUIConfig.SELECTED_CURRENCY.name, null)
currentValue?.let {
val fixedValue = CurrencyInfo.getUpdatedCurrency(CurrencyInfo.getOtherName(currentValue))
sharedPreferences.edit().putString(WalletUIConfig.SELECTED_CURRENCY.name, fixedValue).apply()
}
// The database might have obsolete currencies as well
exchangeRates.cleanupObsoleteCurrencies()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This will run once on migration and ensure we never have obsolete currency names in the datastore.
This way, we don't have to call getOtherName or getUpdatedCurrency every time.

Comment on lines -64 to -67
fun setCurrentCurrencySymbolWithCode(currencyCode: String): String? {
var currentLocale = Locale("", "")
var currentCurrencySymbol: String? = ""
when (currencyCode.lowercase()) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Was this method unnecessary or handled by standard android functions?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This was only used in the old EnterAmountFragment to figure out where the Dash symbol should go; we use isCurrencyFirst for it now which makes use of Androids NumberFormat.

@HashEngineering HashEngineering left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks great. Before merging, I want final confirmation from the CTX team about their server status.

val tradesRequest = TradesRequest(
valueToConvert.toFormattedStringNoCode(),
userPreference.exchangeCurrencyCode!!,
walletUIConfig.get(WalletUIConfig.SELECTED_CURRENCY) ?: Constants.USD_CURRENCY,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this be DEFAULT_EXCHANGE_CURRENCY ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, that'd be better

@HashEngineering
HashEngineering merged commit 7e813c7 into master Aug 22, 2023
@Syn-McJ
Syn-McJ deleted the fix-currency-code branch August 23, 2023 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants