Pending Zaps

A fairly large change that replaces Zaps in the codebase with "Zapping"
which is a tagged union consisting of a resolved Zap and a Pending Zap.
These are both counted as Zaps everywhere in Damus, except pending zaps
can be cancelled (most of the time).
This commit is contained in:
William Casarin
2023-05-13 21:33:34 -07:00
parent 1518a0a16c
commit 03691d0369
24 changed files with 738 additions and 179 deletions

View File

@@ -181,7 +181,9 @@ struct TextEvent: View {
VStack(alignment: .leading) {
TopPart(is_anon: is_anon)
ReplyPart
if !options.contains(.no_replying_to) {
ReplyPart
}
EvBody(options: self.options)

View File

@@ -9,30 +9,30 @@ import SwiftUI
struct ZapEvent: View {
let damus: DamusState
let zap: Zap
let zap: Zapping
var body: some View {
VStack(alignment: .leading) {
HStack(alignment: .center) {
Text("⚡️ \(format_msats(zap.invoice.amount))", comment: "Text indicating the zap amount. i.e. number of satoshis that were tipped to a user")
Text("⚡️ \(format_msats(zap.amount))", comment: "Text indicating the zap amount. i.e. number of satoshis that were tipped to a user")
.font(.headline)
.padding([.top], 2)
if zap.private_request != nil {
if zap.is_private {
Image(systemName: "lock.fill")
.foregroundColor(DamusColors.green)
.help(NSLocalizedString("Only you can see this message and who sent it.", comment: "Help text on green lock icon that explains that only the current user can see the message of a zap event and who sent the zap."))
}
if zap.is_pending {
Image(systemName: "clock.arrow.circlepath")
.foregroundColor(DamusColors.yellow)
.help(NSLocalizedString("Only you can see this message and who sent it.", comment: "Help text on green lock icon that explains that only the current user can see the message of a zap event and who sent the zap."))
}
}
if let priv = zap.private_request {
TextEvent(damus: damus, event: priv, pubkey: priv.pubkey, options: [.no_action_bar, .no_replying_to])
.padding([.top], 1)
} else {
TextEvent(damus: damus, event: zap.request.ev, pubkey: zap.request.ev.pubkey, options: [.no_action_bar, .no_replying_to])
.padding([.top], 1)
}
TextEvent(damus: damus, event: zap.request, pubkey: zap.request.pubkey, options: [.no_action_bar, .no_replying_to])
.padding([.top], 1)
}
}
}
@@ -45,12 +45,14 @@ let test_zap = Zap(event: test_event, invoice: test_zap_invoice, zapper: "zapper
let test_private_zap = Zap(event: test_event, invoice: test_zap_invoice, zapper: "zapper", target: .profile("pk"), request: test_zap_request, is_anon: false, private_request: test_event)
let test_pending_zap = PendingZap(amount_msat: 10000, target: .note(id: "id", author: "pk"), request: test_zap_request, type: .pub, state: .external(.init(state: .fetching_invoice)))
struct ZapEvent_Previews: PreviewProvider {
static var previews: some View {
VStack {
ZapEvent(damus: test_damus_state(), zap: test_zap)
ZapEvent(damus: test_damus_state(), zap: .zap(test_zap))
ZapEvent(damus: test_damus_state(), zap: test_private_zap)
ZapEvent(damus: test_damus_state(), zap: .zap(test_private_zap))
}
}
}