@@ -6,17 +6,36 @@ class ChannelsPresenter {
66 private let interactor : IChannelsInteractor
77 private let router : IChannelsRouter
88
9+ private var openChannels : [ Lnrpc_Channel ] = [ ]
10+ private var pendingOpenChannels : [ Lnrpc_PendingChannelsResponse . PendingOpenChannel ] = [ ]
11+ private var pendingClosingChannels : [ Lnrpc_PendingChannelsResponse . ClosedChannel ] = [ ]
12+ private var pendingForceClosingChannels : [ Lnrpc_PendingChannelsResponse . ForceClosedChannel ] = [ ]
13+ private var waitingCloseChannels : [ Lnrpc_PendingChannelsResponse . WaitingCloseChannel ] = [ ]
14+
915 init ( interactor: IChannelsInteractor , router: IChannelsRouter ) {
1016 self . interactor = interactor
1117 self . router = router
1218 }
1319
20+ private func syncView( ) {
21+ let factory = ChannelsViewItemFactory ( )
22+
23+ let openChannelViewItems = openChannels. map { factory. viewItem ( channel: $0) }
24+ let pendingOpenChannelViewItems = pendingOpenChannels. map { factory. viewItem ( state: . pendingOpen, pendingChannel: $0. channel) }
25+ let pendingClosingChannelViewItems = pendingClosingChannels. map { factory. viewItem ( state: . pendingClosing, pendingChannel: $0. channel) }
26+ let pendingForceClosingChannelViewItems = pendingForceClosingChannels. map { factory. viewItem ( state: . pendingForceClosing, pendingChannel: $0. channel) }
27+ let waitingCloseChannelViewItems = waitingCloseChannels. map { factory. viewItem ( state: . waitingClose, pendingChannel: $0. channel) }
28+
29+ view? . show ( viewItems: openChannelViewItems + pendingOpenChannelViewItems + pendingClosingChannelViewItems + pendingForceClosingChannelViewItems + waitingCloseChannelViewItems)
30+ }
31+
1432}
1533
1634extension ChannelsPresenter : IChannelsViewDelegate {
1735
1836 func onLoad( ) {
1937 interactor. fetchOpenChannels ( )
38+ interactor. fetchPendingChannels ( )
2039 }
2140
2241 func onClose( ) {
@@ -40,11 +59,16 @@ extension ChannelsPresenter: IChannelsViewDelegate {
4059extension ChannelsPresenter : IChannelsInteractorDelegate {
4160
4261 func didUpdate( openChannels: [ Lnrpc_Channel ] ) {
43- let factory = ChannelsViewItemFactory ( )
44- let viewItems = openChannels. map {
45- factory. viewItem ( channel: $0)
46- }
47- view? . show ( viewItems: viewItems)
62+ self . openChannels = openChannels
63+ syncView ( )
64+ }
65+
66+ func didUpdatePendingChannels( response: Lnrpc_PendingChannelsResponse ) {
67+ self . pendingOpenChannels = response. pendingOpenChannels
68+ self . pendingClosingChannels = response. pendingClosingChannels
69+ self . pendingForceClosingChannels = response. pendingForceClosingChannels
70+ self . waitingCloseChannels = response. waitingCloseChannels
71+ syncView ( )
4872 }
4973
5074}
@@ -53,10 +77,20 @@ class ChannelsViewItemFactory {
5377
5478 func viewItem( channel: Lnrpc_Channel ) -> ChannelViewItem {
5579 ChannelViewItem (
80+ state: . open,
5681 remotePubKey: channel. remotePubkey,
5782 localBalance: Int ( channel. localBalance) ,
5883 remoteBalance: Int ( channel. remoteBalance)
5984 )
6085 }
6186
87+ func viewItem( state: ChannelViewItem . State , pendingChannel: Lnrpc_PendingChannelsResponse . PendingChannel ) -> ChannelViewItem {
88+ ChannelViewItem (
89+ state: state,
90+ remotePubKey: pendingChannel. remoteNodePub,
91+ localBalance: Int ( pendingChannel. localBalance) ,
92+ remoteBalance: Int ( pendingChannel. remoteBalance)
93+ )
94+ }
95+
6296}
0 commit comments