lnlink

iOS app for connecting to lightning nodes
git clone git://jb55.com/lnlink
Log | Files | Refs | Submodules | README | LICENSE

commit f00d156d0f5c30046a74d54bac123763a7e1d729
parent d7a51217e36d3a3c6d490a49c2e736d4f3528691
Author: William Casarin <jb55@jb55.com>
Date:   Sat,  5 Mar 2022 09:43:23 -0800

switch_state to simplify payview state changes

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mlightninglink/Views/PayView.swift | 14++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/lightninglink/Views/PayView.swift b/lightninglink/Views/PayView.swift @@ -155,13 +155,17 @@ struct PayView: View { } } + func switch_state(_ state: PayState) { + self.state = state + handle_state_change() + } + func handle_state_change() { switch self.state { case .ready: break case .initial: - self.state = .decoding(nil, self.init_invoice_str) - handle_state_change() + switch_state(.decoding(nil, self.init_invoice_str)) case .decoding(let ln, let inv): DispatchQueue.global(qos: .background).async { self.handle_decode(ln, inv: inv) @@ -181,8 +185,7 @@ struct PayView: View { case .failure(let err): self.error = err.description case .success(let fetch_invoice): - self.state = .decoding(ln, fetch_invoice.invoice) - handle_state_change() + switch_state(.decoding(ln, fetch_invoice.invoice)) } } @@ -206,8 +209,7 @@ struct PayView: View { case .left(let err): self.error = err case .right(let req): - self.state = .fetch_invoice(ln, req) - handle_state_change() + switch_state(.fetch_invoice(ln, req)) } } else if decoded.type == "bolt11 invoice" || decoded.type == "bolt12 invoice" { var amount: InvoiceAmount = .any