diff --git a/stores/LSPStore.ts b/stores/LSPStore.ts index a16d18564..587f6bcbc 100644 --- a/stores/LSPStore.ts +++ b/stores/LSPStore.ts @@ -1,6 +1,5 @@ import { action, observable } from 'mobx'; import ReactNativeBlobUtil from 'react-native-blob-util'; -import EncryptedStorage from 'react-native-encrypted-storage'; import SettingsStore from './SettingsStore'; import ChannelsStore from './ChannelsStore'; @@ -23,6 +22,8 @@ export default class LSPStore { @observable public showLspSettings: boolean = false; @observable public channelAcceptor: any; @observable public customMessagesSubscriber: any; + @observable public getInfoData: any = {}; + @observable public createOrderResponse: any = {}; settingsStore: SettingsStore; channelsStore: ChannelsStore; @@ -319,10 +320,11 @@ export default class LSPStore { console.log('peer', peer); console.log('data', data); - await EncryptedStorage.setItem( - 'get_info_data', - JSON.stringify(data) - ); + if (data.id === '42') { + this.getInfoData = data; + } else { + this.createOrderResponse = data; + } } catch (error: any) { console.error( 'sub custom messages error: ' + error.message diff --git a/views/Settings/LSPS1.tsx b/views/Settings/LSPS1.tsx index d4f23d51c..4bb07a21c 100644 --- a/views/Settings/LSPS1.tsx +++ b/views/Settings/LSPS1.tsx @@ -7,13 +7,13 @@ import { ScrollView, TouchableOpacity } from 'react-native'; -import EncryptedStorage from 'react-native-encrypted-storage'; import Header from '../../components/Header'; import Screen from '../../components/Screen'; import TextInput from '../../components/TextInput'; import LSPStore from '../../stores/LSPStore'; +import InvoicesStore from '../../stores/InvoicesStore'; import ChannelsStore from '../../stores/ChannelsStore'; import Button from '../../components/Button'; @@ -26,13 +26,13 @@ import CaretRight from '../../assets/images/SVG/Caret Right.svg'; interface LSPS1Props { LSPStore: LSPStore; + InvoicesStore: InvoicesStore; ChannelsStore: ChannelsStore; navigation: any; } interface LSPS1State { peer: string; - getInfoData: any; lspBalanceSat: any; clientBalanceSat: any; requiredChannelConfirmations: any; @@ -40,10 +40,10 @@ interface LSPS1State { channelExpiryBlocks: any; token: any; refundOnchainAddress: any; - advanceSettings: boolean; + advancedSettings: boolean; } -@inject('LSPStore', 'ChannelsStore') +@inject('LSPStore', 'ChannelsStore', 'InvoicesStore') @observer export default class LSPS1 extends React.Component { constructor(props: LSPS1Props) { @@ -57,8 +57,7 @@ export default class LSPS1 extends React.Component { token: '', refundOnchainAddress: 'bc1q3uppthgr2k3wag8w2f3fj03ataenwvwauswudt', peer: '03e84a109cd70e57864274932fc87c5e6434c59ebb8e6e7d28532219ba38f7f6df@139.144.22.237:9735', - getInfoData: {}, - advanceSettings: false + advancedSettings: false }; } @@ -70,19 +69,6 @@ export default class LSPS1 extends React.Component { this.sendCustomMessage_lsps1(); } - async retrieveData() { - try { - const savedData: any = await EncryptedStorage.getItem( - 'get_info_data' - ); - this.setState({ - getInfoData: JSON.parse(savedData) - }); - } catch (error) { - console.error('Error retrieving data:', error); - } - } - subscribeToCustomMessages() { this.props.LSPStore.subscribeCustomMessages() .then((response) => { @@ -110,7 +96,6 @@ export default class LSPS1 extends React.Component { data }) .then((response) => { - this.retrieveData(); console.log('Custom message sent:', response); }) .catch((error) => { @@ -230,15 +215,20 @@ export default class LSPS1 extends React.Component { } render() { - const { navigation } = this.props; - const { getInfoData, advanceSettings } = this.state; + const { navigation, LSPStore, InvoicesStore } = this.props; + const { advancedSettings } = this.state; + const getInfoData = LSPStore.getInfoData; const options = getInfoData?.result?.options; + const createOrderResponse = LSPStore?.createOrderResponse; + const result = createOrderResponse?.result; + const payment = result?.payment; return (
- + {getInfoData && + Object.keys(createOrderResponse).length == 0 && Object.keys(getInfoData).length > 0 && options && ( @@ -314,178 +304,337 @@ export default class LSPS1 extends React.Component { )} - - - Initial LSP Balance (Sats) - - - this.setState({ lspBalanceSat: text }) - } - // style={styles.textInput} - /> + {createOrderResponse && + Object.keys(createOrderResponse).length > 0 && + result && + payment && ( + + {result.announce_channel && ( + + )} + {result.channel && ( + + )} + {result.channel_expiry_blocks && ( + + )} + {result.client_balance_sat && ( + + )} + {result.confirms_within_blocks && ( + + )} + {result.created_at && ( + + )} + {result.expires_at && ( + + )} + {result.lsp_balance_sat && ( + + )} + {result.order_id && ( + + )} + {result.order_state && ( + + )} + + {payment.fee_total_sat && ( + + )} + {payment.lightning_invoice && ( + + )} + {payment.state && ( + + )} + {payment.min_fee_for_0conf && ( + + )} + {payment.min_onchain_payment_confirmations && ( + + )} + {payment.onchain_address && ( + + )} + {payment.onchain_payment && ( + + )} + {payment.order_total_sat && ( + + )} + + )} - { - this.setState({ - advanceSettings: !advanceSettings - }); + {Object.keys(createOrderResponse).length == 0 && ( + - - - - - - {advanceSettings ? ( - - ) : ( - - )} - - - + Initial LSP Balance (Sats) + + + this.setState({ lspBalanceSat: text }) + } + // style={styles.textInput} + /> - {advanceSettings && ( - <> - { + this.setState({ + advancedSettings: !advancedSettings + }); + }} + > + - Initial Client Balance (Sats) - - - this.setState({ - clientBalanceSat: text - }) - } - style={styles.textInput} - /> + + + + + {advancedSettings ? ( + + ) : ( + + )} + + + - - Required Channel Confirmations - - - this.setState({ - requiredChannelConfirmations: text - }) - } - style={styles.textInput} - keyboardType="numeric" - /> + {advancedSettings && ( + <> + + Initial Client Balance (Sats) + + + this.setState({ + clientBalanceSat: text + }) + } + style={styles.textInput} + /> - - Confirms Within Blocks - - - this.setState({ - confirmsWithinBlocks: text - }) - } - style={styles.textInput} - keyboardType="numeric" - /> + + Required Channel Confirmations + + + this.setState({ + requiredChannelConfirmations: + text + }) + } + style={styles.textInput} + keyboardType="numeric" + /> - - Channel Expiry Blocks - - - this.setState({ - channelExpiryBlocks: text - }) - } - style={styles.textInput} - keyboardType="numeric" - /> + + Confirms Within Blocks + + + this.setState({ + confirmsWithinBlocks: text + }) + } + style={styles.textInput} + keyboardType="numeric" + /> - - Token - - - this.setState({ token: text }) - } - style={styles.textInput} - /> + + Channel Expiry Blocks + + + this.setState({ + channelExpiryBlocks: text + }) + } + style={styles.textInput} + keyboardType="numeric" + /> - - Refund Onchain Address - - - this.setState({ - refundOnchainAddress: text - }) - } - style={styles.textInput} - /> - - )} - - + + Token + + + this.setState({ token: text }) + } + style={styles.textInput} + /> + + + Refund Onchain Address + + + this.setState({ + refundOnchainAddress: text + }) + } + style={styles.textInput} + /> + + )} + + )} +