Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/src/main/java/to/bitkit/data/SettingsStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import kotlinx.coroutines.flow.map
import to.bitkit.ext.enumValueOfOrNull
import to.bitkit.models.BitcoinDisplayUnit
import to.bitkit.models.PrimaryDisplay
import to.bitkit.utils.Logger
import javax.inject.Inject
import javax.inject.Singleton

Expand Down Expand Up @@ -76,6 +77,11 @@ class SettingsStore @Inject constructor(
val isBiometricEnabled: Flow<Boolean> = store.data.map { it[IS_BIOMETRIC_ENABLED] == true }
suspend fun setIsBiometricEnabled(value: Boolean) { store.edit { it[IS_BIOMETRIC_ENABLED] = value } }

suspend fun wipe() {
store.edit { it.clear() }
Logger.info("Deleted all user settings data.")
}

private companion object {
private val PRIMARY_DISPLAY_UNIT_KEY = stringPreferencesKey("primary_display_unit")
private val BTC_DISPLAY_UNIT_KEY = stringPreferencesKey("btc_display_unit")
Expand Down
44 changes: 31 additions & 13 deletions app/src/main/java/to/bitkit/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package to.bitkit.ui
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
Expand All @@ -16,6 +19,7 @@ import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import kotlinx.serialization.Serializable
import to.bitkit.ui.components.AuthCheckView
import to.bitkit.ui.components.ForgotPinSheet
import to.bitkit.ui.components.ToastOverlay
import to.bitkit.ui.onboarding.CreateWalletWithPassphraseScreen
import to.bitkit.ui.onboarding.IntroScreen
Expand Down Expand Up @@ -97,11 +101,12 @@ class MainActivity : FragmentActivity() {
onCreateClick = {
scope.launch {
try {
appViewModel.resetIsAuthenticatedState()
walletViewModel.setInitNodeLifecycleState()
walletViewModel.createWallet(bip39Passphrase = null)
walletViewModel.setWalletExistsState()
appViewModel.setShowEmptyState(true)
} catch (e: Exception) {
} catch (e: Throwable) {
appViewModel.toast(e)
}
}
Expand Down Expand Up @@ -135,12 +140,13 @@ class MainActivity : FragmentActivity() {
onRestoreClick = { mnemonic, passphrase ->
scope.launch {
try {
appViewModel.resetIsAuthenticatedState()
walletViewModel.setInitNodeLifecycleState()
walletViewModel.isRestoringWallet = true
walletViewModel.restoreWallet(mnemonic, passphrase)
walletViewModel.setWalletExistsState()
appViewModel.setShowEmptyState(false)
} catch (e: Exception) {
} catch (e: Throwable) {
appViewModel.toast(e)
}
}
Expand All @@ -158,11 +164,12 @@ class MainActivity : FragmentActivity() {
onCreateClick = { passphrase ->
scope.launch {
try {
appViewModel.resetIsAuthenticatedState()
walletViewModel.setInitNodeLifecycleState()
walletViewModel.createWallet(bip39Passphrase = passphrase)
walletViewModel.setWalletExistsState()
appViewModel.setShowEmptyState(true)
} catch (e: Exception) {
} catch (e: Throwable) {
appViewModel.toast(e)
}
}
Expand All @@ -171,22 +178,33 @@ class MainActivity : FragmentActivity() {
}
}
} else {
val isAuthenticated by appViewModel.isAuthenticated.collectAsStateWithLifecycle()
ContentView(
appViewModel = appViewModel,
walletViewModel = walletViewModel,
blocktankViewModel = blocktankViewModel,
currencyViewModel = currencyViewModel,
activityListViewModel = activityListViewModel,
transferViewModel = transferViewModel,
)

if (!isAuthenticated) {
val isAuthenticated by appViewModel.isAuthenticated.collectAsStateWithLifecycle()
AnimatedVisibility(
visible = !isAuthenticated,
enter = fadeIn(),
exit = fadeOut(),
) {
AuthCheckView(
showLogoOnPin = true,
appViewModel = appViewModel,
onSuccess = { appViewModel.setIsAuthenticated(true) },
)
} else {
ContentView(
appViewModel = appViewModel,
walletViewModel = walletViewModel,
blocktankViewModel = blocktankViewModel,
currencyViewModel = currencyViewModel,
activityListViewModel = activityListViewModel,
transferViewModel = transferViewModel,
}

val showForgotPinSheet by appViewModel.showForgotPinSheet.collectAsStateWithLifecycle()
if (showForgotPinSheet) {
ForgotPinSheet(
onDismiss = { appViewModel.setShowForgotPin(false) },
onResetClick = { walletViewModel.wipeStorage() },
)
}
}
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/to/bitkit/ui/components/AuthCheckView.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package to.bitkit.ui.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
Expand Down Expand Up @@ -29,6 +30,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import to.bitkit.R
import to.bitkit.env.Env
import to.bitkit.ui.scaffold.AppTopBar
import to.bitkit.ui.shared.util.blockPointerInputPassthrough
import to.bitkit.ui.shared.util.clickableAlpha
import to.bitkit.ui.theme.AppThemeSurface
import to.bitkit.ui.theme.Colors
Expand Down Expand Up @@ -58,7 +60,7 @@ fun AuthCheckView(
validatePin = appViewModel::validatePin,
onSuccess = onSuccess,
onBack = onBack,
onClickForgotPin = { appViewModel.toast(Exception("TODO: Forgot PIN")) },
onClickForgotPin = { appViewModel.setShowForgotPin(true) },
)
}

Expand All @@ -85,6 +87,8 @@ private fun AuthCheckViewContent(
contentAlignment = Alignment.Center,
modifier = Modifier
.fillMaxSize()
.background(Colors.Black)
.blockPointerInputPassthrough()
.navigationBarsPadding()
) {
if ((showBio && isBiometrySupported && !requirePin) || requireBiometrics) {
Expand Down
113 changes: 113 additions & 0 deletions app/src/main/java/to/bitkit/ui/components/ForgotPinSheet.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package to.bitkit.ui.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material3.BottomSheetDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import to.bitkit.R
import to.bitkit.ui.scaffold.SheetTopBar
import to.bitkit.ui.shared.util.gradientBackground
import to.bitkit.ui.theme.AppShapes
import to.bitkit.ui.theme.AppThemeSurface
import to.bitkit.ui.theme.Colors
import to.bitkit.ui.theme.ModalSheetTopPadding

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ForgotPinSheet(
onDismiss: () -> Unit,
onResetClick: () -> Unit,
) {
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)

ModalBottomSheet(
onDismissRequest = onDismiss,
sheetState = sheetState,
shape = AppShapes.sheet,
containerColor = Colors.Black,
dragHandle = {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.fillMaxWidth()
.background(color = Colors.Gray6)
) {
BottomSheetDefaults.DragHandle()
}
},
modifier = Modifier
.fillMaxSize()
.padding(top = ModalSheetTopPadding)
) {
ForgotPinSheetContent(
onResetClick = {
onDismiss()
onResetClick()
},
)
}
}

@Composable
private fun ForgotPinSheetContent(
onResetClick: () -> Unit,
modifier: Modifier = Modifier,
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = modifier
.fillMaxWidth()
.gradientBackground()
.padding(horizontal = 16.dp)
) {
SheetTopBar(stringResource(R.string.security__pin_forgot_title))
Spacer(modifier = Modifier.height(16.dp))

BodyM(
text = stringResource(R.string.security__pin_forgot_text),
color = Colors.White64,
)

Spacer(modifier = Modifier.weight(1f))
Image(
painter = painterResource(R.drawable.restore),
contentDescription = null,
modifier = Modifier.width(256.dp)
)
Spacer(modifier = Modifier.weight(1f))

PrimaryButton(
text = stringResource(R.string.security__pin_forgot_reset),
onClick = onResetClick,
)

Spacer(modifier = Modifier.height(16.dp))
}
}

@Preview(showBackground = true)
@Composable
private fun Preview() {
AppThemeSurface {
ForgotPinSheetContent(
onResetClick = {},
)
}
}
9 changes: 4 additions & 5 deletions app/src/main/java/to/bitkit/ui/screens/SplashScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import to.bitkit.R
import to.bitkit.ui.shared.util.blockPointerInputPassthrough
import to.bitkit.ui.theme.AppThemeSurface
import to.bitkit.ui.theme.Colors

Expand All @@ -32,16 +32,15 @@ fun SplashScreen(isVisible: Boolean = true) {
)
) {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.fillMaxSize()
.background(Colors.Brand),
contentAlignment = Alignment.Center,
.background(Colors.Brand)
.blockPointerInputPassthrough()
) {
Image(
painter = painterResource(id = R.drawable.splash_logo),
contentDescription = null,
modifier = Modifier
.wrapContentSize()
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import to.bitkit.ui.scaffold.SheetTopBar
import to.bitkit.ui.shared.util.gradientBackground
import to.bitkit.ui.theme.AppShapes
import to.bitkit.ui.theme.AppThemeSurface
import to.bitkit.ui.theme.ModalSheetTopPadding
import to.bitkit.ui.utils.localizedRandom
import to.bitkit.viewmodels.AppViewModel

Expand Down Expand Up @@ -76,7 +77,7 @@ fun NewTransactionSheet(
modifier = Modifier
.fillMaxSize()
.gradientBackground()
.padding(top = 100.dp)
.padding(top = ModalSheetTopPadding)
) {
NewTransactionSheetView(
details = details,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fun ChangePinScreen(
},
onBackClick = { navController.popBackStack() },
onCloseClick = { navController.navigateToHome() },
onClickForgotPin = { app.toast(Exception("TODO: Forgot PIN")) },
onClickForgotPin = { app.setShowForgotPin(true) },
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ private fun PinResultContent(
) {
SheetTopBar(stringResource(R.string.security__success_title))

Spacer(modifier = Modifier.height(16.dp))

Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/to/bitkit/ui/shared/util/Modifiers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.pointer.pointerInput
import to.bitkit.ui.theme.Colors

/**
Expand Down Expand Up @@ -65,3 +66,13 @@ fun Modifier.gradientBackground(): Modifier {
)
)
}

fun Modifier.blockPointerInputPassthrough(): Modifier {
return this.pointerInput(Unit) {
awaitPointerEventScope {
while (true) {
awaitPointerEvent()
}
}
}
}
3 changes: 3 additions & 0 deletions app/src/main/java/to/bitkit/ui/theme/Defaults.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.Stable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

@Immutable
object AppTextFieldDefaults {
Expand Down Expand Up @@ -112,3 +113,5 @@ object AppSwitchDefaults {
uncheckedIconColor = Colors.Gray4,
)
}

val ModalSheetTopPadding = 125.dp
2 changes: 1 addition & 1 deletion app/src/main/java/to/bitkit/ui/theme/Shape.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ val Shapes = Shapes(
)

object AppShapes {
val sheet = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp)
val sheet = RoundedCornerShape(topStart = 32.dp, topEnd = 32.dp)
val small = RoundedCornerShape(8.dp)
val smallButton = small
val smallInput = small
Expand Down
Loading