purple: add support for LN checkout flow

This commit adds support for the LN checkout flow, and the Purple
landing page:

1. It adds a "learn more" button on the Damus Purple view, where the
   user can learn more
2. It adds new `damus:purple` urls to enable the LN checkout flow

Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
Daniel D’Aquino
2024-01-14 21:55:04 +00:00
committed by William Casarin
parent 75a9b4df7f
commit 534969e616
8 changed files with 243 additions and 35 deletions

View File

@@ -0,0 +1,34 @@
//
// DamusPurpleURLSheetView.swift
// damus
//
// Created by Daniel DAquino on 2024-01-13.
//
import Foundation
import SwiftUI
struct DamusPurpleURLSheetView: View {
@Environment(\.dismiss) var dismiss
let damus_state: DamusState
let purple_url: DamusPurpleURL
var body: some View {
switch self.purple_url {
case .verify_npub(let checkout_id):
DamusPurpleVerifyNpubView(damus_state: damus_state, checkout_id: checkout_id)
case .welcome(_):
DamusPurpleWelcomeView()
case .landing:
DamusPurpleView(damus_state: damus_state)
}
}
}
struct DamusPurpleURLSheetView_Previews: PreviewProvider {
static var previews: some View {
DamusPurpleURLSheetView(damus_state: test_damus_state, purple_url: .verify_npub(checkout_id: "123"))
}
}

View File

@@ -0,0 +1,64 @@
//
// DamusPurpleVerifyNpubView.swift
// damus
//
// Created by Daniel DAquino on 2024-01-13.
//
import SwiftUI
struct DamusPurpleVerifyNpubView: View {
let damus_state: DamusState
let checkout_id: String
@State var verified: Bool = false
var body: some View {
ZStack {
Rectangle()
.background(Color.black)
VStack {
DamusPurpleLogoView()
VStack(alignment: .center, spacing: 30) {
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"))
.multilineTextAlignment(.center)
if !verified {
Button(action: {
Task {
try await damus_state.purple.verify_npub_for_checkout(checkout_id: checkout_id)
verified = true
}
}, label: {
HStack {
Spacer()
Text(NSLocalizedString("Verify my npub", comment: "Button label to verify the user's npub for the purpose of Purple subscription checkout"))
Spacer()
}
})
.padding(.horizontal, 30)
.buttonStyle(GradientButtonStyle())
}
else {
Text(NSLocalizedString("Verified! Please head back to the checkout page to continue", comment: "Instructions after the user has verified their npub for Damus Purple purchase checkout"))
.multilineTextAlignment(.center)
.foregroundColor(.green)
}
}
.padding([.trailing, .leading], 30)
.padding(.bottom, 20)
}
}
}
func Subtitle(_ txt: String) -> some View {
Text(txt)
.foregroundColor(.white.opacity(0.65))
}
}
#Preview {
DamusPurpleVerifyNpubView(damus_state: test_damus_state, checkout_id: "123")
}

View File

@@ -345,35 +345,7 @@ struct DamusPurpleView: View {
var MainContent: some View {
VStack {
HStack(spacing: 20) {
Image("damus-dark-logo")
.resizable()
.frame(width: 60, height: 60)
.clipShape(RoundedRectangle(cornerRadius: 15.0))
.overlay(
RoundedRectangle(cornerRadius: 15)
.stroke(LinearGradient(
colors: [DamusColors.lighterPink.opacity(0.8), .white.opacity(0), DamusColors.deepPurple.opacity(0.6)],
startPoint: .topLeading,
endPoint: .bottomTrailing), lineWidth: 1)
)
.shadow(radius: 5)
VStack(alignment: .leading) {
Text(NSLocalizedString("Purple", comment: "Subscription service name"))
.font(.system(size: 60.0).weight(.bold))
.foregroundStyle(
LinearGradient(
colors: [DamusColors.lighterPink, DamusColors.deepPurple],
startPoint: .bottomLeading,
endPoint: .topTrailing
)
)
.foregroundColor(.white)
.tracking(-2)
}
}
.padding(.bottom, 30)
DamusPurpleLogoView()
VStack(alignment: .leading, spacing: 30) {
Subtitle(NSLocalizedString("Help us stay independent in our mission for Freedom tech with our Purple subscription, and look cool doing it!", comment: "Damus purple subscription pitch"))
@@ -426,6 +398,17 @@ struct DamusPurpleView: View {
}
}
HStack {
Spacer()
Link(
NSLocalizedString("Learn more", comment: "Label for a link to the Damus Purple landing page"),
destination: damus_state.settings.purple_api_local_test_mode ? Constants.PURPLE_LANDING_PAGE_TEST_URL : Constants.PURPLE_LANDING_PAGE_PRODUCTION_URL
)
.foregroundColor(DamusColors.pink)
.padding()
Spacer()
}
}
.padding([.trailing, .leading], 30)
.padding(.bottom, 20)
@@ -441,6 +424,40 @@ struct DamusPurpleView: View {
}
}
struct DamusPurpleLogoView: View {
var body: some View {
HStack(spacing: 20) {
Image("damus-dark-logo")
.resizable()
.frame(width: 60, height: 60)
.clipShape(RoundedRectangle(cornerRadius: 15.0))
.overlay(
RoundedRectangle(cornerRadius: 15)
.stroke(LinearGradient(
colors: [DamusColors.lighterPink.opacity(0.8), .white.opacity(0), DamusColors.deepPurple.opacity(0.6)],
startPoint: .topLeading,
endPoint: .bottomTrailing), lineWidth: 1)
)
.shadow(radius: 5)
VStack(alignment: .leading) {
Text(NSLocalizedString("Purple", comment: "Subscription service name"))
.font(.system(size: 60.0).weight(.bold))
.foregroundStyle(
LinearGradient(
colors: [DamusColors.lighterPink, DamusColors.deepPurple],
startPoint: .bottomLeading,
endPoint: .topTrailing
)
)
.foregroundColor(.white)
.tracking(-2)
}
}
.padding(.bottom, 30)
}
}
struct DamusPurpleView_Previews: PreviewProvider {
static var previews: some View {
/*