From 9ec0de1729de6476a8b3be5d4cffe9aed4456059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Honza=20Rychnovsk=C3=BD?= Date: Wed, 27 Sep 2023 08:52:31 +0200 Subject: [PATCH] [#944] Adopt SDK version 2.0.0 with SbS included * [#944] Adopt SDK version with SbS included - This supposes to fail in the build until the proper SDK version is consumed - Tested via included builds * Adopt latest SDK changes * Adopt changed TransactionOverview API * Switch to latest v2.0.0-rc.2 * Fix transaction history test fixture * Adopt latest SDK snapshot version * Switch to latest production Zcash SDK version --- gradle.properties | 2 +- .../sdk/fixture/PersistableWalletFixture.kt | 8 ++++++-- .../zcash/ui/fixture/MockSynchronizer.kt | 4 ++-- .../TransactionHistorySyncStateFixture.kt | 6 +++--- .../zcash/global/WalletCoordinator.kt | 5 ++++- .../zcash/ui/fixture/WalletSnapshotFixture.kt | 3 +-- .../ui/screen/history/view/HistoryView.kt | 12 +++++++++--- .../ui/screen/home/model/WalletSnapshot.kt | 2 +- .../screen/home/viewmodel/WalletViewModel.kt | 18 +++++++++++++++--- .../ui/screen/onboarding/AndroidOnboarding.kt | 4 +++- .../src/main/res/ui/history/values/strings.xml | 1 + 11 files changed, 46 insertions(+), 19 deletions(-) diff --git a/gradle.properties b/gradle.properties index 707e65b7e..07909bab8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -153,7 +153,7 @@ PLAY_APP_UPDATE_VERSION=2.0.1 PLAY_APP_UPDATE_KTX_VERSION=2.0.1 ZCASH_ANDROID_WALLET_PLUGINS_VERSION=1.0.0 ZCASH_BIP39_VERSION=1.0.5 -ZCASH_SDK_VERSION=1.20.0-beta01 +ZCASH_SDK_VERSION=2.0.0 ZXING_VERSION=3.5.1 diff --git a/sdk-ext-lib/src/main/java/cash/z/ecc/sdk/fixture/PersistableWalletFixture.kt b/sdk-ext-lib/src/main/java/cash/z/ecc/sdk/fixture/PersistableWalletFixture.kt index 12038beed..453917d3a 100644 --- a/sdk-ext-lib/src/main/java/cash/z/ecc/sdk/fixture/PersistableWalletFixture.kt +++ b/sdk-ext-lib/src/main/java/cash/z/ecc/sdk/fixture/PersistableWalletFixture.kt @@ -1,5 +1,6 @@ package cash.z.ecc.sdk.fixture +import cash.z.ecc.android.sdk.WalletInitMode import cash.z.ecc.android.sdk.model.BlockHeight import cash.z.ecc.android.sdk.model.PersistableWallet import cash.z.ecc.android.sdk.model.SeedPhrase @@ -14,9 +15,12 @@ object PersistableWalletFixture { val SEED_PHRASE = SeedPhraseFixture.new() + val WALLET_INIT_MODE = WalletInitMode.ExistingWallet + fun new( network: ZcashNetwork = NETWORK, birthday: BlockHeight = BIRTHDAY, - seedPhrase: SeedPhrase = SEED_PHRASE - ) = PersistableWallet(network, birthday, seedPhrase) + seedPhrase: SeedPhrase = SEED_PHRASE, + walletInitMode: WalletInitMode = WALLET_INIT_MODE + ) = PersistableWallet(network, birthday, seedPhrase, walletInitMode) } diff --git a/ui-lib/src/androidTest/java/co/electriccoin/zcash/ui/fixture/MockSynchronizer.kt b/ui-lib/src/androidTest/java/co/electriccoin/zcash/ui/fixture/MockSynchronizer.kt index a44830c85..8273f0d98 100644 --- a/ui-lib/src/androidTest/java/co/electriccoin/zcash/ui/fixture/MockSynchronizer.kt +++ b/ui-lib/src/androidTest/java/co/electriccoin/zcash/ui/fixture/MockSynchronizer.kt @@ -2,7 +2,7 @@ package co.electriccoin.zcash.ui.fixture import cash.z.ecc.android.sdk.CloseableSynchronizer import cash.z.ecc.android.sdk.Synchronizer -import cash.z.ecc.android.sdk.block.CompactBlockProcessor +import cash.z.ecc.android.sdk.block.processor.CompactBlockProcessor import cash.z.ecc.android.sdk.model.Account import cash.z.ecc.android.sdk.model.BlockHeight import cash.z.ecc.android.sdk.model.PercentDecimal @@ -126,7 +126,7 @@ internal class MockSynchronizer : CloseableSynchronizer { error("Intentionally not implemented in ${MockSynchronizer::class.simpleName} implementation.") } - override suspend fun rewindToNearestHeight(height: BlockHeight, alsoClearBlockCache: Boolean) { + override suspend fun rewindToNearestHeight(height: BlockHeight) { error("Intentionally not implemented in ${MockSynchronizer::class.simpleName} implementation.") } diff --git a/ui-lib/src/androidTest/java/co/electriccoin/zcash/ui/screen/history/fixture/TransactionHistorySyncStateFixture.kt b/ui-lib/src/androidTest/java/co/electriccoin/zcash/ui/screen/history/fixture/TransactionHistorySyncStateFixture.kt index a216562e9..566026c47 100644 --- a/ui-lib/src/androidTest/java/co/electriccoin/zcash/ui/screen/history/fixture/TransactionHistorySyncStateFixture.kt +++ b/ui-lib/src/androidTest/java/co/electriccoin/zcash/ui/screen/history/fixture/TransactionHistorySyncStateFixture.kt @@ -8,9 +8,9 @@ import kotlinx.collections.immutable.persistentListOf internal object TransactionHistorySyncStateFixture { val TRANSACTIONS = persistentListOf( - TransactionOverviewFixture.new(id = 0), - TransactionOverviewFixture.new(id = 1), - TransactionOverviewFixture.new(id = 2) + TransactionOverviewFixture.new(), + TransactionOverviewFixture.new(), + TransactionOverviewFixture.new() ) val STATE = TransactionHistorySyncState.Syncing(TRANSACTIONS) diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/global/WalletCoordinator.kt b/ui-lib/src/main/java/co/electriccoin/zcash/global/WalletCoordinator.kt index adf925d87..576e31859 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/global/WalletCoordinator.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/global/WalletCoordinator.kt @@ -20,7 +20,10 @@ private val lazy = LazyWithArgument { emitAll(EncryptedPreferenceKeys.PERSISTABLE_WALLET.observe(encryptedPreferenceProvider)) } - WalletCoordinator(it, persistableWallet) + WalletCoordinator( + context = it, + persistableWallet = persistableWallet + ) } fun WalletCoordinator.Companion.getInstance(context: Context) = lazy.getInstance(context) diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/fixture/WalletSnapshotFixture.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/fixture/WalletSnapshotFixture.kt index 68c775001..5f573e9fd 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/ui/fixture/WalletSnapshotFixture.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/fixture/WalletSnapshotFixture.kt @@ -1,7 +1,7 @@ package co.electriccoin.zcash.ui.fixture import cash.z.ecc.android.sdk.Synchronizer -import cash.z.ecc.android.sdk.block.CompactBlockProcessor +import cash.z.ecc.android.sdk.block.processor.CompactBlockProcessor import cash.z.ecc.android.sdk.model.PercentDecimal import cash.z.ecc.android.sdk.model.WalletBalance import cash.z.ecc.android.sdk.model.Zatoshi @@ -22,7 +22,6 @@ object WalletSnapshotFixture { fun new( status: Synchronizer.Status = STATUS, processorInfo: CompactBlockProcessor.ProcessorInfo = CompactBlockProcessor.ProcessorInfo( - null, null, null, null diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/history/view/HistoryView.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/history/view/HistoryView.kt index c2927f10a..dbda737a8 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/history/view/HistoryView.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/history/view/HistoryView.kt @@ -239,9 +239,15 @@ fun HistoryItem( Spacer(modifier = Modifier.height(ZcashTheme.dimens.spacingTiny)) - // * 1000 to covert to millis - @Suppress("MagicNumber") - val dateString = dateFormat.format(transaction.blockTimeEpochSeconds.times(1000)) + val dateString = transaction.minedHeight?.let { + transaction.blockTimeEpochSeconds?.let { blockTimeEpochSeconds -> + // * 1000 to covert to millis + @Suppress("MagicNumber") + dateFormat.format(blockTimeEpochSeconds.times(1000L)) + } ?: stringResource(id = R.string.history_item_date_not_available) + } ?: stringResource(id = R.string.history_item_date_not_available) + // For now, use the same label for the above missing transaction date + Body( text = dateString, maxLines = 1, diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/home/model/WalletSnapshot.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/home/model/WalletSnapshot.kt index b5a264550..1e66ceedd 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/home/model/WalletSnapshot.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/home/model/WalletSnapshot.kt @@ -1,7 +1,7 @@ package co.electriccoin.zcash.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.block.processor.CompactBlockProcessor import cash.z.ecc.android.sdk.ext.ZcashSdk import cash.z.ecc.android.sdk.model.PercentDecimal import cash.z.ecc.android.sdk.model.WalletBalance diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/home/viewmodel/WalletViewModel.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/home/viewmodel/WalletViewModel.kt index e22035bb6..e0b82c9b3 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/home/viewmodel/WalletViewModel.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/home/viewmodel/WalletViewModel.kt @@ -7,7 +7,8 @@ import cash.z.ecc.android.bip39.Mnemonics import cash.z.ecc.android.bip39.toSeed import cash.z.ecc.android.sdk.Synchronizer import cash.z.ecc.android.sdk.WalletCoordinator -import cash.z.ecc.android.sdk.block.CompactBlockProcessor +import cash.z.ecc.android.sdk.WalletInitMode +import cash.z.ecc.android.sdk.block.processor.CompactBlockProcessor import cash.z.ecc.android.sdk.model.Account import cash.z.ecc.android.sdk.model.BlockHeight import cash.z.ecc.android.sdk.model.FiatCurrency @@ -188,8 +189,12 @@ class WalletViewModel(application: Application) : AndroidViewModel(application) val application = getApplication() viewModelScope.launch { - val newWallet = PersistableWallet.new(application, ZcashNetwork.fromResources(application)) - persistExistingWallet(newWallet) + val newWallet = PersistableWallet.new( + application, + ZcashNetwork.fromResources(application), + WalletInitMode.NewWallet + ) + persistWallet(newWallet) } } @@ -198,6 +203,13 @@ class WalletViewModel(application: Application) : AndroidViewModel(application) * to see the side effects. This would be used for a user restoring a wallet from a backup. */ fun persistExistingWallet(persistableWallet: PersistableWallet) { + persistWallet(persistableWallet) + } + + /** + * Persists a wallet asynchronously. Clients observe [secretState] to see the side effects. + */ + private fun persistWallet(persistableWallet: PersistableWallet) { val application = getApplication() viewModelScope.launch { diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/onboarding/AndroidOnboarding.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/onboarding/AndroidOnboarding.kt index 55f77061d..f936d9f61 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/onboarding/AndroidOnboarding.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/onboarding/AndroidOnboarding.kt @@ -8,6 +8,7 @@ import androidx.activity.viewModels import androidx.compose.runtime.Composable import androidx.compose.ui.platform.LocalContext import androidx.lifecycle.compose.collectAsStateWithLifecycle +import cash.z.ecc.android.sdk.WalletInitMode import cash.z.ecc.android.sdk.fixture.WalletFixture import cash.z.ecc.android.sdk.model.BlockHeight import cash.z.ecc.android.sdk.model.PersistableWallet @@ -133,7 +134,8 @@ internal fun persistExistingWalletWithSeedPhrase( val restoredWallet = PersistableWallet( network, birthday, - seedPhrase + seedPhrase, + WalletInitMode.RestoreWallet ) walletViewModel.persistExistingWallet(restoredWallet) } diff --git a/ui-lib/src/main/res/ui/history/values/strings.xml b/ui-lib/src/main/res/ui/history/values/strings.xml index 1a26c9c5e..ebe6cc9d2 100644 --- a/ui-lib/src/main/res/ui/history/values/strings.xml +++ b/ui-lib/src/main/res/ui/history/values/strings.xml @@ -9,5 +9,6 @@ Sending Receiving Expired + Date not available