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})
|
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 = createRequestTypes('CONTRACTS');
|
||||||
export const contracts = {
|
export const contracts = {
|
||||||
|
@ -128,3 +114,25 @@ export function initBlockHeader(){
|
||||||
type: INIT_BLOCK_HEADER
|
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}`);
|
return get(`/contract/${payload.contractName}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function communicationVersion() {
|
||||||
|
return get(`/communication/version`);
|
||||||
|
}
|
||||||
|
|
||||||
export function sendMessage(payload) {
|
export function sendMessage(payload) {
|
||||||
return post(`/communication/sendMessage`, payload);
|
return post(`/communication/sendMessage`, payload);
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,14 +61,14 @@ class Communication extends Component {
|
||||||
<div id="subscribeList">
|
<div id="subscribeList">
|
||||||
{this.state.subscribedChannels.map((item, i) => <p key={i}>{item}</p>)}
|
{this.state.subscribedChannels.map((item, i) => <p key={i}>{item}</p>)}
|
||||||
</div>
|
</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>
|
<React.Fragment>
|
||||||
<p>Messages received:</p>
|
<p>Messages received:</p>
|
||||||
<div id="messagesList">
|
<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}>
|
return (<React.Fragment key={'channel-' + i}>
|
||||||
<p><b>{channelName}</b></p>
|
<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>;
|
return <p key={`${message}-${i}-${f}`}>{message}</p>;
|
||||||
})}
|
})}
|
||||||
</React.Fragment>);
|
</React.Fragment>);
|
||||||
|
@ -112,7 +112,7 @@ class Communication extends Component {
|
||||||
Communication.propTypes = {
|
Communication.propTypes = {
|
||||||
sendMessage: PropTypes.func,
|
sendMessage: PropTypes.func,
|
||||||
listenToMessages: PropTypes.func,
|
listenToMessages: PropTypes.func,
|
||||||
messages: PropTypes.object
|
channels: PropTypes.object
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Communication;
|
export default Communication;
|
||||||
|
|
|
@ -2,10 +2,14 @@ import PropTypes from "prop-types";
|
||||||
import React, {Component} from 'react';
|
import React, {Component} from 'react';
|
||||||
import connect from "react-redux/es/connect/connect";
|
import connect from "react-redux/es/connect/connect";
|
||||||
import {Alert, Icon} from 'tabler-react';
|
import {Alert, Icon} from 'tabler-react';
|
||||||
import {messageSend, messageListen} from "../actions";
|
import {messageSend, messageListen, messageVersion} from "../actions";
|
||||||
import Communication from "../components/Communication";
|
import Communication from "../components/Communication";
|
||||||
|
|
||||||
class CommunicationContainer extends Component {
|
class CommunicationContainer extends Component {
|
||||||
|
componentDidMount() {
|
||||||
|
this.props.communicationVersion();
|
||||||
|
}
|
||||||
|
|
||||||
sendMessage(topic, message) {
|
sendMessage(topic, message) {
|
||||||
this.props.messageSend({topic, message});
|
this.props.messageSend({topic, message});
|
||||||
}
|
}
|
||||||
|
@ -16,14 +20,13 @@ class CommunicationContainer extends Component {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let isEnabledMessage = '';
|
let isEnabledMessage = '';
|
||||||
if (this.enabled === false) {
|
if (this.props.version === undefined || this.props.version === null) {
|
||||||
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) {
|
|
||||||
isEnabledMessage =
|
isEnabledMessage =
|
||||||
<Alert bsStyle="secondary "><Icon name="refresh-cw"/> Checking Whisper support, please wait</Alert>;
|
<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 (
|
return (
|
||||||
|
@ -31,7 +34,7 @@ class CommunicationContainer extends Component {
|
||||||
{isEnabledMessage}
|
{isEnabledMessage}
|
||||||
<Communication listenToMessages={(channel) => this.listenToChannel(channel)}
|
<Communication listenToMessages={(channel) => this.listenToChannel(channel)}
|
||||||
sendMessage={(channel, message) => this.sendMessage(channel, message)}
|
sendMessage={(channel, message) => this.sendMessage(channel, message)}
|
||||||
messages={this.props.messages}/>
|
channels={this.props.channels}/>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -40,18 +43,24 @@ class CommunicationContainer extends Component {
|
||||||
CommunicationContainer.propTypes = {
|
CommunicationContainer.propTypes = {
|
||||||
messageSend: PropTypes.func,
|
messageSend: PropTypes.func,
|
||||||
messageListen: PropTypes.func,
|
messageListen: PropTypes.func,
|
||||||
messages: PropTypes.object
|
communicationVersion: PropTypes.func,
|
||||||
|
channels: PropTypes.object,
|
||||||
|
version: PropTypes.number
|
||||||
};
|
};
|
||||||
|
|
||||||
function mapStateToProps(state) {
|
function mapStateToProps(state) {
|
||||||
return {messages: state.messages};
|
return {
|
||||||
|
channels: state.messages.channels,
|
||||||
|
version: state.messages.version
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default connect(
|
export default connect(
|
||||||
mapStateToProps,
|
mapStateToProps,
|
||||||
{
|
{
|
||||||
messageSend: messageSend.request,
|
messageSend: messageSend.request,
|
||||||
messageListen: messageListen.request
|
messageListen: messageListen.request,
|
||||||
|
communicationVersion: messageVersion.request
|
||||||
}
|
}
|
||||||
)(CommunicationContainer);
|
)(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:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import {eventChannel} from 'redux-saga';
|
||||||
import {all, call, fork, put, takeEvery, take} from 'redux-saga/effects';
|
import {all, call, fork, put, takeEvery, take} from 'redux-saga/effects';
|
||||||
|
|
||||||
const {account, accounts, block, blocks, transaction, transactions, processes, commands, processLogs,
|
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) {
|
function *doRequest(entity, apiFn, payload) {
|
||||||
const {response, error} = yield call(apiFn, payload);
|
const {response, error} = yield call(apiFn, payload);
|
||||||
|
@ -133,6 +133,12 @@ export function *watchListenToMessages() {
|
||||||
yield takeEvery(actions.MESSAGE_LISTEN[actions.REQUEST], listenToMessages);
|
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() {
|
export default function *root() {
|
||||||
yield all([
|
yield all([
|
||||||
fork(watchInitBlockHeader),
|
fork(watchInitBlockHeader),
|
||||||
|
@ -144,6 +150,7 @@ export default function *root() {
|
||||||
fork(watchFetchBlock),
|
fork(watchFetchBlock),
|
||||||
fork(watchFetchTransactions),
|
fork(watchFetchTransactions),
|
||||||
fork(watchPostCommand),
|
fork(watchPostCommand),
|
||||||
|
fork(watchCommunicationVersion),
|
||||||
fork(watchFetchBlocks),
|
fork(watchFetchBlocks),
|
||||||
fork(watchFetchContracts),
|
fork(watchFetchContracts),
|
||||||
fork(watchListenToMessages),
|
fork(watchListenToMessages),
|
||||||
|
|
|
@ -85,6 +85,7 @@ class Whisper {
|
||||||
code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'js', 'message_events.js')).toString();
|
code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'js', 'message_events.js')).toString();
|
||||||
|
|
||||||
if (web3Version[0] === "0") {
|
if (web3Version[0] === "0") {
|
||||||
|
self.isOldWeb3 = true;
|
||||||
code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'js', 'embarkjs_old_web3.js')).toString();
|
code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'js', 'embarkjs_old_web3.js')).toString();
|
||||||
code += "\nEmbarkJS.Messages.registerProvider('whisper', __embarkWhisperOld);";
|
code += "\nEmbarkJS.Messages.registerProvider('whisper', __embarkWhisperOld);";
|
||||||
} else {
|
} else {
|
||||||
|
@ -163,7 +164,6 @@ class Whisper {
|
||||||
|
|
||||||
self.embark.registerAPICall(
|
self.embark.registerAPICall(
|
||||||
'ws',
|
'ws',
|
||||||
// FIXME channel name
|
|
||||||
'/embark-api/communication/listenTo/:topic',
|
'/embark-api/communication/listenTo/:topic',
|
||||||
(ws, req) => {
|
(ws, req) => {
|
||||||
listenTo({
|
listenTo({
|
||||||
|
@ -181,6 +181,14 @@ class Whisper {
|
||||||
ws.send(JSON.stringify(result));
|
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