From e098c2cb7d3fed64fc5af87956e41ffb1e259f8a Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Mon, 6 Aug 2018 13:43:11 -0400 Subject: [PATCH] weird --- embark-ui/src/components/ExplorerLayout.js | 62 --------- .../src/containers/CommunicationContainer.js | 127 ++++++++++++++++++ 2 files changed, 127 insertions(+), 62 deletions(-) delete mode 100644 embark-ui/src/components/ExplorerLayout.js create mode 100644 embark-ui/src/containers/CommunicationContainer.js diff --git a/embark-ui/src/components/ExplorerLayout.js b/embark-ui/src/components/ExplorerLayout.js deleted file mode 100644 index bb7299c75..000000000 --- a/embark-ui/src/components/ExplorerLayout.js +++ /dev/null @@ -1,62 +0,0 @@ -import React from 'react'; -import {NavLink, Route, Switch, withRouter} from 'react-router-dom'; -import { - Page, - Grid, - List -} from "tabler-react"; - -import AccountsContainer from '../containers/AccountsContainer'; -import AccountContainer from '../containers/AccountContainer'; -import BlocksContainer from '../containers/BlocksContainer'; -import BlockContainer from '../containers/BlockContainer'; -import TransactionsContainer from '../containers/TransactionsContainer'; -import TransactionContainer from '../containers/TransactionContainer'; - -const ExplorerLayout = () => ( - - - Explorer -
- - - Accounts - - - Blocks - - - Transactions - - -
-
- - - - - - - - - - -
-); - -export default ExplorerLayout; diff --git a/embark-ui/src/containers/CommunicationContainer.js b/embark-ui/src/containers/CommunicationContainer.js new file mode 100644 index 000000000..e7537b73b --- /dev/null +++ b/embark-ui/src/containers/CommunicationContainer.js @@ -0,0 +1,127 @@ +import React, {Component} from 'react'; +import {Alert, Button, Form, Icon} from 'tabler-react'; + +class CommunicationContainer extends Component { + constructor(props) { + super(props); + + this.state = { + listenTo: '', + channel: '', + message: '', + subscribedChannels: [], + messageList: [], + logs: [] + }; + } + + handleChange(e, name) { + this.setState({ + [name]: e.target.value + }); + } + + sendMessage(e) { + e.preventDefault(); + // TODO send message via API + console.log('Send', this.state.message); + this.addToLog("EmbarkJS.Messages.sendMessage({topic: '" + this.state.channel + "', data: '" + this.state.message + "'})"); + } + + listenToChannel(e) { + e.preventDefault(); + + const subscribedChannels = this.state.subscribedChannels; + subscribedChannels.push(Subscribed to {this.state.listenTo}. Now try sending a message); + this.setState({ + subscribedChannels + }); + + console.log('Listen to', this.state.listenTo); + // TODO listen to channel via API + /*EmbarkJS.Messages.listenTo({topic: [this.state.listenTo]}, (error, message) => { + const messageList = this.state.messageList; + if (error) { + messageList.push(Error: {error}); + } else { + messageList.push(Channel: {message.topic} | Message: {message.data}); + } + this.setState({ + messageList + }); + });*/ + + this.addToLog("EmbarkJS.Messages.listenTo({topic: ['" + this.state.listenTo + "']}).then(function(message) {})"); + } + + addToLog(txt) { + this.state.logs.push(txt); + this.setState({logs: this.state.logs}); + } + + render() { + let isEnabledMessage = ''; + if (this.enabled === false) { + isEnabledMessage = + The node you are using does not support Whisper + The node uses an unsupported version of Whisper + ; + } else if (!this.enabled) { + isEnabledMessage = Checking Whisper support, please wait; + } + + return ( + + {isEnabledMessage} +

Listen To channel

+ + + this.handleChange(e, 'listenTo')}/> + + +
+ {this.state.subscribedChannels.map((item, i) =>

{item}

)} +
+

Messages received:

+
+ {this.state.messageList.map((item, i) =>

{item}

)} +
+
+ + +

Send Message

+ + + + + this.handleChange(e, 'channel')}/> + + + this.handleChange(e, 'message')}/> + + + + + +

Javascript calls being made:

+
+

EmbarkJS.Messages.setProvider('whisper')

+ { + this.state.logs.map((item, i) =>

{item}

) + } +
+
+ ); + } +} + +export default CommunicationContainer;