Skip to content

Commit

Permalink
LSPStore: update mainnet/testnet logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloudis committed Aug 29, 2023
1 parent 61989e0 commit 22d8a05
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
30 changes: 14 additions & 16 deletions stores/LSPStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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;
}

Expand All @@ -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'
}
Expand Down Expand Up @@ -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'
},
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion stores/Stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 22d8a05

Please sign in to comment.