Skip to content

Commit 9d06fdc

Browse files
committed
Initial implementation of handling status in Main module
- new UnlockRemoteWallet module for entering password and sending unlock request - disable lightning related buttons when there is no connection or remote node is locked
1 parent 4cd32d8 commit 9d06fdc

File tree

10 files changed

+410
-64
lines changed

10 files changed

+410
-64
lines changed

LightningWallet.xcodeproj/project.pbxproj

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
11B3512C91713EAFE1CD93A7 /* UnlockRemoteWalletInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B3517F5046A8D7084A3D38 /* UnlockRemoteWalletInteractor.swift */; };
11+
11B352A385C46F9049C0D162 /* UnlockRemoteWalletModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B3579E26E352DE2E1DA3C4 /* UnlockRemoteWalletModule.swift */; };
1012
11B354E4DC19B8DE6D3CC60C /* LightningKitManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B3526153DCFD79445635FF /* LightningKitManager.swift */; };
1113
11B3559BE9692AA8E2CF2E02 /* WalletManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B3503363C680E524222463 /* WalletManager.swift */; };
1214
11B3567690C34D551ED17F3E /* ChannelsInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B3569E8DB04902BB82E20D /* ChannelsInteractor.swift */; };
1315
11B3572B6548AD2B3CAEBF35 /* WalletStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35D5AD19EEEB6AD76D086 /* WalletStorage.swift */; };
16+
11B358EBCC1064B326CDD476 /* UnlockRemoteWalletPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35F7C6336D876A46A7B4E /* UnlockRemoteWalletPresenter.swift */; };
1417
11B35BC8B9EDDF3C8F158687 /* KeychainKitDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B350CF6EBC2880C8A58C3E /* KeychainKitDelegate.swift */; };
1518
11B35C1B600F9D1C84621799 /* LightningConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B350954D6814C2AF78F05A /* LightningConnection.swift */; };
1619
11B35C69E03CA63329DE2B54 /* Wallet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35B7F6D03B2E09A50BDF2 /* Wallet.swift */; };
20+
11B35CB149B637ADE486B1C4 /* UnlockRemoteWalletViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35DB1275B5826DE97F312 /* UnlockRemoteWalletViewController.swift */; };
1721
11B35D787EBE3BE258AA71CC /* ChannelCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35F643A41FEAF8BE7349A /* ChannelCell.swift */; };
22+
11B35EAC42994082E5716260 /* UnlockRemoteWalletRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B350E2AA22B72F2B3F973D /* UnlockRemoteWalletRouter.swift */; };
1823
1A5640E30DA915800F420D29 /* MainPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A564CD0EBF3E1EE5DD4FEAA /* MainPresenter.swift */; };
1924
1A564134A2FD92B7E701F2CD /* ChannelsModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A564C3A195D3FEC236F1FE8 /* ChannelsModule.swift */; };
2025
1A56435C0BAF49254EC66D56 /* ChannelsRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A564BF99757F8D9D2058245 /* ChannelsRouter.swift */; };
@@ -106,11 +111,16 @@
106111
11B3503363C680E524222463 /* WalletManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WalletManager.swift; sourceTree = "<group>"; };
107112
11B350954D6814C2AF78F05A /* LightningConnection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LightningConnection.swift; sourceTree = "<group>"; };
108113
11B350CF6EBC2880C8A58C3E /* KeychainKitDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeychainKitDelegate.swift; sourceTree = "<group>"; };
114+
11B350E2AA22B72F2B3F973D /* UnlockRemoteWalletRouter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UnlockRemoteWalletRouter.swift; sourceTree = "<group>"; };
115+
11B3517F5046A8D7084A3D38 /* UnlockRemoteWalletInteractor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UnlockRemoteWalletInteractor.swift; sourceTree = "<group>"; };
109116
11B3526153DCFD79445635FF /* LightningKitManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LightningKitManager.swift; sourceTree = "<group>"; };
110117
11B3569E8DB04902BB82E20D /* ChannelsInteractor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChannelsInteractor.swift; sourceTree = "<group>"; };
118+
11B3579E26E352DE2E1DA3C4 /* UnlockRemoteWalletModule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UnlockRemoteWalletModule.swift; sourceTree = "<group>"; };
111119
11B35B7F6D03B2E09A50BDF2 /* Wallet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Wallet.swift; sourceTree = "<group>"; };
112120
11B35D5AD19EEEB6AD76D086 /* WalletStorage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WalletStorage.swift; sourceTree = "<group>"; };
121+
11B35DB1275B5826DE97F312 /* UnlockRemoteWalletViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UnlockRemoteWalletViewController.swift; sourceTree = "<group>"; };
113122
11B35F643A41FEAF8BE7349A /* ChannelCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChannelCell.swift; sourceTree = "<group>"; };
123+
11B35F7C6336D876A46A7B4E /* UnlockRemoteWalletPresenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UnlockRemoteWalletPresenter.swift; sourceTree = "<group>"; };
114124
1A564035CC3574B56BBC1708 /* TransactionViewItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransactionViewItem.swift; sourceTree = "<group>"; };
115125
1A56422F697A9DEEB7DC12A5 /* TransactionsPresenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransactionsPresenter.swift; sourceTree = "<group>"; };
116126
1A564407D57445B9B570FAA1 /* TransactionCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransactionCell.swift; sourceTree = "<group>"; };
@@ -214,6 +224,18 @@
214224
/* End PBXFrameworksBuildPhase section */
215225

216226
/* Begin PBXGroup section */
227+
11B352A823EFB37CA718C197 /* UnlockRemoteWallet */ = {
228+
isa = PBXGroup;
229+
children = (
230+
11B3579E26E352DE2E1DA3C4 /* UnlockRemoteWalletModule.swift */,
231+
11B350E2AA22B72F2B3F973D /* UnlockRemoteWalletRouter.swift */,
232+
11B3517F5046A8D7084A3D38 /* UnlockRemoteWalletInteractor.swift */,
233+
11B35F7C6336D876A46A7B4E /* UnlockRemoteWalletPresenter.swift */,
234+
11B35DB1275B5826DE97F312 /* UnlockRemoteWalletViewController.swift */,
235+
);
236+
path = UnlockRemoteWallet;
237+
sourceTree = "<group>";
238+
};
217239
11B35700569459CC8760F1D4 /* Models */ = {
218240
isa = PBXGroup;
219241
children = (
@@ -349,6 +371,7 @@
349371
58AAADC4308B7119C5E36D54 /* LockScreen */,
350372
1A564F9557C289528B905A6A /* Transactions */,
351373
1A564FECD23B04CF4909666C /* Channels */,
374+
11B352A823EFB37CA718C197 /* UnlockRemoteWallet */,
352375
);
353376
path = Modules;
354377
sourceTree = "<group>";
@@ -674,6 +697,11 @@
674697
58AAA8F9415503EEE4E5554D /* TransparentNavigationBar.swift in Sources */,
675698
11B3567690C34D551ED17F3E /* ChannelsInteractor.swift in Sources */,
676699
11B35D787EBE3BE258AA71CC /* ChannelCell.swift in Sources */,
700+
11B35EAC42994082E5716260 /* UnlockRemoteWalletRouter.swift in Sources */,
701+
11B352A385C46F9049C0D162 /* UnlockRemoteWalletModule.swift in Sources */,
702+
11B358EBCC1064B326CDD476 /* UnlockRemoteWalletPresenter.swift in Sources */,
703+
11B3512C91713EAFE1CD93A7 /* UnlockRemoteWalletInteractor.swift in Sources */,
704+
11B35CB149B637ADE486B1C4 /* UnlockRemoteWalletViewController.swift in Sources */,
677705
);
678706
runOnlyForDeploymentPostprocessing = 0;
679707
};

LightningWallet/Modules/Main/MainModule.swift

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,33 @@ protocol IMainRouter {
66
func openSettings()
77
func openTransactions()
88
func openChannels()
9+
func showUnlock()
910
}
1011

1112
protocol IMainView: class {
1213
func showConnectingStatus()
1314
func showSyncingStatus()
15+
func showUnlockingStatus()
16+
func showLockedStatus()
1417
func showErrorStatus(error: Error)
1518
func hideStatus()
1619

20+
func setUnlockButton(visible: Bool)
21+
1722
func show(totalBalance: Int)
23+
func hideTotalBalance()
24+
25+
func setLightningButtons(enabled: Bool)
1826
}
1927

2028
protocol IMainViewDelegate {
2129
func onLoad()
22-
func onDeposit()
23-
func onSend()
24-
func onChannels()
25-
func onSettings()
26-
func onTransactions()
30+
func onTapUnlock()
31+
func onTapDeposit()
32+
func onTapSend()
33+
func onTapChannels()
34+
func onTapSettings()
35+
func onTapTransactions()
2736
}
2837

2938
protocol IMainInteractor {

LightningWallet/Modules/Main/MainPresenter.swift

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class MainPresenter {
1212

1313
private var walletBalance: Int?
1414
private var channelBalance: Int?
15+
private var status: NodeStatus = .connecting
1516

1617
init(interactor: IMainInteractor, router: IMainRouter, viewFactory: IValueFormatterFactory) {
1718
self.viewFactory = viewFactory
@@ -20,42 +21,76 @@ class MainPresenter {
2021
}
2122

2223
private func syncBalanceView() {
23-
if let walletBalance = walletBalance, let channelBalance = channelBalance {
24+
if (status == .syncing || status == .running), let walletBalance = walletBalance, let channelBalance = channelBalance {
2425
let totalBalance = walletBalance + channelBalance
2526
view?.show(totalBalance: totalBalance)
2627
} else {
27-
// todo
28+
view?.hideTotalBalance()
2829
}
2930
}
3031

32+
private func syncUnlockButton() {
33+
view?.setUnlockButton(visible: status == .locked)
34+
}
35+
36+
private func syncLightningButtons() {
37+
view?.setLightningButtons(enabled: status == .syncing || status == .running)
38+
}
39+
40+
private func syncControls() {
41+
switch status {
42+
case .connecting:
43+
view?.showConnectingStatus()
44+
case .syncing:
45+
view?.showSyncingStatus()
46+
case .error(let error):
47+
view?.showErrorStatus(error: error)
48+
case .running:
49+
view?.hideStatus()
50+
case .unlocking:
51+
view?.showUnlockingStatus()
52+
case .locked:
53+
view?.showLockedStatus()
54+
}
55+
56+
syncBalanceView()
57+
syncLightningButtons()
58+
syncUnlockButton()
59+
}
60+
3161
}
3262

3363
extension MainPresenter: IMainViewDelegate {
3464

3565
func onLoad() {
66+
syncControls()
67+
3668
interactor.subscribeToStatus()
69+
interactor.subscribeToWalletBalance()
70+
interactor.subscribeToChannelBalance()
71+
}
3772

38-
interactor.fetchWalletBalance()
39-
interactor.fetchChannelBalance()
73+
func onTapUnlock() {
74+
router.showUnlock()
4075
}
4176

42-
func onDeposit() {
77+
func onTapDeposit() {
4378
print("onDeposit")
4479
}
4580

46-
func onSend() {
81+
func onTapSend() {
4782
print("onSend")
4883
}
4984

50-
func onChannels() {
85+
func onTapChannels() {
5186
router.openChannels()
5287
}
5388

54-
func onSettings() {
89+
func onTapSettings() {
5590
router.openSettings()
5691
}
5792

58-
func onTransactions() {
93+
func onTapTransactions() {
5994
router.openTransactions()
6095
}
6196

@@ -64,18 +99,12 @@ extension MainPresenter: IMainViewDelegate {
6499
extension MainPresenter: IMainInteractorDelegate {
65100

66101
func didUpdate(status: NodeStatus) {
67-
switch status {
68-
case .connecting:
69-
view?.showConnectingStatus()
70-
case .syncing:
71-
view?.showSyncingStatus()
72-
case .error(let error):
73-
view?.showErrorStatus(error: error)
74-
case .running:
75-
view?.hideStatus()
76-
default:
77-
// todo: handle .locked and .unlocking statuses
78-
view?.hideStatus()
102+
self.status = status
103+
syncControls()
104+
105+
if status == .running || status == .syncing {
106+
interactor.fetchWalletBalance()
107+
interactor.fetchChannelBalance()
79108
}
80109
}
81110

LightningWallet/Modules/Main/MainRouter.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ extension MainRouter: IMainRouter {
2020
viewController?.present(ThemeNavigationController(rootViewController: ChannelsRouter.module()), animated: true)
2121
}
2222

23+
func showUnlock() {
24+
viewController?.present(UnlockRemoteWalletRouter.module(), animated: true)
25+
}
26+
2327
}
2428

2529
extension MainRouter {

0 commit comments

Comments
 (0)