2022-03-08 11:05:03 -08:00
|
|
|
package co.electriccoin.zcash.ui.screen.home.model
|
2021-12-29 11:38:14 -08:00
|
|
|
|
|
|
|
import cash.z.ecc.android.sdk.Synchronizer
|
|
|
|
import cash.z.ecc.android.sdk.block.CompactBlockProcessor
|
|
|
|
import cash.z.ecc.android.sdk.ext.ZcashSdk
|
2022-06-23 04:31:16 -07:00
|
|
|
import cash.z.ecc.android.sdk.model.Zatoshi
|
2021-12-29 11:38:14 -08:00
|
|
|
import cash.z.ecc.android.sdk.type.WalletBalance
|
|
|
|
|
2022-04-01 07:28:16 -07:00
|
|
|
// TODO [#292]: Should be moved to SDK-EXT-UI module.
|
2021-12-29 11:38:14 -08:00
|
|
|
data class WalletSnapshot(
|
|
|
|
val status: Synchronizer.Status,
|
|
|
|
val processorInfo: CompactBlockProcessor.ProcessorInfo,
|
|
|
|
val orchardBalance: WalletBalance,
|
|
|
|
val saplingBalance: WalletBalance,
|
|
|
|
val transparentBalance: WalletBalance,
|
|
|
|
val pendingCount: Int
|
|
|
|
) {
|
|
|
|
// Note: the wallet is effectively empty if it cannot cover the miner's fee
|
2022-06-23 04:31:16 -07:00
|
|
|
val hasFunds = saplingBalance.available.value >
|
|
|
|
(ZcashSdk.MINERS_FEE.value.toDouble() / Zatoshi.ZATOSHI_PER_ZEC) // 0.00001
|
|
|
|
val hasSaplingBalance = saplingBalance.total.value > 0
|
2021-12-29 11:38:14 -08:00
|
|
|
|
|
|
|
val isSendEnabled: Boolean get() = status == Synchronizer.Status.SYNCED && hasFunds
|
|
|
|
}
|
|
|
|
|
2022-06-23 04:31:16 -07:00
|
|
|
fun WalletSnapshot.totalBalance() = orchardBalance.total + saplingBalance.total + transparentBalance.total
|
2021-12-29 11:38:14 -08:00
|
|
|
|
2022-06-23 04:31:16 -07:00
|
|
|
// Note that considering both to be spendable is subject to change.
|
|
|
|
// The user experience could be confusing, and in the future we might prefer to ask users
|
|
|
|
// to transfer their balance to the latest balance type to make it spendable.
|
|
|
|
fun WalletSnapshot.spendableBalance() = orchardBalance.available + saplingBalance.available
|