Skip to content

Commit

Permalink
[#944] Adopt SDK version 2.0.0 with SbS included
Browse files Browse the repository at this point in the history
* [#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
  • Loading branch information
HonzaR authored Sep 27, 2023
1 parent c61645a commit 9ec0de1
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 19 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ private val lazy = LazyWithArgument<Context, WalletCoordinator> {
emitAll(EncryptedPreferenceKeys.PERSISTABLE_WALLET.observe(encryptedPreferenceProvider))
}

WalletCoordinator(it, persistableWallet)
WalletCoordinator(
context = it,
persistableWallet = persistableWallet
)
}

fun WalletCoordinator.Companion.getInstance(context: Context) = lazy.getInstance(context)
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -22,7 +22,6 @@ object WalletSnapshotFixture {
fun new(
status: Synchronizer.Status = STATUS,
processorInfo: CompactBlockProcessor.ProcessorInfo = CompactBlockProcessor.ProcessorInfo(
null,
null,
null,
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -188,8 +189,12 @@ class WalletViewModel(application: Application) : AndroidViewModel(application)
val application = getApplication<Application>()

viewModelScope.launch {
val newWallet = PersistableWallet.new(application, ZcashNetwork.fromResources(application))
persistExistingWallet(newWallet)
val newWallet = PersistableWallet.new(
application,
ZcashNetwork.fromResources(application),
WalletInitMode.NewWallet
)
persistWallet(newWallet)
}
}

Expand All @@ -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<Application>()

viewModelScope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -133,7 +134,8 @@ internal fun persistExistingWalletWithSeedPhrase(
val restoredWallet = PersistableWallet(
network,
birthday,
seedPhrase
seedPhrase,
WalletInitMode.RestoreWallet
)
walletViewModel.persistExistingWallet(restoredWallet)
}
1 change: 1 addition & 0 deletions ui-lib/src/main/res/ui/history/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
<string name="history_item_sending">Sending</string>
<string name="history_item_receiving">Receiving</string>
<string name="history_item_expired">Expired</string>
<string name="history_item_date_not_available">Date not available</string>

</resources>

0 comments on commit 9ec0de1

Please sign in to comment.