-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]> Reviewed-by: William Casarin <[email protected]> Signed-off-by: William Casarin <[email protected]>
- Loading branch information
1 parent
75a9b4d
commit 534969e
Showing
8 changed files
with
243 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// DamusPurpleURL.swift | ||
// damus | ||
// | ||
// Created by Daniel Nogueira on 2024-01-13. | ||
// | ||
|
||
import Foundation | ||
|
||
enum DamusPurpleURL { | ||
case verify_npub(checkout_id: String) | ||
case welcome(checkout_id: String) | ||
case landing | ||
|
||
static func from_url(url: URL) -> DamusPurpleURL? { | ||
guard let components = URLComponents(url: url, resolvingAgainstBaseURL: false) else { return nil } | ||
guard components.scheme == "damus" else { return nil } | ||
switch components.path { | ||
case "purple:verify": | ||
guard let checkout_id: String = components.queryItems?.first(where: { $0.name == "id" })?.value else { return nil } | ||
return .verify_npub(checkout_id: checkout_id) | ||
case "purple:welcome": | ||
guard let checkout_id: String = components.queryItems?.first(where: { $0.name == "id" })?.value else { return nil } | ||
return .welcome(checkout_id: checkout_id) | ||
case "purple:landing": | ||
return .landing | ||
default: | ||
return nil | ||
} | ||
} | ||
|
||
func url_string() -> String { | ||
switch self { | ||
case .verify_npub(let id): | ||
return "damus:purple:verify?id=\(id)" | ||
case .welcome(let id): | ||
return "damus:purple:welcome?id=\(id)" | ||
case .landing: | ||
return "damus:purple:landing" | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// DamusPurpleURLSheetView.swift | ||
// damus | ||
// | ||
// Created by Daniel D’Aquino 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")) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// DamusPurpleVerifyNpubView.swift | ||
// damus | ||
// | ||
// Created by Daniel D’Aquino 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") | ||
} |
Oops, something went wrong.