-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This provides a very basic scaffold of the home screen and navigation to other child screens. Additional work needs to be done in both the SDK and this app to build all of the functionality. Specific known gaps - Displaying synchronization status to the user, pending full designs on the progress and animation behaviors - Improved APIs for listing and filtering transactions. This is the issue in the SDK Electric-Coin-Company/zcash-android-wallet-sdk#242 - Implement the UI for displaying transaction history - Display fiat currency values - Hook up buttons to navigate to other screens (scan #137, profile #145, send #134, request #135)
- Loading branch information
1 parent
dcea0ec
commit 205344c
Showing
17 changed files
with
455 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...en/onboarding/model/PercentDecimalTest.kt → ...ash/z/ecc/sdk/model/PercentDecimalTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
sdk-ext-lib/src/main/java/cash/z/ecc/sdk/model/CompactBlockProcessorExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package cash.z.ecc.sdk.model | ||
|
||
import cash.z.ecc.android.sdk.block.CompactBlockProcessor | ||
|
||
fun CompactBlockProcessor.ProcessorInfo.downloadProgress() = if (lastDownloadRange.isEmpty()) { | ||
PercentDecimal.ONE_HUNDRED_PERCENT | ||
} else { | ||
val numerator = (lastDownloadedHeight - lastDownloadRange.first + 1) | ||
.toFloat() | ||
.coerceAtLeast(PercentDecimal.MIN) | ||
val denominator = (lastDownloadRange.last - lastDownloadRange.first + 1).toFloat() | ||
|
||
val progress = (numerator / denominator).coerceAtMost(PercentDecimal.MAX) | ||
|
||
PercentDecimal(progress) | ||
} | ||
|
||
fun CompactBlockProcessor.ProcessorInfo.scanProgress() = if (lastScanRange.isEmpty()) { | ||
PercentDecimal.ONE_HUNDRED_PERCENT | ||
} else { | ||
val numerator = (lastScannedHeight - lastScanRange.first + 1).toFloat().coerceAtLeast(PercentDecimal.MIN) | ||
val demonimator = (lastScanRange.last - lastScanRange.first + 1).toFloat() | ||
|
||
val progress = (numerator / demonimator).coerceAtMost(PercentDecimal.MAX) | ||
|
||
PercentDecimal(progress) | ||
} | ||
|
||
// These are estimates | ||
@Suppress("MagicNumber") | ||
private val DOWNLOAD_WEIGHT = PercentDecimal(0.4f) | ||
private val SCAN_WEIGHT = PercentDecimal(PercentDecimal.MAX - DOWNLOAD_WEIGHT.decimal) | ||
|
||
fun CompactBlockProcessor.ProcessorInfo.totalProgress(): PercentDecimal { | ||
val downloadWeighted = DOWNLOAD_WEIGHT.decimal * (downloadProgress().decimal).coerceAtMost(PercentDecimal.MAX) | ||
val scanWeighted = SCAN_WEIGHT.decimal * (scanProgress().decimal).coerceAtMost(PercentDecimal.MAX) | ||
|
||
return PercentDecimal( | ||
downloadWeighted.coerceAtLeast(PercentDecimal.MIN) + | ||
scanWeighted.coerceAtLeast(PercentDecimal.MIN) | ||
) | ||
} |
25 changes: 25 additions & 0 deletions
25
sdk-ext-lib/src/main/java/cash/z/ecc/sdk/model/PercentDecimal.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cash.z.ecc.sdk.model | ||
|
||
/** | ||
* @param decimal A percent represented as a `Double` decimal value in the range of [0, 1]. | ||
*/ | ||
@JvmInline | ||
value class PercentDecimal(val decimal: Float) { | ||
init { | ||
require(decimal >= MIN) | ||
require(decimal <= MAX) | ||
} | ||
|
||
companion object { | ||
const val MIN = 0.0f | ||
const val MAX = 1.0f | ||
val ZERO_PERCENT = PercentDecimal(MIN) | ||
val ONE_HUNDRED_PERCENT = PercentDecimal(MAX) | ||
|
||
fun newLenient(decimal: Float) = PercentDecimal( | ||
decimal | ||
.coerceAtLeast(MIN) | ||
.coerceAtMost(MAX) | ||
) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
sdk-ext-lib/src/main/java/cash/z/ecc/sdk/model/WalletBalanceExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package cash.z.ecc.sdk.model | ||
|
||
import cash.z.ecc.android.sdk.type.WalletBalance | ||
|
||
// These go away if we update WalletBalance to expose a Zatoshi field type instead of long | ||
val WalletBalance.total get() = Zatoshi(totalZatoshi.coerceAtLeast(0)) | ||
val WalletBalance.available get() = Zatoshi(availableZatoshi.coerceAtLeast(0)) | ||
val WalletBalance.pending get() = Zatoshi(pendingZatoshi.coerceAtLeast(0)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package cash.z.ecc.sdk.model | ||
|
||
import cash.z.ecc.android.sdk.ext.convertZatoshiToZecString | ||
|
||
// Eventually, this could move into the SDK and provide a stronger API for amounts | ||
@JvmInline | ||
value class Zatoshi(val amount: Long) { | ||
init { | ||
require(amount >= 0) | ||
} | ||
|
||
override fun toString() = amount.convertZatoshiToZecString(DECIMALS, DECIMALS) | ||
|
||
companion object { | ||
private const val DECIMALS = 8 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
ui-lib/src/main/java/cash/z/ecc/ui/fixture/WalletSnapshotFixture.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package cash.z.ecc.ui.fixture | ||
|
||
import cash.z.ecc.android.sdk.Synchronizer | ||
import cash.z.ecc.android.sdk.block.CompactBlockProcessor | ||
import cash.z.ecc.android.sdk.type.WalletBalance | ||
import cash.z.ecc.ui.screen.home.model.WalletSnapshot | ||
|
||
@Suppress("MagicNumber") | ||
object WalletSnapshotFixture { | ||
// Should fill in with non-empty values for better example values in tests and UI previews | ||
@Suppress("LongParameterList") | ||
fun new( | ||
status: Synchronizer.Status = Synchronizer.Status.SYNCED, | ||
processorInfo: CompactBlockProcessor.ProcessorInfo = CompactBlockProcessor.ProcessorInfo(), | ||
orchardBalance: WalletBalance = WalletBalance(5, 2), | ||
saplingBalance: WalletBalance = WalletBalance(4, 4), | ||
transparentBalance: WalletBalance = WalletBalance(8, 1), | ||
pendingCount: Int = 0 | ||
) = WalletSnapshot(status, processorInfo, orchardBalance, saplingBalance, transparentBalance, pendingCount) | ||
} |
29 changes: 29 additions & 0 deletions
29
ui-lib/src/main/java/cash/z/ecc/ui/screen/home/model/WalletSnapshot.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package cash.z.ecc.ui.screen.home.model | ||
|
||
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 | ||
|
||
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)) | ||
} |
Oops, something went wrong.