From b3ca497454b158a4f79cc9ea4641899ea3e7c50d Mon Sep 17 00:00:00 2001 From: Kristaps Kaupe Date: Tue, 10 Dec 2024 00:26:00 +0200 Subject: [PATCH] Display LND wallet locked error in UI instead of "Starting up" --- src/ui/lightning.zig | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/ui/lightning.zig b/src/ui/lightning.zig index 778931d..4d997a1 100644 --- a/src/ui/lightning.zig +++ b/src/ui/lightning.zig @@ -77,6 +77,7 @@ var tab: struct { // elements visibile during lnd startup. startup: lvgl.FlexLayout, + wallet_locked: lvgl.FlexLayout, // TODO: support wallet manual unlock (LightningError.code.Locked) // elements when lnd wallet is uninitialized. @@ -115,7 +116,7 @@ var tab: struct { preserve_main_active_tab(); } - fn setMode(self: *@This(), m: enum { setup, startup, operational }) void { + fn setMode(self: *@This(), m: enum { setup, startup, wallet_locked, operational }) void { switch (m) { .setup => { self.nowallet.show(); @@ -135,6 +136,16 @@ var tab: struct { self.pairing.hide(); self.reset.hide(); }, + .wallet_locked => { + self.wallet_locked.show(); + self.nowallet.hide(); + self.startup.hide(); + self.info.card.hide(); + self.balance.card.hide(); + self.channels.card.hide(); + self.pairing.hide(); + self.reset.hide(); + }, .operational => { self.info.card.show(); self.balance.card.show(); @@ -174,6 +185,14 @@ pub fn initTabPanel(allocator: std.mem.Allocator, cont: lvgl.Container) !void { _ = btn.on(.click, nm_lnd_setup_click, null); } + // locked wallet state + // TODO: handle this somehow, instead of just printing error + { + tab.wallet_locked = try lvgl.FlexLayout.new(parent, .row, .{ .all = .center }); + tab.wallet_locked.resizeToMax(); + _ = try lvgl.Label.new(tab.wallet_locked, "ERROR: lightning wallet is locked.", .{}); + } + // regular operational mode // info section @@ -266,7 +285,8 @@ pub fn updateTabPanel(msg: comm.Message) !void { return switch (msg) { .lightning_error => |lnerr| switch (lnerr.code) { .uninitialized => tab.setMode(.setup), - // TODO: handle "wallet locked" and other errors + .locked => tab.setMode(.wallet_locked), + // TODO: handle other errors else => tab.setMode(.startup), }, .lightning_report => |rep| blk: {