secant-android-wallet/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/home/AndroidHome.kt

97 lines
3.4 KiB
Kotlin
Raw Normal View History

2022-06-22 02:48:19 -07:00
@file:Suppress("ktlint:filename")
2022-06-13 09:47:22 -07:00
package co.electriccoin.zcash.ui.screen.home
import androidx.activity.ComponentActivity
import androidx.activity.viewModels
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.lifecycle.compose.collectAsStateWithLifecycle
2022-06-13 09:47:22 -07:00
import co.electriccoin.zcash.spackle.EmulatorWtfUtil
import co.electriccoin.zcash.spackle.FirebaseTestLabUtil
import co.electriccoin.zcash.ui.BuildConfig
import co.electriccoin.zcash.ui.MainActivity
2023-02-20 10:46:23 -08:00
import co.electriccoin.zcash.ui.configuration.ConfigurationEntries
import co.electriccoin.zcash.ui.configuration.RemoteConfig
2022-06-13 09:47:22 -07:00
import co.electriccoin.zcash.ui.screen.home.view.Home
[#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.screen.home.viewmodel.CheckUpdateViewModel
2022-06-13 09:47:22 -07:00
import co.electriccoin.zcash.ui.screen.home.viewmodel.WalletViewModel
import co.electriccoin.zcash.ui.screen.settings.viewmodel.SettingsViewModel
[#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.screen.update.AppUpdateCheckerImp
import co.electriccoin.zcash.ui.screen.update.model.UpdateState
2022-06-13 09:47:22 -07:00
@Composable
internal fun MainActivity.WrapHome(
goScan: () -> Unit,
goProfile: () -> Unit,
goSend: () -> Unit,
goRequest: () -> Unit
) {
WrapHome(
this,
goScan = goScan,
goProfile = goProfile,
goSend = goSend,
goRequest = goRequest
)
}
@Composable
internal fun WrapHome(
activity: ComponentActivity,
goScan: () -> Unit,
goProfile: () -> Unit,
goSend: () -> Unit,
goRequest: () -> Unit
) {
[#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
// we want to show information about app update, if available
val checkUpdateViewModel by activity.viewModels<CheckUpdateViewModel> {
CheckUpdateViewModel.CheckUpdateViewModelFactory(
activity.application,
AppUpdateCheckerImp.new()
)
}
val updateAvailable = checkUpdateViewModel.updateInfo.collectAsStateWithLifecycle().value.let {
[#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
it?.appUpdateInfo != null && it.state == UpdateState.Prepared
}
2022-06-13 09:47:22 -07:00
val walletViewModel by activity.viewModels<WalletViewModel>()
val walletSnapshot = walletViewModel.walletSnapshot.collectAsStateWithLifecycle().value
val settingsViewModel by activity.viewModels<SettingsViewModel>()
val isKeepScreenOnWhileSyncing = settingsViewModel.isKeepScreenOnWhileSyncing.collectAsStateWithLifecycle().value
2022-06-13 09:47:22 -07:00
if (null == walletSnapshot) {
// Display loading indicator
} else {
val context = LocalContext.current
// We might eventually want to check the debuggable property of the manifest instead
// of relying on BuildConfig.
val isDebugMenuEnabled = BuildConfig.DEBUG &&
!FirebaseTestLabUtil.isFirebaseTestLab(context) &&
!EmulatorWtfUtil.isEmulatorWtf(context)
val transactionSnapshot = walletViewModel.transactionSnapshot.collectAsStateWithLifecycle().value
2022-06-13 09:47:22 -07:00
Home(
walletSnapshot,
isKeepScreenOnDuringSync = isKeepScreenOnWhileSyncing,
2023-02-20 10:46:23 -08:00
isRequestZecButtonEnabled = ConfigurationEntries.IS_REQUEST_ZEC_ENABLED.getValue(RemoteConfig.current),
transactionSnapshot,
2022-06-13 09:47:22 -07:00
goScan = goScan,
goRequest = goRequest,
goSend = goSend,
goProfile = goProfile,
isDebugMenuEnabled = isDebugMenuEnabled,
resetSdk = {
walletViewModel.resetSdk()
},
[#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
updateAvailable = updateAvailable
2022-06-13 09:47:22 -07:00
)
activity.reportFullyDrawn()
}
}