zap: remove unnecessary main thread dispatches when zapping
This commit is contained in:
@@ -183,39 +183,24 @@ func send_zap(damus_state: DamusState, target: ZapTarget, lnurl: String, is_cust
|
|||||||
UIImpactFeedbackGenerator(style: .heavy).impactOccurred()
|
UIImpactFeedbackGenerator(style: .heavy).impactOccurred()
|
||||||
damus_state.add_zap(zap: .pending(pending_zap))
|
damus_state.add_zap(zap: .pending(pending_zap))
|
||||||
|
|
||||||
Task {
|
Task { @MainActor in
|
||||||
var mpayreq = damus_state.lnurls.lookup(target.pubkey)
|
guard let payreq = await damus_state.lnurls.lookup_or_fetch(pubkey: target.pubkey, lnurl: lnurl) else {
|
||||||
if mpayreq == nil {
|
|
||||||
mpayreq = await fetch_static_payreq(lnurl)
|
|
||||||
}
|
|
||||||
|
|
||||||
guard let payreq = mpayreq else {
|
|
||||||
// TODO: show error
|
// TODO: show error
|
||||||
DispatchQueue.main.async {
|
|
||||||
remove_zap(reqid: reqid, zapcache: damus_state.zaps, evcache: damus_state.events)
|
remove_zap(reqid: reqid, zapcache: damus_state.zaps, evcache: damus_state.events)
|
||||||
let typ = ZappingEventType.failed(.bad_lnurl)
|
let typ = ZappingEventType.failed(.bad_lnurl)
|
||||||
let ev = ZappingEvent(is_custom: is_custom, type: typ, target: target)
|
let ev = ZappingEvent(is_custom: is_custom, type: typ, target: target)
|
||||||
notify(.zapping, ev)
|
notify(.zapping, ev)
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
damus_state.lnurls.endpoints[target.pubkey] = payreq
|
|
||||||
}
|
|
||||||
|
|
||||||
guard let inv = await fetch_zap_invoice(payreq, zapreq: zapreq, msats: amount_msat, zap_type: zap_type, comment: comment) else {
|
guard let inv = await fetch_zap_invoice(payreq, zapreq: zapreq, msats: amount_msat, zap_type: zap_type, comment: comment) else {
|
||||||
DispatchQueue.main.async {
|
|
||||||
remove_zap(reqid: reqid, zapcache: damus_state.zaps, evcache: damus_state.events)
|
remove_zap(reqid: reqid, zapcache: damus_state.zaps, evcache: damus_state.events)
|
||||||
let typ = ZappingEventType.failed(.fetching_invoice)
|
let typ = ZappingEventType.failed(.fetching_invoice)
|
||||||
let ev = ZappingEvent(is_custom: is_custom, type: typ, target: target)
|
let ev = ZappingEvent(is_custom: is_custom, type: typ, target: target)
|
||||||
notify(.zapping, ev)
|
notify(.zapping, ev)
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
|
|
||||||
switch pending_zap_state {
|
switch pending_zap_state {
|
||||||
case .nwc(let nwc_state):
|
case .nwc(let nwc_state):
|
||||||
// don't both continuing, user has canceled
|
// don't both continuing, user has canceled
|
||||||
@@ -268,7 +253,6 @@ func send_zap(damus_state: DamusState, target: ZapTarget, lnurl: String, is_cust
|
|||||||
notify(.zapping, ev)
|
notify(.zapping, ev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user