@@ -22,20 +22,26 @@ import androidx.compose.foundation.verticalScroll
2222import androidx.compose.material.icons.Icons
2323import androidx.compose.material.icons.filled.ArrowOutward
2424import androidx.compose.material.icons.filled.LocationOn
25+ import androidx.compose.material3.Button
2526import androidx.compose.material3.CircularProgressIndicator
2627import androidx.compose.material3.ExperimentalMaterial3Api
2728import androidx.compose.material3.HorizontalDivider
2829import androidx.compose.material3.Icon
2930import androidx.compose.material3.MaterialTheme
3031import androidx.compose.material3.Scaffold
3132import androidx.compose.material3.Text
33+ import androidx.compose.material3.TextButton
3234import androidx.compose.material3.pulltorefresh.PullToRefreshBox
3335import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState
36+ import androidx.compose.material3.rememberModalBottomSheetState
3437import androidx.compose.runtime.Composable
3538import androidx.compose.runtime.LaunchedEffect
3639import androidx.compose.runtime.collectAsState
3740import androidx.compose.runtime.getValue
41+ import androidx.compose.runtime.mutableStateOf
42+ import androidx.compose.runtime.remember
3843import androidx.compose.runtime.rememberCoroutineScope
44+ import androidx.compose.runtime.setValue
3945import androidx.compose.ui.Alignment
4046import androidx.compose.ui.Modifier
4147import androidx.compose.ui.platform.LocalContext
@@ -55,6 +61,7 @@ import com.bringyour.network.ui.components.AccountSwitcher
5561import com.bringyour.network.ui.components.LoginMode
5662import com.bringyour.network.ui.components.UsageBar
5763import com.bringyour.network.ui.components.overlays.OverlayMode
64+ import com.bringyour.network.ui.components.redeemTransferBalanceCode.RedeemTransferBalanceCodeSheet
5865import com.bringyour.network.ui.shared.viewmodels.OverlayViewModel
5966import com.bringyour.network.ui.shared.viewmodels.Plan
6067import com.bringyour.network.ui.shared.viewmodels.PlanViewModel
@@ -67,6 +74,8 @@ import com.bringyour.network.ui.theme.TextMuted
6774import com.bringyour.network.ui.theme.URNetworkTheme
6875import com.bringyour.network.utils.formatDecimalString
6976import kotlinx.coroutines.CoroutineScope
77+ import kotlinx.coroutines.delay
78+ import kotlinx.coroutines.launch
7079
7180@OptIn(ExperimentalMaterial3Api ::class )
7281@Composable
@@ -93,6 +102,9 @@ fun AccountScreen(
93102
94103 val refreshState = rememberPullToRefreshState()
95104
105+ var isPresentingRedeemTransferBalanceSheet by remember { mutableStateOf(false ) }
106+ val redeemTransferBalanceSheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true )
107+
96108 LaunchedEffect (Unit ) {
97109 subscriptionBalanceViewModel.fetchSubscriptionBalance()
98110 }
@@ -136,11 +148,28 @@ fun AccountScreen(
136148 pendingBytes = subscriptionBalanceViewModel.pendingBalanceByteCount,
137149 availableBytes = availableBalanceByteCount,
138150 totalReferrals = totalReferrals,
139- meanReliabilityWeight = meanReliabilityWeight
151+ meanReliabilityWeight = meanReliabilityWeight,
152+ launchRedeemTransferBalanceCodeSheet = {
153+ isPresentingRedeemTransferBalanceSheet = true
154+ }
140155 )
141156 }
142157 }
143158 }
159+
160+ if (isPresentingRedeemTransferBalanceSheet) {
161+ RedeemTransferBalanceCodeSheet (
162+ sheetState = redeemTransferBalanceSheetState,
163+ setIsPresenting = {
164+ isPresentingRedeemTransferBalanceSheet = it
165+ },
166+ onSuccess = {
167+ subscriptionBalanceViewModel.pollSubscriptionBalance()
168+ overlayViewModel.launch(OverlayMode .Upgrade )
169+ }
170+ )
171+ }
172+
144173 }
145174}
146175
@@ -165,6 +194,7 @@ fun AccountScreenContent(
165194 pendingBytes : Long ,
166195 totalReferrals : Long ,
167196 meanReliabilityWeight : Double ,
197+ launchRedeemTransferBalanceCodeSheet : () -> Unit
168198) {
169199
170200 val context = LocalContext .current
@@ -227,18 +257,30 @@ fun AccountScreenContent(
227257 navController = navController
228258 )
229259
230- if (currentPlan != Plan . Supporter ) {
260+ Spacer (modifier = Modifier .height( 12 .dp))
231261
232- Spacer (modifier = Modifier .height(12 .dp))
262+ UsageBar (
263+ usedBytes = usedBytes,
264+ pendingBytes = pendingBytes,
265+ availableBytes = availableBytes,
266+ totalReferrals = totalReferrals,
267+ meanReliabilityWeight = meanReliabilityWeight
268+ )
269+
270+ Spacer (modifier = Modifier .height(8 .dp))
233271
234- UsageBar (
235- usedBytes = usedBytes,
236- pendingBytes = pendingBytes,
237- availableBytes = availableBytes,
238- totalReferrals = totalReferrals,
239- meanReliabilityWeight = meanReliabilityWeight
272+ Row (
273+ modifier = Modifier
274+ .fillMaxWidth(),
275+ horizontalArrangement = Arrangement .End
276+ ) {
277+ Text (
278+ stringResource(id = R .string.redeem_balance_code),
279+ style = TextStyle (color = BlueMedium ),
280+ modifier = Modifier .clickable {
281+ launchRedeemTransferBalanceCodeSheet()
282+ }
240283 )
241-
242284 }
243285
244286 Spacer (modifier = Modifier .height(16 .dp))
@@ -453,7 +495,8 @@ private fun AccountSupporterAuthenticatedPreview() {
453495 isPollingSubscriptionBalance = false ,
454496 currentStore = null ,
455497 totalReferrals = 1 ,
456- meanReliabilityWeight = 0.1
498+ meanReliabilityWeight = 0.1 ,
499+ launchRedeemTransferBalanceCodeSheet = {}
457500 )
458501 }
459502 }
@@ -497,7 +540,8 @@ private fun AccountBasicAuthenticatedPreview() {
497540 isPollingSubscriptionBalance = false ,
498541 currentStore = null ,
499542 totalReferrals = 1 ,
500- meanReliabilityWeight = 0.1
543+ meanReliabilityWeight = 0.1 ,
544+ launchRedeemTransferBalanceCodeSheet = {}
501545 )
502546 }
503547 }
@@ -540,7 +584,8 @@ private fun AccountGuestPreview() {
540584 isPollingSubscriptionBalance = false ,
541585 currentStore = null ,
542586 totalReferrals = 1 ,
543- meanReliabilityWeight = 0.1
587+ meanReliabilityWeight = 0.1 ,
588+ launchRedeemTransferBalanceCodeSheet = {}
544589 )
545590 }
546591 }
@@ -582,7 +627,8 @@ private fun AccountGuestNoWalletPreview() {
582627 isPollingSubscriptionBalance = false ,
583628 currentStore = null ,
584629 totalReferrals = 1 ,
585- meanReliabilityWeight = 0.1
630+ meanReliabilityWeight = 0.1 ,
631+ launchRedeemTransferBalanceCodeSheet = {}
586632 )
587633 }
588634 }
0 commit comments