11import { configJson } from '../file-models/mempool-config.json'
22import { sdk } from '../sdk'
3- import { configJsonDefaults } from '../utils'
3+ import { lndMountpoint , clnMountpoint } from '../utils'
44import { i18n } from '../i18n'
55const { InputSpec, Value } = sdk
66
@@ -18,12 +18,12 @@ export const lightningInputSpec = InputSpec.of({
1818} )
1919
2020export const matchLightningInputSpec = lightningInputSpec . validator
21- export type LightningInputSpec = typeof matchLightningInputSpec . _TYPE
21+ export type LightningInputSpec = typeof lightningInputSpec . _TYPE
2222
2323export const enableLightning = sdk . Action . withInput (
2424 'enable-lightning' ,
2525
26- async ( { effects } ) => ( {
26+ {
2727 name : i18n ( 'Enable Lightning' ) ,
2828 description : i18n (
2929 'Use this setting to select the Lightning node used to serve network data to the Lightning tab in Mempool' ,
@@ -32,7 +32,7 @@ export const enableLightning = sdk.Action.withInput(
3232 allowedStatuses : 'any' ,
3333 group : null ,
3434 visibility : 'enabled' ,
35- } ) ,
35+ } ,
3636
3737 // form input specification
3838 lightningInputSpec ,
@@ -49,33 +49,27 @@ export const enableLightning = sdk.Action.withInput(
4949
5050 // the execution function
5151 async ( { effects, input } ) => {
52- const config = await configJson . read ( ) . const ( effects )
53- if ( ! config ) throw new Error ( 'Config file not found' )
54-
55- // return early if nothing changed
56- if (
57- config . LIGHTNING . ENABLED &&
58- config . LIGHTNING . BACKEND === input . lightning
59- )
60- return
61-
6252 switch ( input . lightning ) {
6353 case 'lnd' :
64- config . LIGHTNING . ENABLED = true
65- config . LIGHTNING . BACKEND = 'lnd'
66- config . LND . TLS_CERT_PATH = configJsonDefaults . LND . TLS_CERT_PATH
67- config . LND . MACAROON_PATH = configJsonDefaults . LND . MACAROON_PATH
54+ await configJson . merge ( effects , {
55+ LIGHTNING : { ENABLED : true , BACKEND : 'lnd' } ,
56+ LND : {
57+ TLS_CERT_PATH : `${ lndMountpoint } /tls.cert` ,
58+ MACAROON_PATH : `${ lndMountpoint } /readonly.macaroon` ,
59+ } ,
60+ } )
6861 break
6962 case 'cln' :
70- config . LIGHTNING . ENABLED = true
71- config . LIGHTNING . BACKEND = 'cln'
72- config . CLIGHTNING . SOCKET = configJsonDefaults . CLIGHTNING . SOCKET
63+ await configJson . merge ( effects , {
64+ LIGHTNING : { ENABLED : true , BACKEND : 'cln' } ,
65+ CLIGHTNING : { SOCKET : `${ clnMountpoint } /lightning-rpc` } ,
66+ } )
7367 break
7468 default :
75- config . LIGHTNING . ENABLED = false
69+ await configJson . merge ( effects , {
70+ LIGHTNING : { ENABLED : false } ,
71+ } )
7672 break
7773 }
78-
79- await configJson . merge ( effects , config )
8074 } ,
8175)
0 commit comments