-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38e7dfa
commit 71d7570
Showing
6 changed files
with
222 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import * as React from 'react'; | ||
|
||
import Header from '../../components/Header'; | ||
import Screen from '../../components/Screen'; | ||
import { inject, observer } from 'mobx-react'; | ||
|
||
import LSPStore from '../../stores/LSPStore'; | ||
import ChannelsStore from '../../stores/ChannelsStore'; | ||
import { View } from 'react-native'; | ||
import Base64Utils from '../../utils/Base64Utils'; | ||
|
||
import Button from '../../components/Button'; | ||
|
||
interface Lsps1TestProps { | ||
LSPStore: LSPStore; | ||
ChannelsStore: ChannelsStore; | ||
navigation: any; | ||
} | ||
|
||
interface Lsps1TestState { | ||
peer: string; | ||
} | ||
|
||
@inject('LSPStore', 'ChannelsStore') | ||
@observer | ||
export default class Lsps1Test extends React.Component< | ||
Lsps1TestProps, | ||
Lsps1TestState | ||
> { | ||
state = { | ||
peer: '0203e5b16ebe87b089f22e18752f1f7a66a1bdf77879df8d1c9e8d912dbfb9beb4' | ||
}; | ||
|
||
encodeMesage = (n: any) => Buffer.from(JSON.stringify(n)).toString(); | ||
|
||
subscribeToCustomMessages() { | ||
this.props.LSPStore.subscribeCustomMessages() | ||
.then((response) => { | ||
console.log('Subscribed to custom messages:', response); | ||
}) | ||
.catch((error) => { | ||
console.error('Error subscribing to custom messages:', error); | ||
}); | ||
} | ||
|
||
sendCustomMessage_lsps1() { | ||
const peer = this.state.peer; | ||
const type = 37913; | ||
const data = this.encodeMesage({ | ||
jsonrpc: '2.0', | ||
method: 'lsps1.get_info', | ||
params: {}, | ||
id: '42' | ||
}); | ||
|
||
this.props.LSPStore.sendCustomMessage({ peer, type, data }) | ||
.then((response) => { | ||
console.log('Custom message sent:', response); | ||
}) | ||
.catch((error) => { | ||
// Handle errors | ||
console.error('Error sending custom message:', error); | ||
}); | ||
} | ||
|
||
sendCustomMessage_lsps0() { | ||
const peer = this.state.peer; | ||
const type = 37913; | ||
const data = this.encodeMesage({ | ||
method: 'lsps0.list_protocols', | ||
jsonrpc: '2.0', | ||
id: 'example#3cad6a54d302edba4c9ade2f7ffac098', | ||
params: {} | ||
}); | ||
|
||
this.props.LSPStore.sendCustomMessage({ peer, type, data }) | ||
.then((response) => { | ||
console.log('Custom message sent:', response); | ||
}) | ||
.catch((error) => { | ||
// Handle errors | ||
console.error('Error sending custom message:', error); | ||
}); | ||
} | ||
|
||
connectPeer() { | ||
const { ChannelsStore } = this.props; | ||
const peer = | ||
'0203e5b16ebe87b089f22e18752f1f7a66a1bdf77879df8d1c9e8d912dbfb9beb4@150.136.37.44:9735'; | ||
const [node_pubkey_string, host] = peer.split('@'); | ||
ChannelsStore.connectPeer({ node_pubkey_string, host }, true, true); | ||
} | ||
|
||
render() { | ||
const { navigation } = this.props; | ||
return ( | ||
<Screen> | ||
<Header leftComponent="Back" navigation={navigation} /> | ||
<View> | ||
<Button | ||
title="Subscribe to Custom Messages" | ||
onPress={() => this.subscribeToCustomMessages()} | ||
containerStyle={{ paddingBottom: 20 }} | ||
/> | ||
<Button | ||
title="Send Custom Message lsps1" | ||
onPress={() => this.sendCustomMessage_lsps1()} | ||
containerStyle={{ paddingBottom: 20 }} | ||
/> | ||
<Button | ||
title="Send Custom Message lsps0" | ||
onPress={() => this.sendCustomMessage_lsps0()} | ||
containerStyle={{ paddingBottom: 20 }} | ||
/> | ||
<Button | ||
title="connect peer" | ||
onPress={() => this.connectPeer()} | ||
/> | ||
</View> | ||
</Screen> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters