Refresh wallet transparent balance flow from `WalletSummary`
Previously we only showed balance updates for the default address; this could potentially undercount transparent balance in some cases. We also now use the total zero-conf transparent balance for both "total" and "available", because we only allow transparent balance to be shielded, and we use a zero-conf transaction to do so.
This commit is contained in:
parent
55d0dd47d8
commit
e0fcbbea3a
|
@ -715,15 +715,6 @@ class CompactBlockProcessor internal constructor(
|
|||
transactionStorage.invalidate()
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the latest Transparent balance, based on the blocks that have been scanned and transmit this
|
||||
* information into the internal [transparentBalances] flow.
|
||||
*/
|
||||
internal suspend fun checkTransparentBalance() {
|
||||
Twig.debug { "Checking Transparent balance" }
|
||||
transparentBalances.value = getUtxoCacheBalance(getTransparentAddress(backend, Account.DEFAULT))
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the latest balances using the given wallet summary, and transmit this information
|
||||
* into the related internal flows. Note that the Orchard balance is not supported.
|
||||
|
@ -732,10 +723,17 @@ class CompactBlockProcessor internal constructor(
|
|||
summary.accountBalances[Account.DEFAULT]?.let {
|
||||
Twig.debug { "Updating Sapling balance" }
|
||||
saplingBalances.value = it.sapling
|
||||
// TODO [#682]: refresh orchard balance
|
||||
// TODO [#682]: Uncomment this once we have Orchard support.
|
||||
// TODO [#682]: https://github.com/zcash/zcash-android-wallet-sdk/issues/682
|
||||
// orchardBalances.value = it.orchard
|
||||
// We only allow stored transparent balance to be shielded, and we do so with
|
||||
// a zero-conf transaction, so treat all unshielded balance as available.
|
||||
transparentBalances.value =
|
||||
WalletBalance(
|
||||
it.unshielded,
|
||||
it.unshielded
|
||||
)
|
||||
}
|
||||
checkTransparentBalance()
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,7 +4,9 @@ import cash.z.ecc.android.sdk.model.WalletBalance
|
|||
import cash.z.ecc.android.sdk.model.Zatoshi
|
||||
|
||||
internal data class AccountBalance(
|
||||
val sapling: WalletBalance
|
||||
val sapling: WalletBalance,
|
||||
val orchard: WalletBalance,
|
||||
val unshielded: Zatoshi
|
||||
) {
|
||||
companion object {
|
||||
fun new(jni: JniAccountBalance): AccountBalance {
|
||||
|
@ -13,7 +15,13 @@ internal data class AccountBalance(
|
|||
WalletBalance(
|
||||
Zatoshi(jni.saplingTotalBalance),
|
||||
Zatoshi(jni.saplingVerifiedBalance)
|
||||
)
|
||||
),
|
||||
orchard =
|
||||
WalletBalance(
|
||||
Zatoshi(jni.orchardTotalBalance),
|
||||
Zatoshi(jni.orchardVerifiedBalance)
|
||||
),
|
||||
unshielded = Zatoshi(jni.unshieldedBalance)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue