Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions app/src/main/java/to/bitkit/ui/ContentView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ import to.bitkit.ui.sheets.BackgroundPaymentsIntroSheet
import to.bitkit.ui.sheets.BackupRoute
import to.bitkit.ui.sheets.BackupSheet
import to.bitkit.ui.sheets.ForceTransferSheet
import to.bitkit.ui.sheets.GiftSheet
import to.bitkit.ui.sheets.HighBalanceWarningSheet
import to.bitkit.ui.sheets.LnurlAuthSheet
import to.bitkit.ui.sheets.PinSheet
Expand Down Expand Up @@ -363,6 +364,7 @@ fun ContentView(
is Sheet.Backup -> BackupSheet(sheet, onDismiss = { appViewModel.hideSheet() })
is Sheet.LnurlAuth -> LnurlAuthSheet(sheet, appViewModel)
Sheet.ForceTransfer -> ForceTransferSheet(appViewModel, transferViewModel)
is Sheet.Gift -> GiftSheet(sheet, appViewModel)
is Sheet.TimedSheet -> {
when (sheet.type) {
TimedSheetType.APP_UPDATE -> {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/to/bitkit/ui/components/SheetHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ sealed interface Sheet {
data object ActivityTagSelector : Sheet
data class LnurlAuth(val domain: String, val lnurl: String, val k1: String) : Sheet
data object ForceTransfer : Sheet
data class Gift(val code: String, val amount: ULong) : Sheet

data class TimedSheet(val type: TimedSheetType) : Sheet
}
Expand Down
88 changes: 88 additions & 0 deletions app/src/main/java/to/bitkit/ui/sheets/GiftErrorSheet.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package to.bitkit.ui.sheets

import androidx.annotation.StringRes
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import to.bitkit.R
import to.bitkit.ui.components.BodyM
import to.bitkit.ui.components.PrimaryButton
import to.bitkit.ui.components.SheetSize
import to.bitkit.ui.components.VerticalSpacer
import to.bitkit.ui.scaffold.SheetTopBar
import to.bitkit.ui.shared.modifiers.sheetHeight
import to.bitkit.ui.shared.util.gradientBackground
import to.bitkit.ui.theme.Colors

@Composable
fun GiftErrorSheet(
@StringRes titleRes: Int,
@StringRes textRes: Int,
testTag: String,
onDismiss: () -> Unit,
) {
Content(
titleRes = titleRes,
textRes = textRes,
testTag = testTag,
onDismiss = onDismiss,
)
}

@Composable
private fun Content(
@StringRes titleRes: Int,
@StringRes textRes: Int,
testTag: String,
modifier: Modifier = Modifier,
onDismiss: () -> Unit = {},
) {
Column(
modifier = modifier
.sheetHeight(SheetSize.LARGE)
.gradientBackground()
.navigationBarsPadding()
.padding(horizontal = 16.dp)
) {
SheetTopBar(titleText = stringResource(titleRes))
VerticalSpacer(16.dp)

BodyM(
text = stringResource(textRes),
color = Colors.White64,
)

Spacer(modifier = Modifier.weight(1f))

Image(
painter = painterResource(R.drawable.exclamation_mark),
contentDescription = null,
modifier = Modifier
.fillMaxWidth(IMAGE_WIDTH_FRACTION)
.aspectRatio(1.0f)
.align(Alignment.CenterHorizontally)
)

Spacer(modifier = Modifier.weight(1f))

PrimaryButton(
text = stringResource(R.string.common__ok),
onClick = onDismiss,
modifier = Modifier
.fillMaxWidth()
.testTag(testTag),
)
VerticalSpacer(16.dp)
}
}
150 changes: 150 additions & 0 deletions app/src/main/java/to/bitkit/ui/sheets/GiftLoading.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package to.bitkit.ui.sheets

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import to.bitkit.R
import to.bitkit.models.BITCOIN_SYMBOL
import to.bitkit.models.PrimaryDisplay
import to.bitkit.models.formatToModernDisplay
import to.bitkit.ui.LocalCurrencies
import to.bitkit.ui.components.BodyM
import to.bitkit.ui.components.Display
import to.bitkit.ui.components.MoneySSB
import to.bitkit.ui.components.SheetSize
import to.bitkit.ui.components.VerticalSpacer
import to.bitkit.ui.currencyViewModel
import to.bitkit.ui.scaffold.SheetTopBar
import to.bitkit.ui.shared.modifiers.sheetHeight
import to.bitkit.ui.shared.util.gradientBackground
import to.bitkit.ui.theme.Colors

@Composable
fun GiftLoading(
viewModel: GiftViewModel,
) {
Content(
amount = viewModel.amount,
)
}

@Composable
private fun Content(
amount: ULong,
modifier: Modifier = Modifier,
) {
Column(
modifier = modifier
.sheetHeight(SheetSize.LARGE)
.gradientBackground()
.navigationBarsPadding()
.padding(horizontal = 16.dp)
) {
SheetTopBar(titleText = stringResource(R.string.other__gift__claiming__title))
VerticalSpacer(16.dp)

val currencies = LocalCurrencies.current
val currency = currencyViewModel
val primaryDisplay = currencies.primaryDisplay

if (primaryDisplay == PrimaryDisplay.BITCOIN) {
MoneySSB(
sats = amount.toLong(),
unit = PrimaryDisplay.FIAT,
color = Colors.White64,
showSymbol = true,
modifier = Modifier.align(Alignment.Start),
)
VerticalSpacer(16.dp)
val bitcoinAmount = remember(amount, currency, currencies) {
currency?.convert(amount.toLong())?.bitcoinDisplay(currencies.displayUnit)?.value
?: amount.formatToModernDisplay()
}
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.align(Alignment.Start),
) {
Display(
text = BITCOIN_SYMBOL,
color = Colors.White,
modifier = Modifier.padding(end = 6.dp),
)
Display(
text = bitcoinAmount,
color = Colors.White,
)
}
} else {
MoneySSB(
sats = amount.toLong(),
unit = PrimaryDisplay.BITCOIN,
color = Colors.White64,
showSymbol = true,
modifier = Modifier.align(Alignment.Start),
)
VerticalSpacer(16.dp)
val fiatAmount = remember(amount, currency) {
currency?.convert(amount.toLong())?.formatted ?: ""
}
val fiatSymbol = remember(amount, currency) {
currency?.convert(amount.toLong())?.symbol ?: ""
}
if (fiatAmount.isNotEmpty()) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.align(Alignment.Start),
) {
Display(
text = fiatSymbol,
color = Colors.White,
modifier = Modifier.padding(end = 6.dp),
)
Display(
text = fiatAmount,
color = Colors.White,
)
}
}
}
VerticalSpacer(32.dp)

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

Spacer(modifier = Modifier.weight(1f))

Image(
painter = painterResource(R.drawable.gift),
contentDescription = null,
modifier = Modifier
.fillMaxWidth(IMAGE_WIDTH_FRACTION)
.aspectRatio(1.0f)
.align(Alignment.CenterHorizontally)
)

VerticalSpacer(32.dp)

CircularProgressIndicator(
modifier = Modifier
.align(Alignment.CenterHorizontally)
.padding(bottom = 32.dp)
.testTag("GiftLoading")
)
}
}
23 changes: 23 additions & 0 deletions app/src/main/java/to/bitkit/ui/sheets/GiftRoute.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package to.bitkit.ui.sheets

import kotlinx.serialization.Serializable

internal const val IMAGE_WIDTH_FRACTION = 0.8f

@Serializable
sealed interface GiftRoute {
@Serializable
data object Loading : GiftRoute

@Serializable
data object Used : GiftRoute

@Serializable
data object UsedUp : GiftRoute

@Serializable
data object Error : GiftRoute

@Serializable
data object Success : GiftRoute
}
102 changes: 102 additions & 0 deletions app/src/main/java/to/bitkit/ui/sheets/GiftSheet.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package to.bitkit.ui.sheets

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.imePadding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.rememberNavController
import to.bitkit.R
import to.bitkit.models.NewTransactionSheetDetails
import to.bitkit.ui.components.Sheet
import to.bitkit.ui.shared.modifiers.sheetHeight
import to.bitkit.ui.utils.composableWithDefaultTransitions
import to.bitkit.viewmodels.AppViewModel

@Composable
fun GiftSheet(
sheet: Sheet.Gift,
appViewModel: AppViewModel,
modifier: Modifier = Modifier,
viewModel: GiftViewModel = hiltViewModel(),
) {
val navController = rememberNavController()

LaunchedEffect(sheet.code, sheet.amount) {
viewModel.initialize(sheet.code, sheet.amount)
}

val onSuccessState = rememberUpdatedState { details: NewTransactionSheetDetails ->
appViewModel.hideSheet()
appViewModel.showNewTransactionSheet(details = details, event = null)
}

LaunchedEffect(Unit) {
viewModel.successEvent.collect { details ->
onSuccessState.value(details)
}
}

LaunchedEffect(Unit) {
viewModel.navigationEvent.collect { route ->
when (route) {
is GiftRoute.Success -> {
appViewModel.hideSheet()
}
else -> {
navController.navigate(route) {
popUpTo(GiftRoute.Loading) { inclusive = false }
}
}
}
}
}

Column(
modifier = modifier
.fillMaxWidth()
.sheetHeight()
.imePadding()
.testTag("GiftSheet")
) {
NavHost(
navController = navController,
startDestination = GiftRoute.Loading,
) {
composableWithDefaultTransitions<GiftRoute.Loading> {
GiftLoading(
viewModel = viewModel,
)
}
composableWithDefaultTransitions<GiftRoute.Used> {
GiftErrorSheet(
titleRes = R.string.other__gift__used__title,
textRes = R.string.other__gift__used__text,
testTag = "GiftUsed",
onDismiss = { appViewModel.hideSheet() },
)
}
composableWithDefaultTransitions<GiftRoute.UsedUp> {
GiftErrorSheet(
titleRes = R.string.other__gift__used_up__title,
textRes = R.string.other__gift__used_up__text,
testTag = "GiftUsedUp",
onDismiss = { appViewModel.hideSheet() },
)
}
composableWithDefaultTransitions<GiftRoute.Error> {
GiftErrorSheet(
titleRes = R.string.other__gift__error__title,
textRes = R.string.other__gift__error__text,
testTag = "GiftError",
onDismiss = { appViewModel.hideSheet() },
)
}
}
}
}
Loading
Loading