@@ -21,6 +21,7 @@ struct AccountRootView: View {
2121 let navigate : ( AccountNavigationPath ) -> Void
2222 let logout : ( ) -> Void
2323 let api : SdkApi
24+ let urApiService : UrApiServiceProtocol
2425 let networkName : String ?
2526 let meanReliabilityWeight : Double
2627 let isPro : Bool
@@ -48,6 +49,7 @@ struct AccountRootView: View {
4849 navigate: @escaping ( AccountNavigationPath ) -> Void ,
4950 logout: @escaping ( ) -> Void ,
5051 api: SdkApi ,
52+ urApiService: UrApiServiceProtocol ,
5153 referralLinkViewModel: ReferralLinkViewModel ,
5254 accountPaymentsViewModel: AccountPaymentsViewModel ,
5355 networkName: String ? ,
@@ -57,6 +59,7 @@ struct AccountRootView: View {
5759 self . navigate = navigate
5860 self . logout = logout
5961 self . api = api
62+ self . urApiService = urApiService
6063
6164 self . referralLinkViewModel = referralLinkViewModel
6265 self . accountPaymentsViewModel = accountPaymentsViewModel
@@ -69,16 +72,14 @@ struct AccountRootView: View {
6972 var body : some View {
7073
7174 let isGuest = deviceManager. parsedJwt? . guestMode ?? true
72-
75+
7376 ScrollView {
7477
7578 HStack {
7679
7780 Spacer ( minLength: 0 )
7881
7982 VStack {
80-
81- // Spacer().frame(height: 16)
8283
8384 VStack ( alignment: . leading, spacing: 0 ) {
8485
@@ -119,23 +120,33 @@ struct AccountRootView: View {
119120
120121 }
121122
122- if ( !isPro) {
123-
124- Spacer ( ) . frame ( height: 8 )
123+ Spacer ( ) . frame ( height: 8 )
124+
125+ /**
126+ * only display usage bar to users with basic plans
127+ */
128+
129+ UsageBar (
130+ availableByteCount: subscriptionBalanceViewModel. availableByteCount,
131+ pendingByteCount: subscriptionBalanceViewModel. pendingByteCount,
132+ usedByteCount: subscriptionBalanceViewModel. usedBalanceByteCount,
133+ meanReliabilityWeight: meanReliabilityWeight,
134+ totalReferrals: referralLinkViewModel. totalReferrals
135+ )
136+
137+ HStack {
125138
126- /**
127- * only display usage bar to users with basic plans
128- */
139+ Spacer ( )
129140
130- UsageBar (
131- availableByteCount: subscriptionBalanceViewModel. availableByteCount,
132- pendingByteCount: subscriptionBalanceViewModel. pendingByteCount,
133- usedByteCount: subscriptionBalanceViewModel. usedBalanceByteCount,
134- meanReliabilityWeight: meanReliabilityWeight,
135- totalReferrals: referralLinkViewModel. totalReferrals
136- )
141+ Button ( action: {
142+ viewModel. isPresentedRedeemBalanceCodeSheet = true
143+ } ) {
144+ Text ( " Redeem Balance Code " )
145+ . font ( themeManager. currentTheme. secondaryBodyFont)
146+ }
137147
138148 }
149+
139150
140151 Divider ( )
141152 . background ( themeManager. currentTheme. borderBaseColor)
@@ -170,9 +181,6 @@ struct AccountRootView: View {
170181 . background ( themeManager. currentTheme. tintedBackgroundBase)
171182 . cornerRadius ( 12 )
172183 . padding ( )
173- // .padding(.horizontal)
174-
175- // Spacer().frame(height: 16)
176184
177185 /**
178186 * Navigation items
@@ -361,6 +369,42 @@ struct AccountRootView: View {
361369 await subscriptionBalanceViewModel. fetchSubscriptionBalance ( )
362370 }
363371 }
372+ . sheet ( isPresented: $viewModel. isPresentedRedeemBalanceCodeSheet) {
373+
374+ VStack {
375+
376+ RedeemBalanceCodeSheet (
377+ closeSheet: {
378+ viewModel. isPresentedRedeemBalanceCodeSheet = false
379+ } ,
380+ onSuccess: {
381+
382+ viewModel. isPresentedRedeemBalanceCodeSheet = false
383+
384+ // start polling
385+ subscriptionBalanceViewModel. startPolling ( )
386+
387+ Task {
388+ // Wait approx. 300ms for the sheet to animate out and keyboard to dismiss
389+ try ? await Task . sleep ( for: . milliseconds( 300 ) )
390+ viewModel. balanceCodeRedeemed = true
391+ }
392+ } ,
393+ api: urApiService
394+ )
395+
396+ }
397+ . background ( themeManager. currentTheme. backgroundColor)
398+
399+ }
400+ . sheet ( isPresented: $viewModel. balanceCodeRedeemed) {
401+ PurchaseSuccessView ( dismiss: {
402+ viewModel. balanceCodeRedeemed = false
403+ } )
404+ . transition ( . opacity)
405+ . frame ( maxWidth: . infinity)
406+ . ignoresSafeArea ( )
407+ }
364408 . sheet ( isPresented: $viewModel. isPresentedUpgradeSheet) {
365409 UpgradeSubscriptionSheet (
366410 monthlyProduct: subscriptionManager. monthlySubscription,
@@ -447,6 +491,7 @@ struct AccountRootView: View {
447491 }
448492 }
449493 #endif
494+
450495 }
451496
452497 private func handleSuccessWithJwt( _ jwt: String ) async {
@@ -478,7 +523,6 @@ struct AccountRootView: View {
478523 print ( " handleSuccessWithJwt error is \( error) " )
479524 }
480525
481-
482526 }
483527
484528}
0 commit comments