Fix: amount not clearing when returning to the home screen.

After a transaction was sent, the old value would linger. That's fine in the case of a failure so the user can try again but it is not okay after completing a transaction. The issue was that the fragment was staying in memory and it's UiModel was still available. The fix is to let the SendViewModel be the source of truth about what amount the user has entered.
This commit is contained in:
Kevin Gorham 2020-08-01 02:56:42 -04:00
parent a9bc645cb1
commit 92b19820cb
No known key found for this signature in database
GPG Key ID: CCA55602DF49FC38
1 changed files with 5 additions and 2 deletions

View File

@ -115,12 +115,14 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
}
if (::uiModel.isInitialized) {
twig("uiModel exists!")
onModelUpdated(null, uiModel)
twig("uiModel exists! it has pendingSend=${uiModel.pendingSend} ZEC while the sendViewModel=${sendViewModel.zatoshiAmount} zats")
// if the model already existed, cool but let the sendViewModel be the source of truth for the amount
onModelUpdated(null, uiModel.copy(pendingSend = sendViewModel.zatoshiAmount.coerceAtLeast(0).convertZatoshiToZecStringUniform(8)))
}
}
private fun onClearAmount() {
twig("onClearAmount()")
if (::uiModel.isInitialized) {
resumedScope.launch {
binding.textSendAmount.text.apply {
@ -228,6 +230,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
* @param amount the amount to send represented as ZEC, without the dollar sign.
*/
fun setSendAmount(amount: String, updateModel: Boolean = true) {
twig("setSendAmount($amount, $updateModel)")
binding.textSendAmount.text = "\$$amount".toColoredSpan(R.color.text_light_dimmed, "$")
if (updateModel) {
sendViewModel.zatoshiAmount = amount.safelyConvertToBigDecimal().convertZecToZatoshi()