Skip to content

Commit

Permalink
problem: too annoying "Fetch Error" for a remote RPC (#883)
Browse files Browse the repository at this point in the history
* problem: too annoying "Fetch Error" for a remote RPC
solution: display it as a temp notification
rel: fix #835

* problem: unhandled Error on initial Sync
  • Loading branch information
splix authored and gagarin55 committed Jan 22, 2019
1 parent f3630d7 commit f0c635b
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/components/common/ErrorDialog/errorDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const ErrorDialog = ({ open, error, message, handleClose, handleSubmit }) => {
onRequestClose={handleClose}
>
<p>
<strong>ERROR:</strong> An unexpected error has occured. Please restart & update emerald wallet.
<strong>ERROR:</strong> An unexpected error has occurred. Please restart & update emerald wallet.
</p>
<p>
The error was: {message}
Expand Down
3 changes: 2 additions & 1 deletion src/store/ledger/ledgerActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import uuid from 'uuid/v4';
import launcher from '../launcher';
import createLogger from '../../utils/logger';
import ActionTypes from './actionTypes';
import { dispatchRpcError } from '../wallet/screen/screenActions';

const log = createLogger('ledgerActions');
function connection(): Promise<any> {
Expand All @@ -25,7 +26,7 @@ function loadInfo(hdpath: string, addr: string) {
return api.geth.eth.getTransactionCount(addr).then((count) => {
dispatch({ type: ActionTypes.ADDR_TXCOUNT, hdpath, value: count });
});
});
}).catch(dispatchRpcError(dispatch));
};
}

Expand Down
18 changes: 6 additions & 12 deletions src/store/network/networkActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ import { intervalRates } from '../../store/config';
import createLogger from '../../utils/logger';
import ActionTypes from './actionTypes';
import history from '../wallet/history';

const log = createLogger('networkActions');

const handleFailedToFetch = (err) => {
if (err.message.includes('Failed to fetch')) { return; }
throw err;
};
import { dispatchRpcError } from '../wallet/screen/screenActions';

export function switchChain({ chain, chainId }) {
return (dispatch, getState) => {
Expand All @@ -29,7 +23,7 @@ export function loadHeight(watch) {
type: ActionTypes.BLOCK,
height: result,
});
}).catch(handleFailedToFetch);
}).catch(dispatchRpcError(dispatch));
};
}

Expand All @@ -40,7 +34,7 @@ export function loadPeerCount() {
type: ActionTypes.PEER_COUNT,
peerCount: result,
});
}).catch(handleFailedToFetch);
}).catch(dispatchRpcError(dispatch));
};
}

Expand All @@ -66,7 +60,7 @@ export function loadAddressesTransactions(addresses) {
return api.geth.ext.getTransactions(untrackedResults).then((txes) => {
return dispatch(history.actions.trackTxs(txes.map((tx) => tx.result)));
});
});
}).catch(dispatchRpcError(dispatch));
};
}

Expand All @@ -85,7 +79,7 @@ export function loadSyncing() {
type: ActionTypes.SYNCING,
syncing: false,
});
}).catch(handleFailedToFetch);
}).catch(dispatchRpcError(dispatch));
};
}

Expand All @@ -96,7 +90,7 @@ export function getGasPrice() {
type: ActionTypes.GAS_PRICE,
value: result,
});
}).catch(handleFailedToFetch);
}).catch(dispatchRpcError(dispatch));
};
}

Expand Down
5 changes: 5 additions & 0 deletions src/store/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import ledger from './ledger';
import Addressbook from './vault/addressbook';

import { readConfig, listenElectron, connecting, loadClientVersion } from './launcher/launcherActions';
import { showError } from './wallet/screen/screenActions';
import launcherReducers from './launcher/launcherReducers';
import walletReducers from './wallet/walletReducers';
import deployedTokens from '../lib/deployedTokens';
Expand Down Expand Up @@ -137,6 +138,10 @@ export function startSync() {
store.getState().accounts.get('accounts').map((account) => account.get('id'))
)))
.then(() => store.dispatch(connecting(false)))
.catch((err) => {
log.error('Failed to do initial sync', err);
store.dispatch(showError(err));
})
);

return Promise.all(promises);
Expand Down
7 changes: 4 additions & 3 deletions src/store/vault/accounts/accountActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import launcher from '../../launcher';
import network from '../../network';
import ActionTypes from './actionTypes';
import createLogger from '../../../utils/logger';
import { dispatchRpcError } from '../../wallet/screen/screenActions';

const currentChain = (state) => launcher.selectors.getChainName(state);

Expand All @@ -34,7 +35,7 @@ export function loadAccountBalance(address: string) {
accountId: address,
value: result,
});
});
}).catch(dispatchRpcError(dispatch));
// Tokens
const tokens = getState().tokens;
if (!tokens.get('loading')) {
Expand All @@ -58,7 +59,7 @@ function fetchBalances(addresses: Array<string>) {
if (!tokens.get('loading')) {
return dispatch(loadTokensBalances(addresses));
}
});
}).catch(dispatchRpcError(dispatch));
};
}

Expand Down Expand Up @@ -113,7 +114,7 @@ export function loadAccountTxCount(accountId: string) {
accountId,
value: result,
});
});
}).catch(dispatchRpcError(dispatch));
};
}

Expand Down
11 changes: 6 additions & 5 deletions src/store/vault/tokens/tokenActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { detect as detectTraceCall } from '../../../lib/traceCall';
import launcher from '../../../store/launcher';
import ActionTypes from './actionTypes';
import createLogger from '../../../utils/logger';
import { dispatchRpcError } from '../../wallet/screen/screenActions';

const tokenContract = new Contract(TokenAbi);

Expand Down Expand Up @@ -38,7 +39,7 @@ export function loadTokenBalanceOf(token: TokenInfo, accountId: string) {
token,
value: result,
});
});
}).catch(dispatchRpcError(dispatch));
}
throw new Error(`Invalid token info ${JSON.stringify(token)}`);
};
Expand Down Expand Up @@ -70,7 +71,7 @@ export function loadTokenBalances(token: TokenInfo) {
token,
});
});
});
}).catch(dispatchRpcError(dispatch));
}
};
}
Expand All @@ -91,7 +92,7 @@ export function loadTokenDetails(tokenAddress: string): () => Promise<any> {
decimals: results.decimals.result,
symbol: parseString(results.symbol.result),
});
});
}).catch(dispatchRpcError(dispatch));
};
}

Expand All @@ -110,7 +111,7 @@ export function fetchTokenDetails(tokenAddress: string): () => Promise<any> {
decimals,
symbol: parseString(symbol),
};
});
}).catch(dispatchRpcError(dispatch));
};
}

Expand Down Expand Up @@ -147,7 +148,7 @@ export function loadTokensBalances(addresses: string) {
type: ActionTypes.SET_TOKENS_BALANCES,
tokenBalances,
});
});
}).catch(dispatchRpcError(dispatch));
};
}

Expand Down
6 changes: 3 additions & 3 deletions src/store/wallet/history/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Transaction } from './types';
import ActionTypes from './actionTypes';
import { storeTransactions, loadTransactions } from './historyStorage';
import { allTrackedTxs } from './selectors';

import { dispatchRpcError } from '../../wallet/screen/screenActions';

const log = createLogger('historyActions');
const txStoreKey = (chainId) => `chain-${chainId}-trackedTransactions`;
Expand Down Expand Up @@ -40,7 +40,7 @@ function updateAndTrack(dispatch, getState, api, txs) {
})
.then((transactions) => {
dispatch({type: ActionTypes.TRACK_TXS, txs: transactions});
});
}).catch(dispatchRpcError(dispatch));
}

persistTransactions(getState());
Expand Down Expand Up @@ -117,6 +117,6 @@ export function refreshTrackedTransactions() {
dispatch({ type: ActionTypes.UPDATE_TXS, transactions });

return persistTransactions(getState());
});
}).catch(dispatchRpcError(dispatch));
};
}
8 changes: 8 additions & 0 deletions src/store/wallet/screen/screenActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import createLogger from '../../../utils/logger';

const log = createLogger('screenActions');
const logRpc = createLogger('network');

export function gotoScreen(screen, item = null) {
return {
Expand Down Expand Up @@ -71,6 +72,13 @@ export function showNotification(message, notificationType, duration, actionText
};
}

export function dispatchRpcError(dispatch) {
return (err) => {
logRpc.warn('RPC Error', err);
dispatch(showNotification('Remote server connection failure', 'warning', 2000, null, null));
};
}

export function closeNotification() {
return {
type: 'SCREEN/NOTIFICATION_CLOSE',
Expand Down

0 comments on commit f0c635b

Please sign in to comment.