Skip to content

Commit

Permalink
make announce channel toggle + loading before calling endpoints + dis…
Browse files Browse the repository at this point in the history
…playing error if pubkey/host not set
  • Loading branch information
shubhamkmr04 committed Apr 24, 2024
1 parent fe854ac commit 54f3910
Show file tree
Hide file tree
Showing 3 changed files with 621 additions and 469 deletions.
15 changes: 11 additions & 4 deletions stores/LSPStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export default class LSPStore {
@observable public feeId: string | undefined;
@observable public pubkey: string;
@observable public host: string;
@observable public restHost: string;
@observable public loading: boolean = true;
@observable public error: boolean = false;
@observable public error_msg: string = '';
@observable public showLspSettings: boolean = false;
Expand Down Expand Up @@ -62,6 +64,7 @@ export default class LSPStore {
public resetLSPS1Data = () => {
this.createOrderResponse = {};
this.getInfoData = {};
this.loading = true;
};

getLSPHost = () =>
Expand Down Expand Up @@ -321,10 +324,12 @@ export default class LSPStore {

if (data.id === '42') {
this.getInfoData = data;
this.loading = false;
} else if (data.id === '52') {
this.getOrderResponse = data;
} else {
this.createOrderResponse = data;
this.loading = false;
}
};

Expand Down Expand Up @@ -363,7 +368,7 @@ export default class LSPStore {
};

@action
public getinfoREST = (host = 'https://testnet-lsps1.lnolymp.us') => {
public getinfoREST = (host: string) => {
const endpoint = `${host}/api/v1/get_info`;

console.log('Fetching data from:', endpoint);
Expand All @@ -373,6 +378,7 @@ export default class LSPStore {
if (response.info().status === 200) {
const responseData = JSON.parse(response.data);
this.getInfoData = responseData;
this.loading = false;
} else {
throw new Error(
`Failed to fetch get_info: ${response.info().status}`
Expand All @@ -386,7 +392,7 @@ export default class LSPStore {
};

@action
public createorderREST = (host: string, state: any) => {
public createorderREST = (state: any) => {
const data = JSON.stringify({
lsp_balance_sat: state.lspBalanceSat,
client_balance_sat: state.clientBalanceSat,
Expand All @@ -402,8 +408,8 @@ export default class LSPStore {
announce_channel: true,
public_key: this.pubkey
});
const endpoint = `${host}/api/v1/create_order`;

this.loading = true;
const endpoint = `${state.host}/api/v1/create_order`;
console.log('Sending data to:', endpoint);

return ReactNativeBlobUtil.fetch(
Expand All @@ -417,6 +423,7 @@ export default class LSPStore {
.then((response) => {
const responseData = JSON.parse(response.data);
this.createOrderResponse = responseData;
this.loading = false;
console.log('Response received:', responseData);
})
.catch((error) => {
Expand Down
13 changes: 6 additions & 7 deletions views/Settings/LSPS1/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,12 @@ export default class LSPS1Settings extends React.Component<
LSPStore.host = text;
}}
/>
{inputsChanged && (
<Button
containerStyle={{ paddingTop: 30 }}
title="RESET"
onPress={() => this.handleReset()}
/>
)}

<Button
containerStyle={{ paddingTop: 30 }}
title={inputsChanged ? 'RESET' : 'CONNECT TO OLYMPUS'}
onPress={() => this.handleReset()}
/>
</View>
</Screen>
);
Expand Down
Loading

0 comments on commit 54f3910

Please sign in to comment.