@@ -11,18 +11,25 @@ import { isCompatibleVersion, sortDescByKey } from '../utilities/data-formatters
11
11
import logger from '../services/logger.service' ;
12
12
import { AppContextType } from '../types/app-context.type' ;
13
13
import { ApplicationConfiguration , FiatConfig , WalletConnect } from '../types/app-config.type' ;
14
- import { BkprTransaction , Fund , FundChannel , FundOutput , Invoice , ListBitcoinTransactions , ListInvoices , ListPayments , ListPeers , NodeFeeRate , NodeInfo , Payment , Peer } from '../types/lightning-wallet.type' ;
14
+ import { BkprTransaction , Fund , FundChannel , FundOutput , Invoice , ListBitcoinTransactions , ListInvoices , ListPayments , ListOffers , ListPeers , NodeFeeRate , NodeInfo , Payment , Peer } from '../types/lightning-wallet.type' ;
15
15
16
- const aggregateChannels = ( peers : Peer [ ] ) => {
16
+ const aggregateChannels = ( peers : Peer [ ] , currentVersion : string ) => {
17
17
const aggregatedChannels : any = { activeChannels : [ ] , pendingChannels : [ ] , inactiveChannels : [ ] } ;
18
18
peers ?. forEach ( ( peer : Peer ) => {
19
19
if ( peer . channels && peer . channels . length > 0 ) {
20
20
peer . channels . map ( channel => {
21
21
channel . connected = peer . connected || false ;
22
22
channel . node_alias = peer . alias || peer . id ?. substring ( 0 , 20 ) || '' ;
23
- channel . satoshi_to_us = Math . floor ( ( channel . msatoshi_to_us || channel . to_us_msat || 0 ) / SATS_MSAT ) ;
24
- channel . satoshi_total = Math . floor ( ( channel . msatoshi_total || channel . total_msat || 0 ) / SATS_MSAT ) ;
25
- channel . satoshi_to_them = Math . floor ( ( ( channel . msatoshi_total || channel . total_msat || 0 ) - ( channel . msatoshi_to_us || channel . to_us_msat || 0 ) ) / SATS_MSAT ) ;
23
+ if ( isCompatibleVersion ( currentVersion , '23.02' ) ) {
24
+ channel . satoshi_to_us = Math . floor ( ( channel . msatoshi_to_us || channel . to_us_msat || 0 ) / SATS_MSAT ) ;
25
+ channel . satoshi_total = Math . floor ( ( channel . msatoshi_total || channel . total_msat || 0 ) / SATS_MSAT ) ;
26
+ channel . satoshi_to_them = Math . floor ( ( ( channel . msatoshi_total || channel . total_msat || 0 ) - ( channel . msatoshi_to_us || channel . to_us_msat || 0 ) ) / SATS_MSAT ) ;
27
+ } else {
28
+ channel . satoshi_to_us = Math . floor ( ( channel . msatoshi_to_us || 0 ) / SATS_MSAT ) ;
29
+ channel . satoshi_total = Math . floor ( ( channel . msatoshi_total || 0 ) / SATS_MSAT ) ;
30
+ channel . satoshi_to_them = Math . floor ( ( ( channel . msatoshi_total || 0 ) - ( channel . msatoshi_to_us || 0 ) ) / SATS_MSAT ) ;
31
+ }
32
+
26
33
if ( channel . state === 'CHANNELD_NORMAL' ) {
27
34
if ( channel . connected ) {
28
35
channel . current_state = 'ACTIVE' ;
@@ -164,13 +171,13 @@ const calculateBalances = (listFunds: Fund) => {
164
171
return walletBalances ;
165
172
} ;
166
173
167
- const filterOnChainTransactions = ( events : BkprTransaction [ ] , state ) => {
174
+ const filterOnChainTransactions = ( events : BkprTransaction [ ] , currentVersion : string ) => {
168
175
if ( ! events ) {
169
176
return [ ] ;
170
177
} else {
171
178
return events . reduce ( ( acc : any [ ] , event , i ) => {
172
179
if ( event . account === 'wallet' && ( event . tag === 'deposit' || event . tag === 'withdrawal' ) ) {
173
- if ( isCompatibleVersion ( state . nodeInfo . version , '23.02' ) ) {
180
+ if ( isCompatibleVersion ( currentVersion , '23.02' ) ) {
174
181
event . credit_msat = event . credit_msat || 0 ;
175
182
event . debit_msat = event . debit_msat || 0 ;
176
183
} else {
@@ -202,6 +209,7 @@ const AppContext = React.createContext<AppContextType>({
202
209
listChannels : { isLoading : true , activeChannels : [ ] , pendingChannels : [ ] , inactiveChannels : [ ] } ,
203
210
listInvoices : { isLoading : true , invoices : [ ] } ,
204
211
listPayments : { isLoading : true , payments : [ ] } ,
212
+ listOffers : { isLoading : true , offers : [ ] } ,
205
213
listLightningTransactions : { isLoading : true , clnTransactions : [ ] } ,
206
214
listBitcoinTransactions : { isLoading : true , btcTransactions : [ ] } ,
207
215
walletBalances : { isLoading : true , clnLocalBalance : 0 , clnRemoteBalance : 0 , clnPendingBalance : 0 , clnInactiveBalance : 0 , btcSpendableBalance : 0 , btcReservedBalance : 0 } ,
@@ -216,6 +224,7 @@ const AppContext = React.createContext<AppContextType>({
216
224
setListPeers : ( peersList : ListPeers ) => { } ,
217
225
setListInvoices : ( invoicesList : ListInvoices ) => { } ,
218
226
setListPayments : ( paymentsList : ListPayments ) => { } ,
227
+ setListOffers : ( offersList : ListOffers ) => { } ,
219
228
setListBitcoinTransactions : ( transactionsList : ListBitcoinTransactions ) => { } ,
220
229
setStore : ( storeData ) => { } ,
221
230
clearStore : ( ) => { }
@@ -234,6 +243,7 @@ const defaultAppState = {
234
243
listChannels : { isLoading : true , activeChannels : [ ] , pendingChannels : [ ] , inactiveChannels : [ ] } ,
235
244
listInvoices : { isLoading : true , invoices : [ ] } ,
236
245
listPayments : { isLoading : true , payments : [ ] } ,
246
+ listOffers : { isLoading : true , offers : [ ] } ,
237
247
listLightningTransactions : { isLoading : true , clnTransactions : [ ] } ,
238
248
listBitcoinTransactions : { isLoading : true , btcTransactions : [ ] } ,
239
249
walletBalances : { isLoading : true , clnLocalBalance : 0 , clnRemoteBalance : 0 , clnPendingBalance : 0 , clnInactiveBalance : 0 , btcSpendableBalance : 0 , btcReservedBalance : 0 }
@@ -256,6 +266,7 @@ const appReducer = (state, action) => {
256
266
} ;
257
267
258
268
case ApplicationActions . SET_WALLET_CONNECT :
269
+ action . payload . TOR_DOMAIN_NAME = action . payload . TOR_HOST ?. replace ( 'https://' , '' ) . replace ( 'http://' , '' ) ;
259
270
return {
260
271
...state ,
261
272
walletConnect : action . payload
@@ -294,7 +305,7 @@ const appReducer = (state, action) => {
294
305
} ;
295
306
296
307
case ApplicationActions . SET_LIST_PEERS :
297
- let filteredChannels = aggregateChannels ( action . payload . peers ) ;
308
+ let filteredChannels = aggregateChannels ( action . payload . peers , state . nodeInfo . version ) ;
298
309
return {
299
310
...state ,
300
311
listChannels : { ...filteredChannels , isLoading : false , error : action . payload . error } ,
@@ -338,9 +349,15 @@ const appReducer = (state, action) => {
338
349
listPayments : { ...action . payload , payments : sortedPayments }
339
350
} ;
340
351
352
+ case ApplicationActions . SET_LIST_OFFERS :
353
+ return {
354
+ ...state ,
355
+ listOffers : action . payload
356
+ } ;
357
+
341
358
case ApplicationActions . SET_LIST_BITCOIN_TRANSACTIONS :
342
359
const sortedTransactions = action . payload . events ?. sort ( ( t1 : BkprTransaction , t2 : BkprTransaction ) => ( ( t1 . timestamp && t2 . timestamp && t1 . timestamp > t2 . timestamp ) ? - 1 : 1 ) ) ;
343
- const filteredTransactions = filterOnChainTransactions ( sortedTransactions , state ) ;
360
+ const filteredTransactions = filterOnChainTransactions ( sortedTransactions , state . nodeInfo . version ) ;
344
361
return {
345
362
...state ,
346
363
listBitcoinTransactions : { isLoading : false , error : action . payload . error , btcTransactions : filteredTransactions } ,
@@ -404,6 +421,10 @@ const AppProvider: React.PropsWithChildren<any> = (props) => {
404
421
dispatchApplicationAction ( { type : ApplicationActions . SET_LIST_SEND_PAYS , payload : list } ) ;
405
422
} ;
406
423
424
+ const setListOffersHandler = ( list : ListOffers ) => {
425
+ dispatchApplicationAction ( { type : ApplicationActions . SET_LIST_OFFERS , payload : list } ) ;
426
+ } ;
427
+
407
428
const setListBitcoinTransactionsHandler = ( list : any ) => {
408
429
dispatchApplicationAction ( { type : ApplicationActions . SET_LIST_BITCOIN_TRANSACTIONS , payload : list } ) ;
409
430
} ;
@@ -429,6 +450,7 @@ const AppProvider: React.PropsWithChildren<any> = (props) => {
429
450
listChannels : applicationState . listChannels ,
430
451
listInvoices : applicationState . listInvoices ,
431
452
listPayments : applicationState . listPayments ,
453
+ listOffers : applicationState . listOffers ,
432
454
listLightningTransactions : applicationState . listLightningTransactions ,
433
455
listBitcoinTransactions : applicationState . listBitcoinTransactions ,
434
456
walletBalances : applicationState . walletBalances ,
@@ -443,6 +465,7 @@ const AppProvider: React.PropsWithChildren<any> = (props) => {
443
465
setListPeers : setListPeersHandler ,
444
466
setListInvoices : setListInvoicesHandler ,
445
467
setListPayments : setListPaymentsHandler ,
468
+ setListOffers : setListOffersHandler ,
446
469
setListBitcoinTransactions : setListBitcoinTransactionsHandler ,
447
470
setStore : setContextStore ,
448
471
clearStore : clearContextHandler
0 commit comments