Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,18 @@ class CalculateFragment : BaseFragment(R.layout.fragment_calculate) {
if (currency != null && asset != null) {
updateUI(currency, asset)
}
} else {
runCatching {
loadingDialog.show(parentFragmentManager, LoadingProgressDialogFragment.TAG)
}.onFailure {
Timber.e(it)
}
}

val routeProfile = (requireActivity() as WalletActivity).routeProfile
if (routeProfile == null) {
checkData()
return
}
if (routeProfile.supportCurrencies.isEmpty()) {
if (routeProfile == null || routeProfile.supportCurrencies.isEmpty()) {
if (assetId == null && fiatMoneyViewModel.calculateState == null) {
showLoadingDialog()
}
checkData()
return
}
if (fiatMoneyViewModel.asset != null && fiatMoneyViewModel.currency != null) {
dismissLoadingDialog()
return
}
val supportCurrencies = routeProfile.supportCurrencies
Expand Down Expand Up @@ -147,13 +141,27 @@ class CalculateFragment : BaseFragment(R.layout.fragment_calculate) {
)
}
if (fiatMoneyViewModel.calculateState == null) {
refresh()
if (fiatMoneyViewModel.currency != null && fiatMoneyViewModel.asset != null) {
if (assetId == null) {
showLoadingDialog()
}
refresh()
} else {
dismissLoadingDialog()
}
} else {
dismissLoadingDialog()
}
}

private var isLoading = false
private var loadingDialogRequested = false

private fun setLoading(loading: Boolean) {
isLoading = loading
if (!loading) {
dismissLoadingDialog()
}
val binding = bindingOrNull() ?: return
binding.fiatLoading.isVisible = isLoading
binding.assetLoading.isVisible = isLoading
Expand All @@ -163,18 +171,35 @@ class CalculateFragment : BaseFragment(R.layout.fragment_calculate) {
binding.assetRl.isEnabled = !loading
if (!loading) {
updateUI()
}
}

private fun showLoadingDialog() {
loadingDialogRequested = true
view?.post {
if (!loadingDialogRequested || !isAdded || viewDestroyed() || parentFragmentManager.isStateSaved) {
return@post
}
if (parentFragmentManager.findFragmentByTag(LoadingProgressDialogFragment.TAG) != null) {
return@post
}
runCatching {
if (loadingDialog.isAdded) {
loadingDialog.dismiss()
}
LoadingProgressDialogFragment().showNow(parentFragmentManager, LoadingProgressDialogFragment.TAG)
}.onFailure {
Timber.e(it)
}
}
}

private val loadingDialog by lazy {
LoadingProgressDialogFragment()
private fun dismissLoadingDialog() {
loadingDialogRequested = false
if (!isAdded) return
runCatching {
(parentFragmentManager.findFragmentByTag(LoadingProgressDialogFragment.TAG) as? LoadingProgressDialogFragment)
?.dismissAllowingStateLoss()
}.onFailure {
Timber.e(it)
}
}

private suspend fun refresh(errorHandler: (() -> Unit)? = null) {
Expand Down Expand Up @@ -465,12 +490,18 @@ class CalculateFragment : BaseFragment(R.layout.fragment_calculate) {
initData()
updateUI()
} else {
dismissLoadingDialog()
binding.primaryTv.text = v
updateUI()
}
}
}

override fun onDestroyView() {
dismissLoadingDialog()
super.onDestroyView()
}

private fun openBankTransfer() {
viewLifecycleOwner.lifecycleScope.launch {
val app = fiatMoneyViewModel.findOrSyncApp(Constants.MIXIN_CASH_USER_ID)
Expand Down Expand Up @@ -707,12 +738,12 @@ class CalculateFragment : BaseFragment(R.layout.fragment_calculate) {
)
}
}.catch { e ->
setLoading(false)
activity?.finish()
}.collectLatest { state ->
fiatMoneyViewModel.calculateState = state
setLoading(false)
initData()
updateUI()
setLoading(false)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If the quote succeeds but the route profile has no currencies recognized by the app, initData() starts another checkData() request. This call then clears the retry's loading state, exposing the fiat picker while currency is still null. Tapping it crashes at currency!!. Let the retry own the loading state until it finishes.

}
}
}
Expand Down