damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

DamusPurpleVerifyNpubView.swift (3698B)


      1 //
      2 //  DamusPurpleVerifyNpubView.swift
      3 //  damus
      4 //
      5 //  Created by Daniel D’Aquino on 2024-01-13.
      6 //
      7 
      8 import SwiftUI
      9 
     10 struct DamusPurpleVerifyNpubView: View {
     11     let damus_state: DamusState
     12     let checkout_id: String
     13     @State var verified: Bool = false
     14     
     15     let subtitle_height: CGFloat = 100.0
     16 
     17     @Environment(\.openURL) var openURL
     18 
     19     init(damus_state: DamusState, checkout_id: String, verified: Bool = false) {
     20         self.damus_state = damus_state
     21         self.checkout_id = checkout_id
     22         self._verified = State(wrappedValue: verified)
     23     }
     24 
     25     var checkout_url: URL {
     26         let page_url = damus_state.purple.environment.purple_landing_page_url()
     27         return URL(string: "\(page_url)/checkout?id=\(checkout_id)")!
     28     }
     29 
     30     var body: some View {
     31         ZStack {
     32             Rectangle()
     33                 .foregroundStyle(Color.black)
     34                 .background(Color.black)
     35             
     36             VStack {
     37                 DamusPurpleView.LogoView()
     38 
     39                 VStack(alignment: .center, spacing: 30) {
     40 
     41                     if !verified {
     42                         Subtitle(NSLocalizedString("To continue your Purple subscription checkout, please verify your npub by clicking on the button below", comment: "Instruction on how to verify npub during Damus Purple checkout"))
     43 
     44                             .frame(height: subtitle_height)
     45                             .multilineTextAlignment(.center)
     46 
     47                         Button(action: {
     48                             Task {
     49                                 try await damus_state.purple.verify_npub_for_checkout(checkout_id: checkout_id)
     50                                 damus_state.purple.checkout_ids_in_progress.insert(checkout_id)
     51                                 verified = true
     52                             }
     53                         }, label: {
     54                             HStack {
     55                                 Spacer()
     56                                 Text("Verify my npub", comment: "Button label to verify the user's npub for the purpose of Purple subscription checkout")
     57                                 Spacer()
     58                             }
     59                         })
     60                         .padding(.horizontal, 30)
     61                         .buttonStyle(GradientButtonStyle())
     62                     }
     63                     else {
     64                         Text("Verified!", comment: "Instructions after the user has verified their npub for Damus Purple purchase checkout")
     65                                 .frame(height: subtitle_height)
     66                                 .multilineTextAlignment(.center)
     67                                 .foregroundColor(.green)
     68 
     69                         Button(action: {
     70                             openURL(checkout_url)
     71                         }, label: {
     72                             HStack {
     73                                 Spacer()
     74                                 Text("Continue", comment: "Prompt to user to continue")
     75                                 Spacer()
     76                             }
     77                         })
     78                         .padding(.horizontal, 30)
     79                         .buttonStyle(GradientButtonStyle())
     80                     }
     81                     
     82                 }
     83                 .padding([.trailing, .leading], 30)
     84                 .padding(.bottom, 20)
     85             }
     86         }
     87     }
     88         
     89     func Subtitle(_ txt: String) -> some View {
     90         Text(txt)
     91             .foregroundColor(.white.opacity(0.65))
     92     }
     93 }
     94 
     95 #Preview {
     96     VStack(spacing: 0) {
     97         DamusPurpleVerifyNpubView(damus_state: test_damus_state, checkout_id: "123")
     98 
     99         DamusPurpleVerifyNpubView(damus_state: test_damus_state, checkout_id: "123", verified: true)
    100     }
    101 }