secant-android-wallet/ui-lib/src/main/java/co/electriccoin/zcash/ui/MainActivity.kt

430 lines
15 KiB
Kotlin
Raw Normal View History

package co.electriccoin.zcash.ui
2022-05-11 13:24:52 -07:00
import android.annotation.SuppressLint
2021-12-06 12:31:39 -08:00
import android.content.Context
2022-02-17 05:08:06 -08:00
import android.content.Intent
import android.os.Bundle
2021-12-03 05:19:15 -08:00
import android.os.SystemClock
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
2021-12-03 05:19:15 -08:00
import androidx.annotation.VisibleForTesting
2021-12-09 12:18:18 -08:00
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
2021-12-09 12:18:18 -08:00
import androidx.compose.ui.Modifier
2021-12-03 05:19:15 -08:00
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
2021-12-06 12:31:39 -08:00
import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavHostController
import androidx.navigation.NavOptionsBuilder
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
2022-02-17 05:08:06 -08:00
import cash.z.ecc.sdk.model.ZecRequest
import cash.z.ecc.sdk.send
[#310] [Scaffold] Progress Status Circular Bar * [#310] [Scaffold] Progress Status Circular Bar - Added Z to Home ZECs balance - Added USD balance text to Home - Prepared Text extension functions for both - Provided Zatoshi to USD conversion methods + filed related SDK conversion issue * Update Home screen UI with progress bars - Implemented scaffolding UI of progress bars - Added related texts to strings * Update Home screen UI with progress bars - Connected some of the implemented UI elements to SDK values - Added app update information to Home screen - Update WalletSnapshot with progress field * Update Home screen UI with progress bars - Capturing and handling errors from SDK Synchronizer. - Added related error strings. - Simplified Home screen UI. * Zboto font added. Load it in runtime. Import to Typography. * Updated ZEC sign icon. * Draw ZEC balance with Zboto font * Simplify Home screen balances assigning * Switch to PercentDecimal progress representatiton * Support different locales while working with fiat currency * Fix bug in checking of fiat currency value * Generalize strings to provide possibility of other fiat currencies * Add fiat currency conversion states mechanism * Add TODO comment with reference to follow up SynchronizerError issue * Add WalletDisplayValues to simplify HomeView composable * Add CurrencyConversion class for connection to Price API (and convert Zatoshi to fiat currency) * Add basic HomeView tests * Add basic HomeViewIntegration test * Review changes - Used Duration API for times - Allow injecting clock into currency conversion - Moved FiatCurrencyConversionRateState to sdk-ext-ui because I suspect that we’ll consider this to be a UI object. I based this on the fact that current/stale cutoff values are arbitrary and probably should be the domain of the UI rather than the SDK. - Added some tests, although additional coverage is needed - Added fixtures for model objects * Minor code refactoring - Move UpdateInfoFixture class to fixture dir - Remove unnecessary annotation - Add common application context method to test suite - Fix Test class import - Move several WalletSnapshotFixture parameters to const fields * Add WalletDisplayValuesTest to cover the model class. * Fix import after changes merged * Use the new MonetarySeparatorsFixture in related tests * Add a few basic Zatoshi -> USD conversion tests * Turn on core lib desugaring for sdk-ext-ui-lib module * Make WalletDisplayValues a data class I think there may be some instances where this can help with recomposition * Add preference key for fiat currency This allows us to configure reading the value with observers correctly, even if we don’t allow the user to change it right now. * Delegate symbol and formatting to JVM * Add tests for Locale Co-authored-by: Carter Jernigan <git@carterjernigan.com>
2022-07-13 00:16:05 -07:00
import co.electriccoin.zcash.ui.design.compat.FontCompat
import co.electriccoin.zcash.ui.design.component.ConfigurationOverride
import co.electriccoin.zcash.ui.design.component.GradientSurface
import co.electriccoin.zcash.ui.design.component.Override
import co.electriccoin.zcash.ui.design.theme.ZcashTheme
import co.electriccoin.zcash.ui.screen.about.WrapAbout
2022-06-22 02:48:19 -07:00
import co.electriccoin.zcash.ui.screen.address.view.WalletAddresses
import co.electriccoin.zcash.ui.screen.backup.WrapBackup
import co.electriccoin.zcash.ui.screen.backup.copyToClipboard
2022-06-13 09:47:22 -07:00
import co.electriccoin.zcash.ui.screen.home.WrapHome
import co.electriccoin.zcash.ui.screen.home.model.spendableBalance
import co.electriccoin.zcash.ui.screen.home.viewmodel.CheckUpdateViewModel
import co.electriccoin.zcash.ui.screen.home.viewmodel.SecretState
import co.electriccoin.zcash.ui.screen.home.viewmodel.WalletViewModel
import co.electriccoin.zcash.ui.screen.onboarding.WrapOnboarding
import co.electriccoin.zcash.ui.screen.profile.WrapProfile
import co.electriccoin.zcash.ui.screen.request.view.Request
import co.electriccoin.zcash.ui.screen.scan.WrapScan
import co.electriccoin.zcash.ui.screen.seed.view.Seed
import co.electriccoin.zcash.ui.screen.send.view.Send
2022-06-13 09:47:22 -07:00
import co.electriccoin.zcash.ui.screen.settings.WrapSettings
import co.electriccoin.zcash.ui.screen.support.WrapSupport
import co.electriccoin.zcash.ui.screen.update.AppUpdateCheckerImp
import co.electriccoin.zcash.ui.screen.update.WrapUpdate
import co.electriccoin.zcash.ui.screen.update.model.UpdateState
import kotlinx.coroutines.flow.MutableStateFlow
2021-12-06 12:31:39 -08:00
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
2021-12-03 05:19:15 -08:00
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds
@Suppress("TooManyFunctions")
class MainActivity : ComponentActivity() {
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
val walletViewModel by viewModels<WalletViewModel>()
// TODO [#382]: https://github.com/zcash/secant-android-wallet/issues/382
// TODO [#403]: https://github.com/zcash/secant-android-wallet/issues/403
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
val checkUpdateViewModel by viewModels<CheckUpdateViewModel> {
CheckUpdateViewModel.CheckUpdateViewModelFactory(
application,
AppUpdateCheckerImp.new()
)
}
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
lateinit var navControllerForTesting: NavHostController
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
val configurationOverrideFlow = MutableStateFlow<ConfigurationOverride?>(null)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
2021-12-03 05:19:15 -08:00
setupSplashScreen()
[#310] [Scaffold] Progress Status Circular Bar * [#310] [Scaffold] Progress Status Circular Bar - Added Z to Home ZECs balance - Added USD balance text to Home - Prepared Text extension functions for both - Provided Zatoshi to USD conversion methods + filed related SDK conversion issue * Update Home screen UI with progress bars - Implemented scaffolding UI of progress bars - Added related texts to strings * Update Home screen UI with progress bars - Connected some of the implemented UI elements to SDK values - Added app update information to Home screen - Update WalletSnapshot with progress field * Update Home screen UI with progress bars - Capturing and handling errors from SDK Synchronizer. - Added related error strings. - Simplified Home screen UI. * Zboto font added. Load it in runtime. Import to Typography. * Updated ZEC sign icon. * Draw ZEC balance with Zboto font * Simplify Home screen balances assigning * Switch to PercentDecimal progress representatiton * Support different locales while working with fiat currency * Fix bug in checking of fiat currency value * Generalize strings to provide possibility of other fiat currencies * Add fiat currency conversion states mechanism * Add TODO comment with reference to follow up SynchronizerError issue * Add WalletDisplayValues to simplify HomeView composable * Add CurrencyConversion class for connection to Price API (and convert Zatoshi to fiat currency) * Add basic HomeView tests * Add basic HomeViewIntegration test * Review changes - Used Duration API for times - Allow injecting clock into currency conversion - Moved FiatCurrencyConversionRateState to sdk-ext-ui because I suspect that we’ll consider this to be a UI object. I based this on the fact that current/stale cutoff values are arbitrary and probably should be the domain of the UI rather than the SDK. - Added some tests, although additional coverage is needed - Added fixtures for model objects * Minor code refactoring - Move UpdateInfoFixture class to fixture dir - Remove unnecessary annotation - Add common application context method to test suite - Fix Test class import - Move several WalletSnapshotFixture parameters to const fields * Add WalletDisplayValuesTest to cover the model class. * Fix import after changes merged * Use the new MonetarySeparatorsFixture in related tests * Add a few basic Zatoshi -> USD conversion tests * Turn on core lib desugaring for sdk-ext-ui-lib module * Make WalletDisplayValues a data class I think there may be some instances where this can help with recomposition * Add preference key for fiat currency This allows us to configure reading the value with observers correctly, even if we don’t allow the user to change it right now. * Delegate symbol and formatting to JVM * Add tests for Locale Co-authored-by: Carter Jernigan <git@carterjernigan.com>
2022-07-13 00:16:05 -07:00
if (FontCompat.isFontPrefetchNeeded()) {
lifecycleScope.launch {
FontCompat.prefetchFontsLegacy(applicationContext)
setupUiContent()
}
} else {
setupUiContent()
}
}
2021-12-03 05:19:15 -08:00
private fun setupSplashScreen() {
2021-12-09 12:18:18 -08:00
val splashScreen = installSplashScreen()
val start = SystemClock.elapsedRealtime().milliseconds
splashScreen.setKeepOnScreenCondition {
2021-12-09 12:18:18 -08:00
if (SPLASH_SCREEN_DELAY > Duration.ZERO) {
val now = SystemClock.elapsedRealtime().milliseconds
2021-12-03 05:19:15 -08:00
2021-12-09 12:18:18 -08:00
// This delay is for debug purposes only; do not enable for production usage.
if (now - start < SPLASH_SCREEN_DELAY) {
return@setKeepOnScreenCondition true
2021-12-09 12:18:18 -08:00
}
2021-12-03 05:19:15 -08:00
}
2021-12-09 12:18:18 -08:00
SecretState.Loading == walletViewModel.secretState.value
2021-12-03 05:19:15 -08:00
}
}
2021-12-06 12:31:39 -08:00
private fun setupUiContent() {
setContent {
Override(configurationOverrideFlow) {
ZcashTheme {
GradientSurface(
Modifier
.fillMaxWidth()
.fillMaxHeight()
) {
when (val secretState = walletViewModel.secretState.collectAsState().value) {
SecretState.Loading -> {
// For now, keep displaying splash screen using condition above.
// In the future, we might consider displaying something different here.
}
SecretState.None -> {
WrapOnboarding()
}
is SecretState.NeedsBackup -> WrapBackup(
secretState.persistableWallet,
onBackupComplete = { walletViewModel.persistBackupComplete() }
)
is SecretState.Ready -> Navigation()
2021-12-09 12:18:18 -08:00
}
2021-12-06 12:31:39 -08:00
}
}
}
}
// Force collection to improve performance; sync can start happening while
// the user is going through the backup flow. Don't use eager collection in the view model,
// so that the collection is still tied to UI lifecycle.
lifecycleScope.launch {
walletViewModel.synchronizer.collect {
}
}
2021-12-06 12:31:39 -08:00
}
@Suppress("LongMethod")
2021-12-03 05:19:15 -08:00
@Composable
@SuppressWarnings("LongMethod")
private fun Navigation() {
val navController = rememberNavController().also {
2022-05-11 13:24:52 -07:00
// This suppress is necessary, as this is how we set up the nav controller for tests.
@SuppressLint("RestrictedApi")
navControllerForTesting = it
}
NavHost(navController = navController, startDestination = NAV_HOME) {
composable(NAV_HOME) {
WrapHome(
goScan = { navController.navigateJustOnce(NAV_SCAN) },
goProfile = { navController.navigateJustOnce(NAV_PROFILE) },
goSend = { navController.navigateJustOnce(NAV_SEND) },
goRequest = { navController.navigateJustOnce(NAV_REQUEST) }
)
2022-06-13 09:47:22 -07:00
WrapCheckForUpdate()
}
composable(NAV_PROFILE) {
2022-01-13 09:49:08 -08:00
WrapProfile(
onBack = { navController.popBackStackJustOnce(NAV_PROFILE) },
onAddressDetails = { navController.navigateJustOnce(NAV_WALLET_ADDRESS_DETAILS) },
2022-01-13 09:49:08 -08:00
onAddressBook = { },
onSettings = { navController.navigateJustOnce(NAV_SETTINGS) },
onCoinholderVote = { },
onSupport = { navController.navigateJustOnce(NAV_SUPPORT) },
onAbout = { navController.navigateJustOnce(NAV_ABOUT) }
)
2022-01-13 09:49:08 -08:00
}
composable(NAV_WALLET_ADDRESS_DETAILS) {
WrapWalletAddresses(
goBack = {
navController.popBackStackJustOnce(NAV_WALLET_ADDRESS_DETAILS)
}
)
}
composable(NAV_SETTINGS) {
WrapSettings(
goBack = {
navController.popBackStackJustOnce(NAV_SETTINGS)
},
goWalletBackup = {
navController.navigateJustOnce(NAV_SEED)
}
)
}
composable(NAV_SEED) {
WrapSeed(
goBack = {
navController.popBackStackJustOnce(NAV_SEED)
}
)
}
2022-02-17 05:08:06 -08:00
composable(NAV_REQUEST) {
WrapRequest(goBack = { navController.popBackStackJustOnce(NAV_REQUEST) })
2022-02-17 05:08:06 -08:00
}
composable(NAV_SEND) {
WrapSend(goBack = { navController.popBackStackJustOnce(NAV_SEND) })
}
composable(NAV_SUPPORT) {
// Pop back stack won't be right if we deep link into support
WrapSupport(goBack = { navController.popBackStackJustOnce(NAV_SUPPORT) })
}
composable(NAV_ABOUT) {
WrapAbout(goBack = { navController.popBackStackJustOnce(NAV_ABOUT) })
}
composable(NAV_SCAN) {
[#313] scan qr screen functional * [#312] [#309] Scaffold Scan QR Screen - Screen scaffolding. - Model classes. - Screen states handling. - Needed dependencies added. - Camera permission handling. Redirect to Settings. - Added SettingsUtilTest class. - Added view classes tests. - Renamed tag class in update package. - Fix the scan frame size while changing the screen orientation. - Use local variable for cameraProvider. - Use UUID for source of randomness. - Eliminate blocking call for camera. - Fix preview name. - Remove Google Guava dependency. - Suppress Lint warning. - Improved calculation of the camera frame size. Moved it into Constraint layout. - Added custom image analyser class. - Implemented logic for the QR scan screen while QR code is found. - Manual tests added. - New module with integration tests for QR Scan screen. Added 3 integration and 4 view tests. - Simplify QR Scan screen view basic tests. - Switched from pure compose permission handling to Accompanist way of handling CAMERA permission. - Added validation of Zcash wallet address from QR scanning result. - Fix the integration tests for the CI WTF emulator runs. - Add comment on RTL test result. - Improve waitForDeviceIdle() method. Use it on the other test too. - Change the integration test module main manifest package name. - Debounce scans. - Improve thread safety of scan collection. - Added instructions on how to set up an emulator in manual tests. - Replace compose collectAsState() with coroutine launch(). - Add sample() to get rid of several callback events at the same time. - Stop updating the scanState when it's already in Scanning state. - Fix condition on navigation. - Remove validateJob check. - Speed up the integration test - Wrap ImageAnalysis.qrCodeFlow to remember. - Auto-close the camera image when we're done with it in all cases. - Update minimal SDK version to 24 for WTF emulators. - Update Architecture documentation. - Removed extra blank space in ui-design module definition. - Add ui-integration-test-lib. - Update Mermaid diagram with newly added module. - Move UI modules into one wrap in the diagram. - Move sdk-ext-lib and sdk-ext-ui under the same modules section. - Update camera dependencies. Co-authored-by: Carter Jernigan <git@carterjernigan.com>
2022-06-02 04:35:51 -07:00
WrapScanValidator(
onScanValid = {
// TODO [#449] https://github.com/zcash/secant-android-wallet/issues/449
navController.navigateJustOnce(NAV_SEND) {
popUpTo(NAV_HOME) { inclusive = false }
[#313] scan qr screen functional * [#312] [#309] Scaffold Scan QR Screen - Screen scaffolding. - Model classes. - Screen states handling. - Needed dependencies added. - Camera permission handling. Redirect to Settings. - Added SettingsUtilTest class. - Added view classes tests. - Renamed tag class in update package. - Fix the scan frame size while changing the screen orientation. - Use local variable for cameraProvider. - Use UUID for source of randomness. - Eliminate blocking call for camera. - Fix preview name. - Remove Google Guava dependency. - Suppress Lint warning. - Improved calculation of the camera frame size. Moved it into Constraint layout. - Added custom image analyser class. - Implemented logic for the QR scan screen while QR code is found. - Manual tests added. - New module with integration tests for QR Scan screen. Added 3 integration and 4 view tests. - Simplify QR Scan screen view basic tests. - Switched from pure compose permission handling to Accompanist way of handling CAMERA permission. - Added validation of Zcash wallet address from QR scanning result. - Fix the integration tests for the CI WTF emulator runs. - Add comment on RTL test result. - Improve waitForDeviceIdle() method. Use it on the other test too. - Change the integration test module main manifest package name. - Debounce scans. - Improve thread safety of scan collection. - Added instructions on how to set up an emulator in manual tests. - Replace compose collectAsState() with coroutine launch(). - Add sample() to get rid of several callback events at the same time. - Stop updating the scanState when it's already in Scanning state. - Fix condition on navigation. - Remove validateJob check. - Speed up the integration test - Wrap ImageAnalysis.qrCodeFlow to remember. - Auto-close the camera image when we're done with it in all cases. - Update minimal SDK version to 24 for WTF emulators. - Update Architecture documentation. - Removed extra blank space in ui-design module definition. - Add ui-integration-test-lib. - Update Mermaid diagram with newly added module. - Move UI modules into one wrap in the diagram. - Move sdk-ext-lib and sdk-ext-ui under the same modules section. - Update camera dependencies. Co-authored-by: Carter Jernigan <git@carterjernigan.com>
2022-06-02 04:35:51 -07:00
}
},
goBack = { navController.popBackStackJustOnce(NAV_SCAN) }
[#313] scan qr screen functional * [#312] [#309] Scaffold Scan QR Screen - Screen scaffolding. - Model classes. - Screen states handling. - Needed dependencies added. - Camera permission handling. Redirect to Settings. - Added SettingsUtilTest class. - Added view classes tests. - Renamed tag class in update package. - Fix the scan frame size while changing the screen orientation. - Use local variable for cameraProvider. - Use UUID for source of randomness. - Eliminate blocking call for camera. - Fix preview name. - Remove Google Guava dependency. - Suppress Lint warning. - Improved calculation of the camera frame size. Moved it into Constraint layout. - Added custom image analyser class. - Implemented logic for the QR scan screen while QR code is found. - Manual tests added. - New module with integration tests for QR Scan screen. Added 3 integration and 4 view tests. - Simplify QR Scan screen view basic tests. - Switched from pure compose permission handling to Accompanist way of handling CAMERA permission. - Added validation of Zcash wallet address from QR scanning result. - Fix the integration tests for the CI WTF emulator runs. - Add comment on RTL test result. - Improve waitForDeviceIdle() method. Use it on the other test too. - Change the integration test module main manifest package name. - Debounce scans. - Improve thread safety of scan collection. - Added instructions on how to set up an emulator in manual tests. - Replace compose collectAsState() with coroutine launch(). - Add sample() to get rid of several callback events at the same time. - Stop updating the scanState when it's already in Scanning state. - Fix condition on navigation. - Remove validateJob check. - Speed up the integration test - Wrap ImageAnalysis.qrCodeFlow to remember. - Auto-close the camera image when we're done with it in all cases. - Update minimal SDK version to 24 for WTF emulators. - Update Architecture documentation. - Removed extra blank space in ui-design module definition. - Add ui-integration-test-lib. - Update Mermaid diagram with newly added module. - Move UI modules into one wrap in the diagram. - Move sdk-ext-lib and sdk-ext-ui under the same modules section. - Update camera dependencies. Co-authored-by: Carter Jernigan <git@carterjernigan.com>
2022-06-02 04:35:51 -07:00
)
}
}
}
[#313] scan qr screen functional * [#312] [#309] Scaffold Scan QR Screen - Screen scaffolding. - Model classes. - Screen states handling. - Needed dependencies added. - Camera permission handling. Redirect to Settings. - Added SettingsUtilTest class. - Added view classes tests. - Renamed tag class in update package. - Fix the scan frame size while changing the screen orientation. - Use local variable for cameraProvider. - Use UUID for source of randomness. - Eliminate blocking call for camera. - Fix preview name. - Remove Google Guava dependency. - Suppress Lint warning. - Improved calculation of the camera frame size. Moved it into Constraint layout. - Added custom image analyser class. - Implemented logic for the QR scan screen while QR code is found. - Manual tests added. - New module with integration tests for QR Scan screen. Added 3 integration and 4 view tests. - Simplify QR Scan screen view basic tests. - Switched from pure compose permission handling to Accompanist way of handling CAMERA permission. - Added validation of Zcash wallet address from QR scanning result. - Fix the integration tests for the CI WTF emulator runs. - Add comment on RTL test result. - Improve waitForDeviceIdle() method. Use it on the other test too. - Change the integration test module main manifest package name. - Debounce scans. - Improve thread safety of scan collection. - Added instructions on how to set up an emulator in manual tests. - Replace compose collectAsState() with coroutine launch(). - Add sample() to get rid of several callback events at the same time. - Stop updating the scanState when it's already in Scanning state. - Fix condition on navigation. - Remove validateJob check. - Speed up the integration test - Wrap ImageAnalysis.qrCodeFlow to remember. - Auto-close the camera image when we're done with it in all cases. - Update minimal SDK version to 24 for WTF emulators. - Update Architecture documentation. - Removed extra blank space in ui-design module definition. - Add ui-integration-test-lib. - Update Mermaid diagram with newly added module. - Move UI modules into one wrap in the diagram. - Move sdk-ext-lib and sdk-ext-ui under the same modules section. - Update camera dependencies. Co-authored-by: Carter Jernigan <git@carterjernigan.com>
2022-06-02 04:35:51 -07:00
@Composable
private fun WrapScanValidator(
onScanValid: (address: String) -> Unit,
goBack: () -> Unit
) {
val synchronizer = walletViewModel.synchronizer.collectAsState().value
if (synchronizer == null) {
// Display loading indicator
} else {
WrapScan(
onScanDone = { result ->
lifecycleScope.launch {
val isAddressValid = !synchronizer.validateAddress(result).isNotValid
if (isAddressValid) {
onScanValid(result)
}
}
},
goBack = goBack
)
}
}
@Composable
private fun WrapCheckForUpdate() {
val updateInfo = checkUpdateViewModel.updateInfo.collectAsState().value
updateInfo?.let {
if (it.appUpdateInfo != null && it.state == UpdateState.Prepared) {
WrapUpdate(updateInfo)
}
}
// Check for an app update asynchronously. We create an effect that matches the activity
// lifecycle. If the wrapping compose recomposes, the check shouldn't run again.
LaunchedEffect(true) {
checkUpdateViewModel.checkForAppUpdate()
}
2021-12-03 05:19:15 -08:00
}
@Composable
private fun WrapWalletAddresses(
2022-06-22 02:48:19 -07:00
goBack: () -> Unit
) {
val walletAddresses = walletViewModel.addresses.collectAsState().value
if (null == walletAddresses) {
// Display loading indicator
} else {
WalletAddresses(
walletAddresses,
goBack
)
}
}
@Composable
private fun WrapSeed(
goBack: () -> Unit
) {
val persistableWallet = run {
val secretState = walletViewModel.secretState.collectAsState().value
if (secretState is SecretState.Ready) {
secretState.persistableWallet
} else {
null
}
}
val synchronizer = walletViewModel.synchronizer.collectAsState().value
if (null == synchronizer || null == persistableWallet) {
// Display loading indicator
} else {
Seed(
persistableWallet = persistableWallet,
onBack = goBack,
onCopyToClipboard = {
copyToClipboard(applicationContext, persistableWallet)
}
)
}
}
2022-02-17 05:08:06 -08:00
@Composable
private fun WrapRequest(
goBack: () -> Unit
) {
val walletAddresses = walletViewModel.addresses.collectAsState().value
if (null == walletAddresses) {
// Display loading indicator
} else {
Request(
walletAddresses.unified,
goBack = goBack,
onCreateAndSend = {
val chooserIntent = Intent.createChooser(it.newShareIntent(applicationContext), null)
startActivity(chooserIntent)
goBack()
2022-06-22 02:48:19 -07:00
}
2022-02-17 05:08:06 -08:00
)
}
}
@Composable
private fun WrapSend(
goBack: () -> Unit
) {
val synchronizer = walletViewModel.synchronizer.collectAsState().value
val spendableBalance = walletViewModel.walletSnapshot.collectAsState().value?.spendableBalance()
val spendingKey = walletViewModel.spendingKey.collectAsState().value
if (null == synchronizer || null == spendableBalance || null == spendingKey) {
// Display loading indicator
} else {
Send(
mySpendableBalance = spendableBalance,
goBack = goBack,
onCreateAndSend = {
synchronizer.send(spendingKey, it)
goBack()
2022-06-22 02:48:19 -07:00
}
)
}
}
2021-12-03 05:19:15 -08:00
companion object {
@VisibleForTesting
internal val SPLASH_SCREEN_DELAY = 0.seconds
@VisibleForTesting
const val NAV_HOME = "home"
@VisibleForTesting
const val NAV_PROFILE = "profile"
@VisibleForTesting
const val NAV_WALLET_ADDRESS_DETAILS = "wallet_address_details"
@VisibleForTesting
const val NAV_SETTINGS = "settings"
@VisibleForTesting
const val NAV_SEED = "seed"
2022-02-17 05:08:06 -08:00
@VisibleForTesting
const val NAV_REQUEST = "request"
@VisibleForTesting
const val NAV_SEND = "send"
@VisibleForTesting
const val NAV_SUPPORT = "support"
@VisibleForTesting
const val NAV_ABOUT = "about"
@VisibleForTesting
const val NAV_SCAN = "scan"
2021-12-03 05:19:15 -08:00
}
}
2021-12-06 12:31:39 -08:00
private fun ZecRequest.newShareIntent(context: Context) = runBlocking {
Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, context.getString(R.string.request_template_format, toUri()))
type = "text/plain"
}
2022-02-17 05:08:06 -08:00
}
private fun NavHostController.navigateJustOnce(
route: String,
navOptionsBuilder: (NavOptionsBuilder.() -> Unit)? = null
) {
if (currentDestination?.route == route) {
return
}
if (navOptionsBuilder != null) {
navigate(route, navOptionsBuilder)
} else {
navigate(route)
}
}
/**
* Pops up the current screen from the back stack. Parameter currentRouteToBePopped is meant to be
* set only to the current screen so we can easily debounce multiple screen popping from the back stack.
*
* @param currentRouteToBePopped current screen which should be popped up.
*/
private fun NavHostController.popBackStackJustOnce(currentRouteToBePopped: String) {
if (currentDestination?.route != currentRouteToBePopped) {
return
}
popBackStack()
}