Skip to content

Commit

Permalink
feat(staking): AND-6804 discover tab - pt2 (#4171)
Browse files Browse the repository at this point in the history
  • Loading branch information
dserrano-bc committed Dec 1, 2022
1 parent d4baf57 commit e4b3e27
Show file tree
Hide file tree
Showing 17 changed files with 353 additions and 173 deletions.
Expand Up @@ -415,7 +415,6 @@ class TransactionInteractor(
if (accountBalance.totalBalance.isZero) {
FeatureAccess.Blocked(
BlockedReason.ShouldAcknowledgeStakingWithdrawal(
bondingDays = limits.bondingDays,
assetIconUrl = asset.logo
)
)
Expand Down
Expand Up @@ -288,8 +288,7 @@ class TransactionFlowActivity :
is BlockedReason.TooManyInFlightTransactions,
is BlockedReason.InsufficientTier -> KycUpgradeNowSheet.newInstance()
is BlockedReason.ShouldAcknowledgeStakingWithdrawal -> StakingAccountWithdrawWarning.newInstance(
featureBlockedReason.assetIconUrl,
featureBlockedReason.bondingDays
featureBlockedReason.assetIconUrl
)
null -> throw IllegalStateException(
"No featureBlockedReason provided for TransactionStep.FEATURE_BLOCKED, state $state"
Expand Down
Expand Up @@ -61,10 +61,6 @@ class StakingAccountWithdrawWarning : ComposeModalBottomDialog() {
arguments?.getString(ASSET_ICON_URL)
}

private val bondingDays: Int? by lazy {
arguments?.getInt(ASSET_BONDING_DAYS)
}

interface Host : HostedBottomSheet.Host {
fun learnMoreClicked()
fun onNextClicked()
Expand All @@ -79,19 +75,16 @@ class StakingAccountWithdrawWarning : ComposeModalBottomDialog() {
onLearnMoreClicked = host::learnMoreClicked,
onNext = host::onNextClicked,
assetIcon = assetIconUrl?.let { ImageResource.Remote(it) } ?: ImageResource.Local(R.drawable.ic_blockchain),
accountTypeIcon = ImageResource.Local(R.drawable.ic_staking_explainer),
bondingDays = bondingDays ?: 0
accountTypeIcon = ImageResource.Local(R.drawable.ic_staking_explainer)
)
}

companion object {
private const val ASSET_ICON_URL = "ASSET_ICON_URL"
private const val ASSET_BONDING_DAYS = "ASSET_BONDING_DAYS"
fun newInstance(assetIconUrl: String?, bondingDays: Int) =
fun newInstance(assetIconUrl: String?) =
StakingAccountWithdrawWarning().apply {
arguments = Bundle().apply {
putString(ASSET_ICON_URL, assetIconUrl)
putInt(ASSET_BONDING_DAYS, bondingDays)
}
}
}
Expand All @@ -105,14 +98,9 @@ fun StakingAccountInfo(
onLearnMoreClicked: () -> Unit,
onNext: () -> Unit,
assetIcon: ImageResource,
accountTypeIcon: ImageResource,
bondingDays: Int
accountTypeIcon: ImageResource
) {
val items = listOf(
InfoItem(stringResource(id = R.string.staking_cannot_withdraw_paragraph_1)),
InfoItem(stringResource(id = R.string.staking_cannot_withdraw_paragraph_2, bondingDays)),
InfoItem(stringResource(id = R.string.staking_cannot_withdraw_paragraph_3, bondingDays))
)
val items = listOf(InfoItem(stringResource(id = R.string.staking_cannot_withdraw_paragraph)))
val pagerState = rememberPagerState()
val coroutineScope = rememberCoroutineScope()
val scroll = rememberScrollState(0)
Expand Down Expand Up @@ -255,8 +243,7 @@ fun StakingInfo() {
{},
{},
ImageResource.Local(R.drawable.ic_blockchain),
ImageResource.Local(R.drawable.ic_staking_explainer),
2
ImageResource.Local(R.drawable.ic_staking_explainer)
)
}
}
Expand Down
Expand Up @@ -110,32 +110,32 @@ class KycUpgradeNowSheet : SlidingModalBottomDialog<DialogSheetKycUpgradeNowBind
verifyClicked = {
ctaClicked = true
logAnalytics(
com.blockchain.presentation.customviews.kyc.KycUpgradeNowSheet.AnalyticsType.GetVerifiedClicked
AnalyticsType.GetVerifiedClicked
)
startKycClicked()
}
).apply {
val initialItems =
com.blockchain.presentation.customviews.kyc.KycUpgradeNowSheet.ViewPagerTab.values().toList()
ViewPagerTab.values().toList()
.toItems(isBasicApproved = false)
submitList(initialItems)
}

viewPager.adapter = viewPagerAdapter
tabLayoutMediator = TabLayoutMediator(tabLayout, viewPager) { tab, position ->
tab.text =
when (com.blockchain.presentation.customviews.kyc.KycUpgradeNowSheet.ViewPagerTab.values()[position]) {
com.blockchain.presentation.customviews.kyc.KycUpgradeNowSheet.ViewPagerTab.BASIC -> getString(
when (ViewPagerTab.values()[position]) {
ViewPagerTab.BASIC -> getString(
R.string.kyc_upgrade_now_tab_basic
)
com.blockchain.presentation.customviews.kyc.KycUpgradeNowSheet.ViewPagerTab.VERIFIED -> getString(
ViewPagerTab.VERIFIED -> getString(
R.string.kyc_upgrade_now_tab_verified
)
}
}
tabLayoutMediator.attach()
viewPager.setCurrentItem(
com.blockchain.presentation.customviews.kyc.KycUpgradeNowSheet.ViewPagerTab.values().indexOf(initialTab),
ViewPagerTab.values().indexOf(initialTab),
false
)

Expand All @@ -144,14 +144,14 @@ class KycUpgradeNowSheet : SlidingModalBottomDialog<DialogSheetKycUpgradeNowBind
onSuccess = { (highestTier, _) ->
val isAtleastSilver = highestTier != KycTier.BRONZE
val items =
com.blockchain.presentation.customviews.kyc.KycUpgradeNowSheet.ViewPagerTab.values().toList()
ViewPagerTab.values().toList()
.toItems(isBasicApproved = isAtleastSilver)
viewPagerAdapter.submitList(items)
},
onError = {}
)

logAnalytics(com.blockchain.presentation.customviews.kyc.KycUpgradeNowSheet.AnalyticsType.Viewed)
logAnalytics(AnalyticsType.Viewed)
}

private fun startKycClicked() {
Expand Down
Expand Up @@ -43,7 +43,6 @@ fun ButtonContentSmall(
loadingIconResId = loadingIconResId,
)
} else {

Row(
Modifier.alpha(contentAlpha),
horizontalArrangement = Arrangement.Center,
Expand Down
Expand Up @@ -70,8 +70,9 @@ fun OutlinedButton(
isDarkTheme: Boolean = isSystemInDarkTheme(),
icon: ImageResource = ImageResource.None,
contentPadding: PaddingValues = ButtonDefaults.ContentPadding,
backgroundColour: Color = Color.Unspecified
) {
var backgroundColor by remember { mutableStateOf(Color.Unspecified) }
var backgroundColor by remember { mutableStateOf(backgroundColour) }
var borderColor by remember {
mutableStateOf(
if (isDarkTheme) defaultBorderDarkColor else defaultBorderLightColor
Expand Down
@@ -1,6 +1,7 @@
package com.blockchain.componentlib.button

import android.content.res.Configuration
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.requiredHeightIn
import androidx.compose.material.ButtonDefaults
Expand All @@ -20,7 +21,8 @@ fun SmallMinimalButton(
onClick: () -> Unit,
modifier: Modifier = Modifier,
state: ButtonState = ButtonState.Enabled,
icon: ImageResource = ImageResource.None
icon: ImageResource = ImageResource.None,
isTransparent: Boolean = true
) {

val contentPadding = PaddingValues(
Expand All @@ -44,22 +46,30 @@ fun SmallMinimalButton(
modifier = modifier.requiredHeightIn(min = dimensionResource(R.dimen.large_spacing)),
contentPadding = contentPadding,
icon = icon,
buttonContent = {
state: ButtonState,
backgroundColour = if (isTransparent) {
Color.Unspecified
} else {
if (isSystemInDarkTheme()) {
AppTheme.colors.muted
} else {
Color.White
}
},
buttonContent = { state: ButtonState,
text: String,
textColor: Color,
textAlpha: Float,
loadingIconResId: Int,
icon: ImageResource, ->
icon: ImageResource ->
ButtonContentSmall(
state = state,
text = text,
textColor = textColor,
contentAlpha = textAlpha,
icon = icon,
loadingIconResId = loadingIconResId,
loadingIconResId = loadingIconResId
)
},
}
)
}

Expand Down Expand Up @@ -158,3 +168,18 @@ private fun SmallMinimalButton_DarkDisabled() {
}
}
}

@Preview
@Composable
private fun SmallMinimalButton_Non_Transparent() {
AppTheme {
AppSurface {
SmallMinimalButton(
onClick = { },
text = "Small Minimal Button",
state = ButtonState.Enabled,
isTransparent = false
)
}
}
}
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
Expand All @@ -28,6 +29,7 @@ import com.blockchain.componentlib.button.DestructiveMinimalButton
import com.blockchain.componentlib.button.DestructivePrimaryButton
import com.blockchain.componentlib.button.MinimalButton
import com.blockchain.componentlib.button.PrimaryButton
import com.blockchain.componentlib.button.SmallMinimalButton
import com.blockchain.componentlib.theme.AppSurface
import com.blockchain.componentlib.theme.AppTheme
import com.blockchain.componentlib.theme.Dark800
Expand All @@ -53,8 +55,8 @@ fun BottomSheetTwoButtons(
showTitleInHeader = showTitleInHeader,
subtitle = subtitle,
buttonsContent = {
button1.toBottomSheetButtonComposable(Modifier.fillMaxWidth()).invoke()
button2.toBottomSheetButtonComposable(Modifier.fillMaxWidth()).invoke()
button1.toBottomSheetButtonComposable(Modifier.wrapContentWidth()).invoke()
button2.toBottomSheetButtonComposable(Modifier.wrapContentWidth()).invoke()
},
isDarkTheme = isDarkTheme,
shouldShowHeaderDivider = shouldShowHeaderDivider,
Expand All @@ -81,7 +83,7 @@ fun BottomSheetOneButton(
showTitleInHeader = showTitleInHeader,
subtitle = subtitle,
buttonsContent = {
button.toBottomSheetButtonComposable(Modifier.fillMaxWidth()).invoke()
button.toBottomSheetButtonComposable(Modifier.wrapContentWidth()).invoke()
},
isDarkTheme = isDarkTheme,
shouldShowHeaderDivider = shouldShowHeaderDivider,
Expand Down Expand Up @@ -187,6 +189,7 @@ private fun BottomSheet(
.wrapContentHeight()
.padding(horizontal = dimensionResource(R.dimen.standard_spacing)),
verticalArrangement = Arrangement.spacedBy(16.dp),
horizontalAlignment = Alignment.CenterHorizontally,
content = buttonsContent
)
Spacer(Modifier.size(dimensionResource(R.dimen.small_spacing)))
Expand All @@ -201,23 +204,28 @@ private fun BottomSheetButton.toBottomSheetButtonComposable(modifier: Modifier):
ButtonType.PRIMARY -> PrimaryButton(
text = text,
onClick = onClick,
modifier = modifier
modifier = modifier.fillMaxWidth()
)
ButtonType.MINIMAL -> MinimalButton(
text = text,
onClick = onClick,
modifier = modifier.fillMaxWidth()
)
ButtonType.SMALL_MINIMAL -> SmallMinimalButton(
text = text,
onClick = onClick,
modifier = modifier
)
ButtonType.DESTRUCTIVE_MINIMAL -> DestructiveMinimalButton(
text = text,
onClick = onClick,
modifier = modifier
modifier = modifier.fillMaxWidth()
)
ButtonType.DESTRUCTIVE_PRIMARY ->
DestructivePrimaryButton(
text = text,
onClick = onClick,
modifier = modifier
modifier = modifier.fillMaxWidth()
)
}
}
Expand All @@ -230,7 +238,7 @@ data class BottomSheetButton(
)

enum class ButtonType {
PRIMARY, MINIMAL, DESTRUCTIVE_MINIMAL, DESTRUCTIVE_PRIMARY
PRIMARY, MINIMAL, DESTRUCTIVE_MINIMAL, DESTRUCTIVE_PRIMARY, SMALL_MINIMAL
}

@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO)
Expand Down Expand Up @@ -330,3 +338,26 @@ fun PrimaryAndMinimalButtonSheet() {
}
}
}

@Preview()
@Composable
fun PrimaryAndSmallMinimalButtonSheet() {
AppTheme {
AppSurface {
BottomSheetTwoButtons(
onCloseClick = {},
title = "NoButtonBottomSheet",
headerImageResource = ImageResource.Local(R.drawable.ic_blockchain),
subtitle = "NoButtonBottomSheetSubtitle",
button1 = BottomSheetButton(
type = ButtonType.SMALL_MINIMAL,
onClick = {}, text = "Learn More"
),
button2 = BottomSheetButton(
type = ButtonType.PRIMARY,
onClick = {}, text = "Ok"
)
)
}
}
}
2 changes: 1 addition & 1 deletion core/src/main/java/com/blockchain/nabu/UserIdentity.kt
Expand Up @@ -72,5 +72,5 @@ sealed class BlockedReason : Serializable {
data class Unknown(override val message: String) : Sanctions()
}
class TooManyInFlightTransactions(val maxTransactions: Int) : BlockedReason()
class ShouldAcknowledgeStakingWithdrawal(val bondingDays: Int, val assetIconUrl: String) : BlockedReason()
class ShouldAcknowledgeStakingWithdrawal(val assetIconUrl: String) : BlockedReason()
}
Expand Up @@ -32,7 +32,7 @@ class EarnAccessBlockedBottomSheet : ComposeModalBottomDialog() {
showTitleInHeader = false,
subtitle = paragraph,
button1 = BottomSheetButton(
type = ButtonType.MINIMAL,
type = ButtonType.SMALL_MINIMAL,
onClick = {
context.openUrl(LEARN_MORE_URL)
},
Expand All @@ -50,7 +50,7 @@ class EarnAccessBlockedBottomSheet : ComposeModalBottomDialog() {
companion object {
private const val TITLE = "TITLE"
private const val PARAGRAPH = "PARAGRAPH"
private const val LEARN_MORE_URL = "https://www.blockchain.com"
private const val LEARN_MORE_URL = "https://support.blockchain.com/hc/en-us/articles/360018751932"

fun newInstance(title: String, paragraph: String) = EarnAccessBlockedBottomSheet().apply {
arguments = Bundle().apply {
Expand Down
Expand Up @@ -116,6 +116,7 @@ class EarnDashboardFragment :
}
)
)
is EarnDashboardNavigationEvent.OpenUrl -> openExternalUrl(navigationEvent.url)
}

private fun showBlockedAccessSheet(title: String, paragraph: String) {
Expand Down

0 comments on commit e4b3e27

Please sign in to comment.