fix(loading-screen): better messages in loading screen

This commit is contained in:
George Lima 2019-03-01 20:25:38 -03:00
parent cb33e86099
commit 780cc6cae1
2 changed files with 27 additions and 4 deletions

View File

@ -58,10 +58,19 @@ export const withDaemonStatusCheck = <PassedProps: {}>(
.catch((error) => {
const statusMessage = error.message === 'Something went wrong' ? 'ZEC Wallet Starting' : error.message;
this.setState((state) => {
const newProgress = state.progress > 70 ? state.progress + 2.5 : state.progress + 5;
return { progress: newProgress > 95 ? 95 : newProgress, message: statusMessage };
const isRpcOff = Math.trunc(error.statusCode / 100) === 5;
this.setState({
message: statusMessage,
});
// if rpc is off (500) we have probably started the daemon process and are waiting it to boot up
if (isRpcOff) {
this.setState((state) => {
const newProgress = state.progress > 70 ? state.progress + 2.5 : state.progress + 5;
return { progress: newProgress > 95 ? 95 : newProgress, message: statusMessage };
});
}
});
};

View File

@ -21,6 +21,15 @@ const client = got.extend({
auth: `${RPC.user}:${RPC.password}`,
});
const getMessage = (statusCode) => {
switch (statusCode) {
case 401:
return 'Not authorized to access Zcash RPC, please check your rpcuser and rpcpassword';
default:
return 'Something went wrong';
}
};
const api: APIMethods = METHODS.reduce(
(obj, method) => ({
...obj,
@ -34,7 +43,12 @@ const api: APIMethods = METHODS.reduce(
},
})
.then(data => Promise.resolve(data.body && data.body.result))
.catch(payload => Promise.reject(new Error(payload.body?.error.message || 'Something went wrong'))),
.catch(payload =>
// eslint-disable-next-line
Promise.reject({
message: payload.body?.error?.message || getMessage(payload.statusCode),
statusCode: payload.statusCode,
})),
}),
{},
);