From d72024ee1c4da963d6ba9578da10765fff38188c Mon Sep 17 00:00:00 2001 From: Angelos Veglektsis Date: Mon, 4 Nov 2024 15:15:42 +0200 Subject: [PATCH] Minor UI fixes --- .../composeResources/values/strings.xml | 2 +- .../common/extensions/CoroutineExtensions.kt | 4 +- .../models/exchange/OnOffRampsViewModel.kt | 46 ++-- .../compose/components/Buttons.android.kt | 244 +++++++++++++++++ .../sheets/MainMenuBottomSheet.android.kt | 1 + .../blockstream/compose/components/Buttons.kt | 259 ++---------------- .../screens/exchange/OnOffRampsScreen.kt | 11 +- .../screens/overview/WalletOverviewScreen.kt | 2 +- .../compose/sheets/MainMenuBottomSheet.kt | 21 +- .../blockstream/compose/utils/Animations.kt | 6 +- 10 files changed, 324 insertions(+), 272 deletions(-) create mode 100644 compose/src/androidMain/kotlin/com/blockstream/compose/components/Buttons.android.kt diff --git a/common/src/commonMain/composeResources/values/strings.xml b/common/src/commonMain/composeResources/values/strings.xml index 115eb0d4f..485cba93b 100644 --- a/common/src/commonMain/composeResources/values/strings.xml +++ b/common/src/commonMain/composeResources/values/strings.xml @@ -1563,5 +1563,5 @@ Asset to sell Provided by %1$s Type an amount between %1$s and %2$s. A minimum setup fee of %3$s will be applied to the received amount. - Finalize on Browser + Buy with %1$s diff --git a/common/src/commonMain/kotlin/com/blockstream/common/extensions/CoroutineExtensions.kt b/common/src/commonMain/kotlin/com/blockstream/common/extensions/CoroutineExtensions.kt index 4719bdd30..31976424e 100644 --- a/common/src/commonMain/kotlin/com/blockstream/common/extensions/CoroutineExtensions.kt +++ b/common/src/commonMain/kotlin/com/blockstream/common/extensions/CoroutineExtensions.kt @@ -10,10 +10,12 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.withContext import org.koin.mp.KoinPlatformTools +import kotlin.coroutines.CoroutineContext +import kotlin.coroutines.EmptyCoroutineContext // Log and handle the exception. Prevent unhanded exception crash -suspend fun tryCatch(block: suspend () -> T): T? = withContext(context = logException()) { +suspend fun tryCatch(context: CoroutineContext = EmptyCoroutineContext, block: suspend () -> T): T? = withContext(context = context + logException()) { block() } diff --git a/common/src/commonMain/kotlin/com/blockstream/common/models/exchange/OnOffRampsViewModel.kt b/common/src/commonMain/kotlin/com/blockstream/common/models/exchange/OnOffRampsViewModel.kt index eba2b58d4..5eddce4d9 100644 --- a/common/src/commonMain/kotlin/com/blockstream/common/models/exchange/OnOffRampsViewModel.kt +++ b/common/src/commonMain/kotlin/com/blockstream/common/models/exchange/OnOffRampsViewModel.kt @@ -1,7 +1,7 @@ package com.blockstream.common.models.exchange import blockstream_green.common.generated.resources.Res -import blockstream_green.common.generated.resources.id_buy_sell +import blockstream_green.common.generated.resources.id_buy import blockstream_green.common.generated.resources.id_type_an_amount_between_s_and_s import breez_sdk.SwapInfo import com.blockstream.common.data.DenominatedValue @@ -17,6 +17,7 @@ import com.blockstream.common.extensions.isPolicyAsset import com.blockstream.common.extensions.launchIn import com.blockstream.common.extensions.previewAccountAssetBalance import com.blockstream.common.extensions.previewWallet +import com.blockstream.common.extensions.tryCatch import com.blockstream.common.gdk.data.AccountAssetBalance import com.blockstream.common.gdk.data.AssetBalance import com.blockstream.common.lightning.satoshi @@ -28,12 +29,10 @@ import com.blockstream.common.utils.toAmountLook import com.blockstream.common.utils.toAmountLookOrNa import com.rickclephas.kmp.observableviewmodel.launch import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.IO import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.onEach -import kotlinx.coroutines.withContext import org.jetbrains.compose.resources.getString abstract class OnOffRampsViewModelAbstract( @@ -64,7 +63,8 @@ abstract class OnOffRampsViewModelAbstract( class OnOffRampsViewModel(greenWallet: GreenWallet) : OnOffRampsViewModelAbstract(greenWallet = greenWallet) { - override val isSandboxEnvironment: MutableStateFlow = MutableStateFlow(appInfo.isDevelopment) + override val isSandboxEnvironment: MutableStateFlow = + MutableStateFlow(appInfo.isDevelopment) private val availableBuyAssets = session.ifConnected { listOfNotNull( @@ -88,7 +88,7 @@ class OnOffRampsViewModel(greenWallet: GreenWallet) : override val buyAccount: MutableStateFlow = MutableStateFlow(session.ifConnected { - session.accounts.value.firstOrNull { it.network.policyAsset == buyAsset.value?.assetId }?.accountAssetBalance + (listOfNotNull(session.activeAccount.value) + session.accounts.value).firstOrNull { it.network.policyAsset == buyAsset.value?.assetId }?.accountAssetBalance }) override val amount: MutableStateFlow = MutableStateFlow("") @@ -102,19 +102,21 @@ class OnOffRampsViewModel(greenWallet: GreenWallet) : private val _amountHint = MutableStateFlow(null) override val amountHint = _amountHint - private var swapInfo : SwapInfo? = null + private var swapInfo: SwapInfo? = null init { viewModelScope.launch { - _navData.value = NavData(title = getString(Res.string.id_buy_sell)) + _navData.value = NavData(title = getString(Res.string.id_buy)) } session.ifConnected { buyAsset.onEach { buyAsset -> - _buyAccounts.value = session.accounts.value.filter { it.network.policyAsset == buyAsset?.assetId }.map { - it.accountAssetBalance - } + _buyAccounts.value = + session.accounts.value.filter { it.network.policyAsset == buyAsset?.assetId } + .map { + it.accountAssetBalance + } if (buyAccount.value?.account?.network?.policyAsset != buyAsset?.assetId) { buyAccount.value = _buyAccounts.value.firstOrNull() @@ -159,10 +161,10 @@ class OnOffRampsViewModel(greenWallet: GreenWallet) : var isError = false var hintOrError: String? = null - if(isLightning){ + if (isLightning) { // Cache SwapInfo - if(swapInfo == null){ - swapInfo = withContext(context = Dispatchers.IO) { + if (swapInfo == null) { + swapInfo = tryCatch(context = Dispatchers.Main) { session.receiveOnchain() } } @@ -193,7 +195,9 @@ class OnOffRampsViewModel(greenWallet: GreenWallet) : ) } - isError = (balance?.satoshi?.let { it >= (minValue ?: 0) && it < (maxValue ?: 0) } ?: true).not() + isError = + (balance?.satoshi?.let { it >= (minValue ?: 0) && it < (maxValue ?: 0) } + ?: true).not() } if (isError) { @@ -224,7 +228,8 @@ class OnOffRampsViewModel(greenWallet: GreenWallet) : private fun redirectToRamps() { doAsync({ - val meldKey = if(isSandboxEnvironment.value) MELD_DEVELOPMENT_KEY else MELD_PRODUCTION_KEY + val meldKey = + if (isSandboxEnvironment.value) MELD_DEVELOPMENT_KEY else MELD_PRODUCTION_KEY if (isBuy.value) { val address = session.getReceiveAddressAsString(buyAccount.value!!.account) @@ -277,14 +282,17 @@ class OnOffRampsViewModel(greenWallet: GreenWallet) : amount.value = denominatedValue.asInput ?: "" } - companion object: Loggable() { + companion object : Loggable() { private const val MELD_PRODUCTION = "https://meldcrypto.com" private const val MELD_SANDBOX = "https://sb.meldcrypto.com" - private const val MELD_PRODUCTION_KEY = "WXDhJPMkahPCQ9AjtjS4Mi:49txEyv53WtUvXfVg1FNYvQdzWJc" - private const val MELD_DEVELOPMENT_KEY = "WQ59eghSwdJxyfaKbk87Cm:D2J97iJX5XjutTot6PAcxNnt4NTuCSWaH" + private const val MELD_PRODUCTION_KEY = + "WXDhJPMkahPCQ9AjtjS4Mi:49txEyv53WtUvXfVg1FNYvQdzWJc" + private const val MELD_DEVELOPMENT_KEY = + "WQ59eghSwdJxyfaKbk87Cm:D2J97iJX5XjutTot6PAcxNnt4NTuCSWaH" - fun meldUrl(isSandboxEnvironment: Boolean) = if(isSandboxEnvironment) MELD_SANDBOX else MELD_PRODUCTION + fun meldUrl(isSandboxEnvironment: Boolean) = + if (isSandboxEnvironment) MELD_SANDBOX else MELD_PRODUCTION } } diff --git a/compose/src/androidMain/kotlin/com/blockstream/compose/components/Buttons.android.kt b/compose/src/androidMain/kotlin/com/blockstream/compose/components/Buttons.android.kt new file mode 100644 index 000000000..466e6359f --- /dev/null +++ b/compose/src/androidMain/kotlin/com/blockstream/compose/components/Buttons.android.kt @@ -0,0 +1,244 @@ +package com.blockstream.compose.components + +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.material3.HorizontalDivider +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview +import blockstream_green.common.generated.resources.Res +import blockstream_green.common.generated.resources.share_network +import com.blockstream.compose.theme.GreenThemePreview +import org.jetbrains.compose.resources.painterResource + +@Composable +@Preview +fun GreenButtonPreview() { + GreenThemePreview { + GreenColumn( + space = 6, + modifier = Modifier.verticalScroll(rememberScrollState()) + ) { + Text("Specific") + + GreenRow(padding = 0) { + ScanQrButton { + + } + + LearnMoreButton { + + } + } + + GreenRow(padding = 0) { + AboutButton { } + AppSettingsButton { } + HelpButton { } + } + + GreenRow(padding = 0) { + ZoomButton { } + } + + HorizontalDivider() + Text("Normal") + GreenButton( + text = "Normal Loading", + enabled = false, + onProgress = true, + modifier = Modifier.fillMaxWidth() + ) { } + GreenRow(padding = 0) { + GreenButton(text = "Normal Enabled", icon = painterResource(Res.drawable.share_network)) { } + GreenButton(text = "Norma Disabled", enabled = false) { } + } + GreenRow(padding = 0) { + GreenButton(text = "Big Enabled", size = GreenButtonSize.BIG) { } + GreenButton(text = "Big Disabled", size = GreenButtonSize.BIG, enabled = false) { } + } + GreenRow(padding = 0) { + GreenButton(text = "S", size = GreenButtonSize.SMALL) { } + GreenButton(text = "Small Enabled", size = GreenButtonSize.SMALL) { } + GreenButton( + text = "Small Disabled", + size = GreenButtonSize.SMALL, + enabled = false + ) { } + } + GreenRow(padding = 0) { + GreenButton(text = "T", size = GreenButtonSize.TINY) { } + GreenButton(text = "Tiny Enabled", size = GreenButtonSize.TINY) { } + GreenButton( + text = "Tiny Disabled", + size = GreenButtonSize.TINY, + enabled = false + ) { } + } + GreenRow(padding = 0) { + GreenButton(text = "Greener", color = GreenButtonColor.RED) { } + GreenButton(text = "Red", color = GreenButtonColor.RED) { } + GreenButton(text = "White", color = GreenButtonColor.WHITE) { } + } + + + HorizontalDivider() + Text("Outline") + GreenRow(padding = 0, space = 4) { + GreenButton(text = "Normal Enabled", type = GreenButtonType.OUTLINE) { } + GreenButton( + text = "Norma Disabled", + type = GreenButtonType.OUTLINE, + enabled = false + ) { } + } + + GreenRow(padding = 0, space = 4) { + GreenButton( + text = "Big Enabled", + type = GreenButtonType.OUTLINE, + size = GreenButtonSize.BIG + ) { } + GreenButton( + text = "Big Disabled", + type = GreenButtonType.OUTLINE, + size = GreenButtonSize.BIG, + enabled = false + ) { } + } + + GreenRow(padding = 0, space = 4) { + GreenButton( + text = "S", + type = GreenButtonType.OUTLINE, + size = GreenButtonSize.SMALL + ) { } + GreenButton( + text = "Small Enabled", + type = GreenButtonType.OUTLINE, + size = GreenButtonSize.SMALL + ) { } + GreenButton( + text = "Small Disabled", + type = GreenButtonType.OUTLINE, + size = GreenButtonSize.SMALL, + enabled = false + ) { } + } + + GreenRow(padding = 0, space = 4) { + GreenButton( + text = "T", + type = GreenButtonType.OUTLINE, + size = GreenButtonSize.TINY + ) { } + GreenButton( + text = "Tiny Enabled", + type = GreenButtonType.OUTLINE, + size = GreenButtonSize.TINY + ) { } + GreenButton( + text = "Tiny Disabled", + type = GreenButtonType.OUTLINE, + size = GreenButtonSize.TINY, + enabled = false + ) { } + } + + GreenRow(padding = 0, space = 4) { + GreenButton( + text = "Green", + type = GreenButtonType.OUTLINE, + color = GreenButtonColor.GREENER + ) { } + GreenButton( + text = "Green", + type = GreenButtonType.OUTLINE, + color = GreenButtonColor.RED + ) { } + GreenButton( + text = "Green", + type = GreenButtonType.OUTLINE, + color = GreenButtonColor.WHITE + ) { } + } + + HorizontalDivider() + Text("Text") + GreenRow(padding = 0, space = 4) { + GreenButton(text = "Normal Enabled", type = GreenButtonType.TEXT) { } + GreenButton( + text = "Norma Disabled", + type = GreenButtonType.TEXT, + enabled = false + ) { } + } + + GreenRow(padding = 0, space = 4) { + GreenButton( + text = "Big Enabled", + type = GreenButtonType.TEXT, + size = GreenButtonSize.BIG + ) { } + GreenButton( + text = "Big Disabled", + type = GreenButtonType.TEXT, + size = GreenButtonSize.BIG, + enabled = false + ) { } + } + + GreenRow(padding = 0, space = 4) { + GreenButton( + text = "S", + type = GreenButtonType.TEXT, + size = GreenButtonSize.SMALL + ) { } + GreenButton( + text = "Small Enabled", + type = GreenButtonType.TEXT, + size = GreenButtonSize.SMALL + ) { } + GreenButton( + text = "Small Disabled", + type = GreenButtonType.TEXT, + size = GreenButtonSize.SMALL, + enabled = false + ) { } + } + + GreenRow(padding = 0, space = 4) { + GreenButton( + text = "T", + type = GreenButtonType.TEXT, + size = GreenButtonSize.TINY + ) { } + GreenButton( + text = "Tiny Enabled", + type = GreenButtonType.TEXT, + size = GreenButtonSize.TINY + ) { } + GreenButton( + text = "Tiny Disabled", + type = GreenButtonType.TEXT, + size = GreenButtonSize.TINY, + enabled = false + ) { } + } + + GreenRow(padding = 0, space = 4) { + GreenButton( + text = "Green", + type = GreenButtonType.TEXT, + color = GreenButtonColor.RED + ) { } + GreenButton( + text = "Green", + type = GreenButtonType.TEXT, + color = GreenButtonColor.WHITE + ) { } + } + } + } +} + diff --git a/compose/src/androidMain/kotlin/com/blockstream/compose/sheets/MainMenuBottomSheet.android.kt b/compose/src/androidMain/kotlin/com/blockstream/compose/sheets/MainMenuBottomSheet.android.kt index 2df230ef1..f21cfeca6 100644 --- a/compose/src/androidMain/kotlin/com/blockstream/compose/sheets/MainMenuBottomSheet.android.kt +++ b/compose/src/androidMain/kotlin/com/blockstream/compose/sheets/MainMenuBottomSheet.android.kt @@ -31,6 +31,7 @@ fun MainMenuBottomSheetPreview() { onSelect = { menuEntry -> }, + isTestnet = false, onDismissRequest = { showBottomSheet = false } diff --git a/compose/src/commonMain/kotlin/com/blockstream/compose/components/Buttons.kt b/compose/src/commonMain/kotlin/com/blockstream/compose/components/Buttons.kt index 4140e0e1a..983c7b6e3 100644 --- a/compose/src/commonMain/kotlin/com/blockstream/compose/components/Buttons.kt +++ b/compose/src/commonMain/kotlin/com/blockstream/compose/components/Buttons.kt @@ -1,13 +1,13 @@ package com.blockstream.compose.components import androidx.compose.foundation.BorderStroke +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults -import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedButton @@ -22,6 +22,7 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import blockstream_green.common.generated.resources.Res import blockstream_green.common.generated.resources.arrow_square_out +import blockstream_green.common.generated.resources.arrows_counter_clockwise import blockstream_green.common.generated.resources.clipboard import blockstream_green.common.generated.resources.green_shield import blockstream_green.common.generated.resources.id_about @@ -32,20 +33,17 @@ import blockstream_green.common.generated.resources.id_increase_qr_size import blockstream_green.common.generated.resources.id_learn_more import blockstream_green.common.generated.resources.id_paste import blockstream_green.common.generated.resources.id_scan_qr_code -import blockstream_green.common.generated.resources.id_watchonly import blockstream_green.common.generated.resources.magnifying_glass_plus import blockstream_green.common.generated.resources.qr_code import blockstream_green.common.generated.resources.question -import blockstream_green.common.generated.resources.share_network -import com.blockstream.compose.theme.GreenThemePreview import com.blockstream.compose.theme.green import com.blockstream.compose.theme.labelLarge import com.blockstream.compose.theme.labelMedium import com.blockstream.compose.theme.labelSmall import com.blockstream.compose.theme.whiteMedium +import com.blockstream.compose.utils.Rotating import org.jetbrains.compose.resources.painterResource import org.jetbrains.compose.resources.stringResource -import org.jetbrains.compose.ui.tooling.preview.Preview enum class GreenButtonSize { NORMAL, SMALL, TINY, BIG @@ -74,6 +72,7 @@ fun GreenButton( size: GreenButtonSize = GreenButtonSize.NORMAL, icon: Painter? = null, enabled: Boolean = true, + onProgress: Boolean = false, onClick: () -> Unit, ) { @@ -148,15 +147,24 @@ fun GreenButton( contentPadding = contentPadding, shape = MaterialTheme.shapes.small, ) { - icon?.also { - Icon( - painter = it, - contentDescription = null, - modifier = Modifier - .padding(end = 6.dp) - .size(18.dp) - ) + + if (icon != null || onProgress) { + Box(modifier = Modifier.padding(end = 6.dp)) { + Rotating( + duration = 2000, + enabled = onProgress, + ) { + Icon( + painter = icon.takeIf { !onProgress } + ?: painterResource(Res.drawable.arrows_counter_clockwise), + contentDescription = null, + modifier = Modifier + .size(18.dp) + ) + } + } } + GreenButtonText(text = text, textStyle = textStyle) } } @@ -361,228 +369,3 @@ fun AppSettingsButton(modifier: Modifier = Modifier, onClick: () -> Unit) { } } -@Composable -@Preview -fun GreenButtonPreview() { - GreenThemePreview { - GreenColumn( - space = 6, -// modifier = Modifier.verticalScroll(rememberScrollState()) - ) { - Text("Specific") - - GreenRow(padding = 0) { - ScanQrButton { - - } - - LearnMoreButton { - - } - } - - GreenRow(padding = 0) { - AboutButton { } - AppSettingsButton { } - HelpButton { } - } - - GreenRow(padding = 0) { - ZoomButton { } - } - - HorizontalDivider() - Text("Normal") - GreenRow(padding = 0) { - GreenButton(text = "Normal Enabled", icon = painterResource(Res.drawable.share_network)) { } - GreenButton(text = "Norma Disabled", enabled = false) { } - } - GreenRow(padding = 0) { - GreenButton(text = "Big Enabled", size = GreenButtonSize.BIG) { } - GreenButton(text = "Big Disabled", size = GreenButtonSize.BIG, enabled = false) { } - } - GreenRow(padding = 0) { - GreenButton(text = "S", size = GreenButtonSize.SMALL) { } - GreenButton(text = "Small Enabled", size = GreenButtonSize.SMALL) { } - GreenButton( - text = "Small Disabled", - size = GreenButtonSize.SMALL, - enabled = false - ) { } - } - GreenRow(padding = 0) { - GreenButton(text = "T", size = GreenButtonSize.TINY) { } - GreenButton(text = "Tiny Enabled", size = GreenButtonSize.TINY) { } - GreenButton( - text = "Tiny Disabled", - size = GreenButtonSize.TINY, - enabled = false - ) { } - } - GreenRow(padding = 0) { - GreenButton(text = "Greener", color = GreenButtonColor.RED) { } - GreenButton(text = "Red", color = GreenButtonColor.RED) { } - GreenButton(text = "White", color = GreenButtonColor.WHITE) { } - } - - - HorizontalDivider() - Text("Outline") - GreenRow(padding = 0, space = 4) { - GreenButton(text = "Normal Enabled", type = GreenButtonType.OUTLINE) { } - GreenButton( - text = "Norma Disabled", - type = GreenButtonType.OUTLINE, - enabled = false - ) { } - } - - GreenRow(padding = 0, space = 4) { - GreenButton( - text = "Big Enabled", - type = GreenButtonType.OUTLINE, - size = GreenButtonSize.BIG - ) { } - GreenButton( - text = "Big Disabled", - type = GreenButtonType.OUTLINE, - size = GreenButtonSize.BIG, - enabled = false - ) { } - } - - GreenRow(padding = 0, space = 4) { - GreenButton( - text = "S", - type = GreenButtonType.OUTLINE, - size = GreenButtonSize.SMALL - ) { } - GreenButton( - text = "Small Enabled", - type = GreenButtonType.OUTLINE, - size = GreenButtonSize.SMALL - ) { } - GreenButton( - text = "Small Disabled", - type = GreenButtonType.OUTLINE, - size = GreenButtonSize.SMALL, - enabled = false - ) { } - } - - GreenRow(padding = 0, space = 4) { - GreenButton( - text = "T", - type = GreenButtonType.OUTLINE, - size = GreenButtonSize.TINY - ) { } - GreenButton( - text = "Tiny Enabled", - type = GreenButtonType.OUTLINE, - size = GreenButtonSize.TINY - ) { } - GreenButton( - text = "Tiny Disabled", - type = GreenButtonType.OUTLINE, - size = GreenButtonSize.TINY, - enabled = false - ) { } - } - - GreenRow(padding = 0, space = 4) { - GreenButton( - text = "Green", - type = GreenButtonType.OUTLINE, - color = GreenButtonColor.GREENER - ) { } - GreenButton( - text = "Green", - type = GreenButtonType.OUTLINE, - color = GreenButtonColor.RED - ) { } - GreenButton( - text = "Green", - type = GreenButtonType.OUTLINE, - color = GreenButtonColor.WHITE - ) { } - } - - HorizontalDivider() - Text("Text") - GreenRow(padding = 0, space = 4) { - GreenButton(text = "Normal Enabled", type = GreenButtonType.TEXT) { } - GreenButton( - text = "Norma Disabled", - type = GreenButtonType.TEXT, - enabled = false - ) { } - } - - GreenRow(padding = 0, space = 4) { - GreenButton( - text = "Big Enabled", - type = GreenButtonType.TEXT, - size = GreenButtonSize.BIG - ) { } - GreenButton( - text = "Big Disabled", - type = GreenButtonType.TEXT, - size = GreenButtonSize.BIG, - enabled = false - ) { } - } - - GreenRow(padding = 0, space = 4) { - GreenButton( - text = "S", - type = GreenButtonType.TEXT, - size = GreenButtonSize.SMALL - ) { } - GreenButton( - text = "Small Enabled", - type = GreenButtonType.TEXT, - size = GreenButtonSize.SMALL - ) { } - GreenButton( - text = "Small Disabled", - type = GreenButtonType.TEXT, - size = GreenButtonSize.SMALL, - enabled = false - ) { } - } - - GreenRow(padding = 0, space = 4) { - GreenButton( - text = "T", - type = GreenButtonType.TEXT, - size = GreenButtonSize.TINY - ) { } - GreenButton( - text = "Tiny Enabled", - type = GreenButtonType.TEXT, - size = GreenButtonSize.TINY - ) { } - GreenButton( - text = "Tiny Disabled", - type = GreenButtonType.TEXT, - size = GreenButtonSize.TINY, - enabled = false - ) { } - } - - GreenRow(padding = 0, space = 4) { - GreenButton( - text = "Green", - type = GreenButtonType.TEXT, - color = GreenButtonColor.RED - ) { } - GreenButton( - text = "Green", - type = GreenButtonType.TEXT, - color = GreenButtonColor.WHITE - ) { } - } - } - } -} - diff --git a/compose/src/commonMain/kotlin/com/blockstream/compose/screens/exchange/OnOffRampsScreen.kt b/compose/src/commonMain/kotlin/com/blockstream/compose/screens/exchange/OnOffRampsScreen.kt index d43c0f025..d6d0166c9 100644 --- a/compose/src/commonMain/kotlin/com/blockstream/compose/screens/exchange/OnOffRampsScreen.kt +++ b/compose/src/commonMain/kotlin/com/blockstream/compose/screens/exchange/OnOffRampsScreen.kt @@ -19,11 +19,12 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.lifecycle.compose.collectAsStateWithLifecycle import blockstream_green.common.generated.resources.Res +import blockstream_green.common.generated.resources.arrow_square_out import blockstream_green.common.generated.resources.id_account import blockstream_green.common.generated.resources.id_asset_to_buy import blockstream_green.common.generated.resources.id_buy +import blockstream_green.common.generated.resources.id_buy_with_s import blockstream_green.common.generated.resources.id_create_new_account -import blockstream_green.common.generated.resources.id_finalize_on_browser import blockstream_green.common.generated.resources.id_provided_by_ import blockstream_green.common.generated.resources.id_select_account import blockstream_green.common.generated.resources.id_sell @@ -61,6 +62,7 @@ import com.blockstream.compose.theme.md_theme_surface import com.blockstream.compose.theme.whiteLow import com.blockstream.compose.utils.AppBar import com.blockstream.compose.utils.HandleSideEffect +import org.jetbrains.compose.resources.painterResource import org.jetbrains.compose.resources.stringResource import org.koin.core.parameter.parametersOf @@ -241,6 +243,7 @@ fun OnOffRampsScreen( } val buttonEnabled by viewModel.buttonEnabled.collectAsStateWithLifecycle() + val onProgress by viewModel.onProgress.collectAsStateWithLifecycle() if(viewModel.appInfo.isDevelopment) { val isSandboxEnvironment by viewModel.isSandboxEnvironment.collectAsStateWithLifecycle() @@ -275,10 +278,12 @@ fun OnOffRampsScreen( ) GreenButton( - text = stringResource(Res.string.id_finalize_on_browser), + text = stringResource(Res.string.id_buy_with_s, "meld.io"), modifier = Modifier.fillMaxWidth(), size = GreenButtonSize.BIG, - enabled = buttonEnabled + icon = painterResource(Res.drawable.arrow_square_out), + enabled = buttonEnabled, + onProgress = onProgress ) { viewModel.postEvent(Events.Continue) } diff --git a/compose/src/commonMain/kotlin/com/blockstream/compose/screens/overview/WalletOverviewScreen.kt b/compose/src/commonMain/kotlin/com/blockstream/compose/screens/overview/WalletOverviewScreen.kt index ee166b494..847b0c225 100644 --- a/compose/src/commonMain/kotlin/com/blockstream/compose/screens/overview/WalletOverviewScreen.kt +++ b/compose/src/commonMain/kotlin/com/blockstream/compose/screens/overview/WalletOverviewScreen.kt @@ -465,7 +465,7 @@ fun WalletOverviewScreen( }, onReceiveClick = { viewModel.postEvent(WalletOverviewViewModel.LocalEvents.Receive) }, onCircleClick = { - bottomSheetNavigator?.show(MainMenuBottomSheet) + bottomSheetNavigator?.show(MainMenuBottomSheet(isTestnet = viewModel.greenWallet.isTestnet)) } ) } diff --git a/compose/src/commonMain/kotlin/com/blockstream/compose/sheets/MainMenuBottomSheet.kt b/compose/src/commonMain/kotlin/com/blockstream/compose/sheets/MainMenuBottomSheet.kt index cf1df53e4..784559cc3 100644 --- a/compose/src/commonMain/kotlin/com/blockstream/compose/sheets/MainMenuBottomSheet.kt +++ b/compose/src/commonMain/kotlin/com/blockstream/compose/sheets/MainMenuBottomSheet.kt @@ -23,6 +23,8 @@ import blockstream_green.common.generated.resources.id_redeposit_expired_2fa_coi import blockstream_green.common.generated.resources.id_scan_qr_code import blockstream_green.common.generated.resources.qr_code import com.blockstream.common.CountlyBase +import com.blockstream.common.Parcelable +import com.blockstream.common.Parcelize import com.blockstream.compose.LocalAppInfo import com.blockstream.compose.components.GreenArrow import com.blockstream.compose.components.GreenBottomSheet @@ -41,7 +43,8 @@ enum class MainMenuEntry { BUY_SELL, ACCOUNT_TRANSFER, SCAN, REDEPOSIT; } -object MainMenuBottomSheet : BottomScreen() { +@Parcelize +data class MainMenuBottomSheet(val isTestnet: Boolean) : BottomScreen(), Parcelable { @Composable override fun Content() { val onDismissRequest = onDismissRequest() @@ -50,16 +53,19 @@ object MainMenuBottomSheet : BottomScreen() { setResult(menuEntry) onDismissRequest.invoke() }, + isTestnet = isTestnet, onDismissRequest = onDismissRequest ) } - @Composable - fun getResult(fn: (MainMenuEntry) -> Unit) = - getNavigationResult(this::class, fn) + companion object{ + @Composable + fun getResult(fn: (MainMenuEntry) -> Unit) = + getNavigationResult(this::class, fn) - private fun setResult(result: MainMenuEntry) = - setNavigationResult(this::class, result) + private fun setResult(result: MainMenuEntry) = + setNavigationResult(this::class, result) + } } @Composable @@ -84,6 +90,7 @@ fun MainMenuItem(title: String, subtitle: String, icon: Painter, onClick: (() -> @Composable fun MainMenuBottomSheetView( onSelect: (item: MainMenuEntry) -> Unit, + isTestnet: Boolean, onDismissRequest: () -> Unit, ) { GreenBottomSheet( @@ -102,7 +109,7 @@ fun MainMenuBottomSheetView( GreenColumn { - if(countly.getRemoteConfigForOnOffRamps() != false) { + if(countly.getRemoteConfigForOnOffRamps() != false && !isTestnet) { MainMenuItem( title = stringResource(Res.string.id_buy), subtitle = "BTC", diff --git a/compose/src/commonMain/kotlin/com/blockstream/compose/utils/Animations.kt b/compose/src/commonMain/kotlin/com/blockstream/compose/utils/Animations.kt index b4afd16ea..716c507ce 100644 --- a/compose/src/commonMain/kotlin/com/blockstream/compose/utils/Animations.kt +++ b/compose/src/commonMain/kotlin/com/blockstream/compose/utils/Animations.kt @@ -94,7 +94,7 @@ fun AlphaPulse(pulseFraction: Float = 0.75f, duration : Int = 500, modifier: Mod } @Composable -fun Rotating(duration: Int = 1000, content: @Composable () -> Unit) { +fun Rotating(duration: Int = 1000, enabled: Boolean = true, modifier: Modifier = Modifier, content: @Composable () -> Unit) { val infiniteTransition = rememberInfiniteTransition() val rotate by infiniteTransition.animateFloat( @@ -106,7 +106,9 @@ fun Rotating(duration: Int = 1000, content: @Composable () -> Unit) { ) ) - Box(modifier = Modifier.rotate(rotate)) { + Box(modifier = Modifier.ifTrue(enabled){ + rotate(rotate) + }.then(modifier)) { content() } } \ No newline at end of file