fix(@embark/core): Metamask + geth warning to enable regular txs

A console warning is meant to appear in the browser console when the dapp is connecting to web3 using metamask and the blockchain client is geth. The warning displays information telling the user they should enable regular transactions to prevent known issues regarding transactions getting stuck.

The issue fixed here pertained to `warnAboutMetamask` vs `warnIfMetamask` - maybe there was a change that introduced this issue upstream.

Additionally, enabling and disabling of regular transactions via an API endpoint did not

Add ability to stop regular txs via query string, and validate request parameters.
This commit is contained in:
emizzle 2019-03-05 15:19:45 +11:00 committed by Eric Mastro
parent 0e63d6bcf9
commit c233dbc7fb
6 changed files with 39 additions and 12 deletions

View File

@ -420,6 +420,13 @@ export const initRegularTxs = {
failure: () => action(INIT_REGULAR_TXS[FAILURE]) failure: () => action(INIT_REGULAR_TXS[FAILURE])
}; };
export const STOP_REGULAR_TXS = createRequestTypes('STOP_REGULAR_TXS');
export const stopRegularTxs = {
request: () => action(STOP_REGULAR_TXS[REQUEST], {mode: 'off'}),
success: () => action(STOP_REGULAR_TXS[SUCCESS]),
failure: () => action(STOP_REGULAR_TXS[FAILURE])
};
// Web Socket // Web Socket
export const WATCH_NEW_PROCESS_LOGS = 'WATCH_NEW_PROCESS_LOGS'; export const WATCH_NEW_PROCESS_LOGS = 'WATCH_NEW_PROCESS_LOGS';
export const STOP_NEW_PROCESS_LOGS = 'STOP_NEW_PROCESS_LOGS'; export const STOP_NEW_PROCESS_LOGS = 'STOP_NEW_PROCESS_LOGS';

View File

@ -17,6 +17,7 @@ import {
listenToServices as listenToServicesAction, listenToServices as listenToServicesAction,
listenToContracts as listenToContractsAction, listenToContracts as listenToContractsAction,
initRegularTxs as initRegularTxsAction, initRegularTxs as initRegularTxsAction,
stopRegularTxs as stopRegularTxsAction,
changeTheme, fetchTheme changeTheme, fetchTheme
} from '../actions'; } from '../actions';
@ -71,7 +72,7 @@ class AppContainer extends Component {
this.doAuthenticate(); this.doAuthenticate();
} }
const enableRegularTxs = !!getQueryParam(this.props.location, ENABLE_REGULAR_TXS); const enableRegularTxs = getQueryParam(this.props.location, ENABLE_REGULAR_TXS);
if (getQueryToken(this.props.location) && if (getQueryToken(this.props.location) &&
(!this.props.credentials.authenticating || (!this.props.credentials.authenticating ||
@ -85,9 +86,12 @@ class AppContainer extends Component {
this.props.listenToServices(); this.props.listenToServices();
this.props.fetchPlugins(); this.props.fetchPlugins();
this.props.listenToContracts(); this.props.listenToContracts();
if (enableRegularTxs) { if (enableRegularTxs === "true") {
this.props.initRegularTxs(); this.props.initRegularTxs();
this.props.history.replace(stripQueryParam(this.props.location, ENABLE_REGULAR_TXS)); this.props.history.replace(stripQueryParam(this.props.location, ENABLE_REGULAR_TXS));
} else if (enableRegularTxs === "false") {
this.props.stopRegularTxs();
this.props.history.replace(stripQueryParam(this.props.location, ENABLE_REGULAR_TXS));
} }
} }
} }
@ -158,7 +162,8 @@ AppContainer.propTypes = {
history: PropTypes.object, history: PropTypes.object,
listenToServices: PropTypes.func, listenToServices: PropTypes.func,
listenToContracts: PropTypes.func, listenToContracts: PropTypes.func,
initRegularTxs: PropTypes.func initRegularTxs: PropTypes.func,
stopRegularTxs: PropTypes.func
}; };
function mapStateToProps(state) { function mapStateToProps(state) {
@ -184,6 +189,7 @@ export default withRouter(connect(
changeTheme: changeTheme.request, changeTheme: changeTheme.request,
fetchTheme: fetchTheme.request, fetchTheme: fetchTheme.request,
listenToContracts: listenToContractsAction, listenToContracts: listenToContractsAction,
initRegularTxs: initRegularTxsAction.request initRegularTxs: initRegularTxsAction.request,
stopRegularTxs: stopRegularTxsAction.request
}, },
)(AppContainer)); )(AppContainer));

View File

@ -79,7 +79,8 @@ export const debugStepIntoForward = doRequest.bind(null, actions.debugStepIntoFo
export const debugStepIntoBackward = doRequest.bind(null, actions.debugStepIntoBackward, api.debugStepIntoBackward); export const debugStepIntoBackward = doRequest.bind(null, actions.debugStepIntoBackward, api.debugStepIntoBackward);
export const toggleBreakpoint = doRequest.bind(null, actions.toggleBreakpoint, api.toggleBreakpoint); export const toggleBreakpoint = doRequest.bind(null, actions.toggleBreakpoint, api.toggleBreakpoint);
export const authenticate = doRequest.bind(null, actions.authenticate, api.authenticate); export const authenticate = doRequest.bind(null, actions.authenticate, api.authenticate);
export const initRegularTxs = doRequest.bind(null, actions.initRegularTxs, api.initRegularTxs); export const initRegularTxs = doRequest.bind(null, actions.initRegularTxs, api.regularTxs);
export const stopRegularTxs = doRequest.bind(null, actions.stopRegularTxs, api.regularTxs);
export const fetchCredentials = doRequest.bind(null, actions.fetchCredentials, storage.fetchCredentials); export const fetchCredentials = doRequest.bind(null, actions.fetchCredentials, storage.fetchCredentials);
export const saveCredentials = doRequest.bind(null, actions.saveCredentials, storage.saveCredentials); export const saveCredentials = doRequest.bind(null, actions.saveCredentials, storage.saveCredentials);
@ -348,6 +349,10 @@ export function *watchInitRegularTxs() {
yield takeEvery(actions.INIT_REGULAR_TXS[actions.REQUEST], initRegularTxs); yield takeEvery(actions.INIT_REGULAR_TXS[actions.REQUEST], initRegularTxs);
} }
export function *watchStopRegularTxs() {
yield takeEvery(actions.STOP_REGULAR_TXS[actions.REQUEST], stopRegularTxs);
}
function createChannel(socket) { function createChannel(socket) {
return eventChannel(emit => { return eventChannel(emit => {
socket.onmessage = ((message) => { socket.onmessage = ((message) => {
@ -591,6 +596,7 @@ export default function *root() {
fork(watchPostFileSuccess), fork(watchPostFileSuccess),
fork(watchPostFolderSuccess), fork(watchPostFolderSuccess),
fork(watchListenContracts), fork(watchListenContracts),
fork(watchInitRegularTxs) fork(watchInitRegularTxs),
fork(watchStopRegularTxs)
]); ]);
} }

View File

@ -228,7 +228,7 @@ export function toggleBreakpoint(payload) {
return post('/debugger/breakpoint', {params: payload, credentials: payload.credentials}); return post('/debugger/breakpoint', {params: payload, credentials: payload.credentials});
} }
export function initRegularTxs(payload) { export function regularTxs(payload) {
return get('/regular-txs', {params: payload, credentials: payload.credentials}); return get('/regular-txs', {params: payload, credentials: payload.credentials});
} }

View File

@ -60,8 +60,16 @@ class BlockchainListener {
this.embark.registerAPICall( this.embark.registerAPICall(
'get', 'get',
'/embark-api/regular-txs', '/embark-api/regular-txs',
(req, _res) => { (req, res) => {
this.events.request(`regularTxs:${req.query.mode === 'on' ? 'start' : 'stop'}`); if(!req.query.mode || !['on', 'off'].includes(req.query.mode)) {
return res.status(400).send("Invalid parameter 'mode' provided. Must be one of: ['on', 'off']");
}
this.events.request(`regularTxs:${req.query.mode === 'on' ? 'start' : 'stop'}`, (err, result) => {
if(err) {
return res.send({ error: err.message });
}
res.send(result);
});
} }
); );
} }

View File

@ -13,7 +13,7 @@ Blockchain.connect = function(options, callback) {
const connect = ({ const connect = ({
dappConnection, dappConnection,
dappAutoEnable = true, dappAutoEnable = true,
warnAboutMetamask, warnIfMetamask,
blockchainClient = '' blockchainClient = ''
}) => { }) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -21,8 +21,8 @@ Blockchain.connect = function(options, callback) {
this.doFirst((done) => { this.doFirst((done) => {
this.autoEnable = dappAutoEnable; this.autoEnable = dappAutoEnable;
this.doConnect(dappConnection, { this.doConnect(dappConnection, {
warnAboutMetamask: warnAboutMetamask, warnAboutMetamask: warnIfMetamask,
blockchainClient: blockchainClient blockchainClient
}, async (err) => { }, async (err) => {
let _err = err; let _err = err;
try { try {