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
|
|
|
|
import cash.z.ecc.android.sdk.type.WalletBalance
|
|
|
|
import cash.z.ecc.sdk.model.Zatoshi
|
|
|
|
|
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
|
|
|
|
val hasFunds = saplingBalance.availableZatoshi >
|
|
|
|
(ZcashSdk.MINERS_FEE_ZATOSHI.toDouble() / ZcashSdk.ZATOSHI_PER_ZEC) // 0.00001
|
|
|
|
val hasSaplingBalance = saplingBalance.totalZatoshi > 0
|
|
|
|
|
|
|
|
val isSendEnabled: Boolean get() = status == Synchronizer.Status.SYNCED && hasFunds
|
|
|
|
}
|
|
|
|
|
|
|
|
fun WalletSnapshot.totalBalance(): Zatoshi {
|
|
|
|
val total = (orchardBalance + saplingBalance + transparentBalance).totalZatoshi
|
|
|
|
|
|
|
|
return Zatoshi(total.coerceAtLeast(0))
|
|
|
|
}
|
2022-03-01 05:11:23 -08:00
|
|
|
|
|
|
|
fun WalletSnapshot.spendableBalance(): Zatoshi {
|
|
|
|
// 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.
|
|
|
|
val total = (orchardBalance + saplingBalance).totalZatoshi
|
|
|
|
|
|
|
|
return Zatoshi(total.coerceAtLeast(0))
|
|
|
|
}
|