Skip to content

Commit

Permalink
Update wallet settings
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandarIlic committed Jan 24, 2024
1 parent 01f3ac0 commit 285af9a
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 199 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import net.primal.android.theme.AppTheme
import net.primal.android.theme.PrimalTheme
import net.primal.android.user.domain.Badges

private val NavigationBarFullHeightDp = 64.dp
val NavigationBarFullHeightDp = 64.dp
private val NavigationBarBoltCircleSizeDp = NavigationBarFullHeightDp
private val NavigationBarVisibleHeightDp = 56.dp
private val NavigationBarBoltBorderSpaceDp = 6.dp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ListItem
import androidx.compose.material3.ListItemDefaults
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand All @@ -29,8 +25,6 @@ import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
Expand All @@ -40,82 +34,29 @@ import androidx.compose.ui.unit.sp
import net.primal.android.R
import net.primal.android.core.compose.IconText
import net.primal.android.core.compose.PrimalDivider
import net.primal.android.core.compose.PrimalSwitch
import net.primal.android.core.compose.button.PrimalFilledButton
import net.primal.android.core.compose.button.PrimalLoadingButton
import net.primal.android.theme.AppTheme
import net.primal.android.theme.PrimalTheme
import net.primal.android.theme.domain.PrimalTheme
import net.primal.android.user.domain.NostrWalletConnect
import net.primal.android.user.domain.WalletPreference

@Composable
fun ExternalWalletSettings(
nwcWallet: NostrWalletConnect?,
walletPreference: WalletPreference,
profileLightningAddress: String?,
onUsePrimalWalletSwitchChanged: (Boolean) -> Unit,
onExternalWalletDisconnect: () -> Unit,
onEditProfileClick: () -> Unit,
) {
fun ExternalWalletSettings(nwcWallet: NostrWalletConnect?, onExternalWalletDisconnect: () -> Unit) {
Column(
modifier = Modifier.animateContentSize(),
) {
val primalWalletPreferred = walletPreference != WalletPreference.NostrWalletConnect
ExternalWalletListItem(
preferPrimalWallet = primalWalletPreferred,
onExternalWalletSwitchChanged = onUsePrimalWalletSwitchChanged,
)

if (!primalWalletPreferred) {
Spacer(modifier = Modifier.height(24.dp))

ExternalWalletSection(
nwcWallet = nwcWallet,
onExternalWalletDisconnect = onExternalWalletDisconnect,
)
Spacer(modifier = Modifier.height(16.dp))

Spacer(modifier = Modifier.height(24.dp))
ExternalWalletSection(
nwcWallet = nwcWallet,
onExternalWalletDisconnect = onExternalWalletDisconnect,
)

NostrProfileLightingAddressSection(
lightningAddress = profileLightningAddress,
onEditProfileClick = onEditProfileClick,
)
}
Spacer(modifier = Modifier.height(16.dp))
}
}

@Composable
private fun ExternalWalletListItem(preferPrimalWallet: Boolean, onExternalWalletSwitchChanged: (Boolean) -> Unit) {
ListItem(
modifier = Modifier.clickable {
onExternalWalletSwitchChanged(!preferPrimalWallet)
},
headlineContent = {
Text(
modifier = Modifier.padding(bottom = 4.dp),
text = stringResource(id = R.string.settings_wallet_use_primal_wallet),
style = AppTheme.typography.bodyLarge,
color = AppTheme.colorScheme.onPrimary,
)
},
supportingContent = {
Text(
modifier = Modifier.fillMaxWidth(),
text = stringResource(id = R.string.settings_wallet_use_primal_wallet_hint),
style = AppTheme.typography.bodySmall,
color = AppTheme.extraColorScheme.onSurfaceVariantAlt1,
)
},
trailingContent = {
PrimalSwitch(
checked = preferPrimalWallet,
onCheckedChange = onExternalWalletSwitchChanged,
)
},
)
}

@Composable
private fun ExternalWalletSection(nwcWallet: NostrWalletConnect?, onExternalWalletDisconnect: () -> Unit) {
SectionTitle(
Expand Down Expand Up @@ -292,68 +233,6 @@ fun ConnectMutinyWalletButton(modifier: Modifier = Modifier, onClick: (() -> Uni
}
}

@Composable
private fun NostrProfileLightingAddressSection(lightningAddress: String?, onEditProfileClick: () -> Unit) {
Column {
SectionTitle(
title = stringResource(id = R.string.settings_wallet_nwc_profile_lightning_address),
)

Card(
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
colors = CardDefaults.cardColors(
containerColor = AppTheme.extraColorScheme.surfaceVariantAlt1,
),
) {
ListItem(
modifier = Modifier.clickable { onEditProfileClick() },
colors = ListItemDefaults.colors(
containerColor = AppTheme.extraColorScheme.surfaceVariantAlt1,
),
headlineContent = {
Text(
text = "Address",
style = AppTheme.typography.bodyMedium.copy(fontSize = 16.sp),
)
},
trailingContent = {
Text(
text = lightningAddress ?: "",
style = AppTheme.typography.bodyMedium.copy(fontSize = 16.sp),
)
},
)
}
Text(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp)
.padding(horizontal = 4.dp)
.clickable(
interactionSource = remember { MutableInteractionSource() },
indication = null,
onClick = onEditProfileClick,
),
text = buildAnnotatedString {
append(stringResource(id = R.string.settings_wallet_nwc_profile_lightning_address_hint))
append(
AnnotatedString(
text = " ${
stringResource(id = R.string.settings_wallet_nwc_profile_lightning_address_hint_suffix)
}",
spanStyle = SpanStyle(
color = AppTheme.colorScheme.secondary,
fontStyle = AppTheme.typography.bodySmall.fontStyle,
),
),
)
append(".")
},
style = AppTheme.typography.bodySmall,
)
}
}

@Preview
@Composable
private fun PreviewExternalWalletSettings(
Expand All @@ -365,11 +244,7 @@ private fun PreviewExternalWalletSettings(
Column {
ExternalWalletSettings(
nwcWallet = state.wallet,
walletPreference = state.walletPreference,
profileLightningAddress = state.userLightningAddress,
onUsePrimalWalletSwitchChanged = {},
onExternalWalletDisconnect = {},
onEditProfileClick = {},
)
}
}
Expand Down
Loading

0 comments on commit 285af9a

Please sign in to comment.