diff --git a/stores/LSPStore.ts b/stores/LSPStore.ts index 50f98a2bf2..08edbc8b8e 100644 --- a/stores/LSPStore.ts +++ b/stores/LSPStore.ts @@ -2,6 +2,7 @@ import { action, observable } from 'mobx'; import ReactNativeBlobUtil from 'react-native-blob-util'; import { NativeEventEmitter, NativeModules } from 'react-native'; +import NodeInfoStore from './NodeInfoStore'; import SettingsStore from './SettingsStore'; import stores from './Stores'; @@ -19,9 +20,11 @@ export default class LSPStore { @observable public showLspSettings: boolean = false; @observable public channelAcceptor: any; + nodeInfoStore: NodeInfoStore; settingsStore: SettingsStore; - constructor(settingsStore: SettingsStore) { + constructor(nodeInfoStore: NodeInfoStore, settingsStore: SettingsStore) { + this.nodeInfoStore = nodeInfoStore; this.settingsStore = settingsStore; } @@ -35,16 +38,19 @@ export default class LSPStore { this.channelAcceptor = undefined; }; + getLspHost = () => { + return this.settingsStore.embeddedLndNetwork === 'Testnet' || + this.nodeInfoStore.nodeInfo.testnet + ? this.settingsStore.settings.lspTestnet + : this.settingsStore.settings.lspMainnet; + }; + @action public getLSPInfo = () => { return new Promise((resolve, reject) => { ReactNativeBlobUtil.fetch( 'get', - `${ - this.settingsStore.embeddedLndNetwork === 'Mainnet' - ? this.settingsStore.settings.lspMainnet - : this.settingsStore.settings.lspTestnet - }/api/v1/info`, + `${this.getLspHost()}/api/v1/info`, { 'Content-Type': 'application/json' } @@ -85,11 +91,7 @@ export default class LSPStore { return new Promise((resolve, reject) => { ReactNativeBlobUtil.fetch( 'post', - `${ - this.settingsStore.embeddedLndNetwork === 'Mainnet' - ? this.settingsStore.settings.lspMainnet - : this.settingsStore.settings.lspTestnet - }/api/v1/fee`, + `${this.getLspHost()}/api/v1/fee`, { 'Content-Type': 'application/json' }, @@ -173,11 +175,7 @@ export default class LSPStore { return new Promise((resolve, reject) => { ReactNativeBlobUtil.fetch( 'post', - `${ - this.settingsStore.embeddedLndNetwork === 'Mainnet' - ? this.settingsStore.settings.lspMainnet - : this.settingsStore.settings.lspTestnet - }/api/v1/proposal`, + `${this.getLspHost()}/api/v1/proposal`, this.settingsStore.settings.lspAccessKey ? { 'Content-Type': 'application/json', diff --git a/stores/Stores.ts b/stores/Stores.ts index df108fecd5..c78127bcab 100644 --- a/stores/Stores.ts +++ b/stores/Stores.ts @@ -47,7 +47,7 @@ class Stores { this.fiatStore = new FiatStore(this.settingsStore); this.channelsStore = new ChannelsStore(this.settingsStore); this.nodeInfoStore = new NodeInfoStore(this.settingsStore); - this.lspStore = new LSPStore(this.settingsStore); + this.lspStore = new LSPStore(this.nodeInfoStore, this.settingsStore); this.channelBackupStore = new ChannelBackupStore( this.nodeInfoStore, this.settingsStore