mirror of https://github.com/embarklabs/embark.git
conflict in saga
This commit is contained in:
parent
46996f41c9
commit
fd1b43d3e3
|
@ -76,20 +76,6 @@ export const processLogs = {
|
|||
failure: (error) => action(PROCESS_LOGS[FAILURE], {error})
|
||||
};
|
||||
|
||||
export const MESSAGE_LISTEN = createRequestTypes('MESSAGE_LISTEN');
|
||||
export const messageListen = {
|
||||
request: (channel) => action(MESSAGE_LISTEN[REQUEST], {channel}),
|
||||
success: (message) => action(MESSAGE_LISTEN[SUCCESS], {message}),
|
||||
failure: (error) => action(MESSAGE_LISTEN[FAILURE], {error})
|
||||
};
|
||||
|
||||
export const MESSAGE_SEND = createRequestTypes('MESSAGE_SEND');
|
||||
export const messageSend = {
|
||||
request: (body) => action(MESSAGE_SEND[REQUEST], {body}),
|
||||
success: () => action(MESSAGE_SEND[SUCCESS]),
|
||||
failure: (error) => action(MESSAGE_SEND[FAILURE], {error})
|
||||
};
|
||||
|
||||
|
||||
export const CONTRACTS = createRequestTypes('CONTRACTS');
|
||||
export const contracts = {
|
||||
|
@ -128,3 +114,25 @@ export function initBlockHeader(){
|
|||
type: INIT_BLOCK_HEADER
|
||||
};
|
||||
}
|
||||
|
||||
export const MESSAGE_VERSION = createRequestTypes('MESSAGE_VERSION');
|
||||
export const messageVersion = {
|
||||
request: () => action(MESSAGE_VERSION[REQUEST]),
|
||||
success: (version) => action(MESSAGE_VERSION[SUCCESS], {version}),
|
||||
failure: (error) => action(MESSAGE_VERSION[FAILURE], {error})
|
||||
};
|
||||
|
||||
|
||||
export const MESSAGE_SEND = createRequestTypes('MESSAGE_SEND');
|
||||
export const messageSend = {
|
||||
request: (body) => action(MESSAGE_SEND[REQUEST], {body}),
|
||||
success: () => action(MESSAGE_SEND[SUCCESS]),
|
||||
failure: (error) => action(MESSAGE_SEND[FAILURE], {error})
|
||||
};
|
||||
|
||||
export const MESSAGE_LISTEN = createRequestTypes('MESSAGE_LISTEN');
|
||||
export const messageListen = {
|
||||
request: (channel) => action(MESSAGE_LISTEN[REQUEST], {channel}),
|
||||
success: (message) => action(MESSAGE_LISTEN[SUCCESS], {message}),
|
||||
failure: (error) => action(MESSAGE_LISTEN[FAILURE], {error})
|
||||
};
|
|
@ -64,6 +64,10 @@ export function fetchContract(payload) {
|
|||
return get(`/contract/${payload.contractName}`);
|
||||
}
|
||||
|
||||
export function communicationVersion() {
|
||||
return get(`/communication/version`);
|
||||
}
|
||||
|
||||
export function sendMessage(payload) {
|
||||
return post(`/communication/sendMessage`, payload);
|
||||
}
|
||||
|
|
|
@ -61,14 +61,14 @@ class Communication extends Component {
|
|||
<div id="subscribeList">
|
||||
{this.state.subscribedChannels.map((item, i) => <p key={i}>{item}</p>)}
|
||||
</div>
|
||||
{this.props.messages && this.props.messages.channels && Boolean(Object.keys(this.props.messages.channels).length) &&
|
||||
{this.props.channels && Boolean(Object.keys(this.props.channels).length) &&
|
||||
<React.Fragment>
|
||||
<p>Messages received:</p>
|
||||
<div id="messagesList">
|
||||
{Object.keys(this.props.messages.channels).map((channelName, i) => {
|
||||
{Object.keys(this.props.channels).map((channelName, i) => {
|
||||
return (<React.Fragment key={'channel-' + i}>
|
||||
<p><b>{channelName}</b></p>
|
||||
{this.props.messages.channels[channelName].messages.map((message, f) => {
|
||||
{this.props.channels[channelName].messages.map((message, f) => {
|
||||
return <p key={`${message}-${i}-${f}`}>{message}</p>;
|
||||
})}
|
||||
</React.Fragment>);
|
||||
|
@ -112,7 +112,7 @@ class Communication extends Component {
|
|||
Communication.propTypes = {
|
||||
sendMessage: PropTypes.func,
|
||||
listenToMessages: PropTypes.func,
|
||||
messages: PropTypes.object
|
||||
channels: PropTypes.object
|
||||
};
|
||||
|
||||
export default Communication;
|
||||
|
|
|
@ -2,10 +2,14 @@ import PropTypes from "prop-types";
|
|||
import React, {Component} from 'react';
|
||||
import connect from "react-redux/es/connect/connect";
|
||||
import {Alert, Icon} from 'tabler-react';
|
||||
import {messageSend, messageListen} from "../actions";
|
||||
import {messageSend, messageListen, messageVersion} from "../actions";
|
||||
import Communication from "../components/Communication";
|
||||
|
||||
class CommunicationContainer extends Component {
|
||||
componentDidMount() {
|
||||
this.props.communicationVersion();
|
||||
}
|
||||
|
||||
sendMessage(topic, message) {
|
||||
this.props.messageSend({topic, message});
|
||||
}
|
||||
|
@ -16,14 +20,13 @@ class CommunicationContainer extends Component {
|
|||
|
||||
render() {
|
||||
let isEnabledMessage = '';
|
||||
if (this.enabled === false) {
|
||||
isEnabledMessage = <React.Fragment>
|
||||
<Alert type="warning">The node you are using does not support Whisper</Alert>
|
||||
<Alert type="warning">The node uses an unsupported version of Whisper</Alert>
|
||||
</React.Fragment>;
|
||||
} else if (!this.enabled) {
|
||||
if (this.props.version === undefined || this.props.version === null) {
|
||||
isEnabledMessage =
|
||||
<Alert bsStyle="secondary "><Icon name="refresh-cw"/> Checking Whisper support, please wait</Alert>;
|
||||
} else if (!this.props.version) {
|
||||
isEnabledMessage = <Alert type="warning">The node you are using does not support Whisper</Alert>;
|
||||
} else if (this.props.version === -1) {
|
||||
isEnabledMessage = <Alert type="warning">The node uses an unsupported version of Whisper</Alert>;
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -31,7 +34,7 @@ class CommunicationContainer extends Component {
|
|||
{isEnabledMessage}
|
||||
<Communication listenToMessages={(channel) => this.listenToChannel(channel)}
|
||||
sendMessage={(channel, message) => this.sendMessage(channel, message)}
|
||||
messages={this.props.messages}/>
|
||||
channels={this.props.channels}/>
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
|
@ -40,18 +43,24 @@ class CommunicationContainer extends Component {
|
|||
CommunicationContainer.propTypes = {
|
||||
messageSend: PropTypes.func,
|
||||
messageListen: PropTypes.func,
|
||||
messages: PropTypes.object
|
||||
communicationVersion: PropTypes.func,
|
||||
channels: PropTypes.object,
|
||||
version: PropTypes.number
|
||||
};
|
||||
|
||||
function mapStateToProps(state) {
|
||||
return {messages: state.messages};
|
||||
return {
|
||||
channels: state.messages.channels,
|
||||
version: state.messages.version
|
||||
};
|
||||
}
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
{
|
||||
messageSend: messageSend.request,
|
||||
messageListen: messageListen.request
|
||||
messageListen: messageListen.request,
|
||||
communicationVersion: messageVersion.request
|
||||
}
|
||||
)(CommunicationContainer);
|
||||
|
||||
|
|
|
@ -16,6 +16,12 @@ export default function messages(state = {channels: {}}, action) {
|
|||
}
|
||||
};
|
||||
}
|
||||
case actions.MESSAGE_VERSION[actions.SUCCESS]: {
|
||||
return {
|
||||
...state,
|
||||
version: action.version.data
|
||||
};
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import {eventChannel} from 'redux-saga';
|
|||
import {all, call, fork, put, takeEvery, take} from 'redux-saga/effects';
|
||||
|
||||
const {account, accounts, block, blocks, transaction, transactions, processes, commands, processLogs,
|
||||
contracts, contract, contractProfile, messageSend} = actions;
|
||||
contracts, contract, contractProfile, messageSend, messageVersion} = actions;
|
||||
|
||||
function *doRequest(entity, apiFn, payload) {
|
||||
const {response, error} = yield call(apiFn, payload);
|
||||
|
@ -133,6 +133,12 @@ export function *watchListenToMessages() {
|
|||
yield takeEvery(actions.MESSAGE_LISTEN[actions.REQUEST], listenToMessages);
|
||||
}
|
||||
|
||||
export const fetchCommunicationVersion = doRequest.bind(null, messageVersion, api.communicationVersion);
|
||||
|
||||
export function *watchCommunicationVersion() {
|
||||
yield takeEvery(actions.MESSAGE_VERSION[actions.REQUEST], fetchCommunicationVersion);
|
||||
}
|
||||
|
||||
export default function *root() {
|
||||
yield all([
|
||||
fork(watchInitBlockHeader),
|
||||
|
@ -144,6 +150,7 @@ export default function *root() {
|
|||
fork(watchFetchBlock),
|
||||
fork(watchFetchTransactions),
|
||||
fork(watchPostCommand),
|
||||
fork(watchCommunicationVersion),
|
||||
fork(watchFetchBlocks),
|
||||
fork(watchFetchContracts),
|
||||
fork(watchListenToMessages),
|
||||
|
|
|
@ -85,6 +85,7 @@ class Whisper {
|
|||
code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'js', 'message_events.js')).toString();
|
||||
|
||||
if (web3Version[0] === "0") {
|
||||
self.isOldWeb3 = true;
|
||||
code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'js', 'embarkjs_old_web3.js')).toString();
|
||||
code += "\nEmbarkJS.Messages.registerProvider('whisper', __embarkWhisperOld);";
|
||||
} else {
|
||||
|
@ -163,7 +164,6 @@ class Whisper {
|
|||
|
||||
self.embark.registerAPICall(
|
||||
'ws',
|
||||
// FIXME channel name
|
||||
'/embark-api/communication/listenTo/:topic',
|
||||
(ws, req) => {
|
||||
listenTo({
|
||||
|
@ -181,6 +181,14 @@ class Whisper {
|
|||
ws.send(JSON.stringify(result));
|
||||
});
|
||||
});
|
||||
|
||||
self.embark.registerAPICall(
|
||||
'get',
|
||||
'/embark-api/communication/version',
|
||||
(req, res) => {
|
||||
res.send(self.isOldWeb3 ? -1 : self.version || 0);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue