Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable users to enter Lisk Service URL in network switcher - Closes #3475 #3479

Merged
merged 18 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion i18n/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,8 @@
"Try again": "Try again",
"Twitter": "Twitter",
"Type": "Type",
"Unable to connect to Lisk Service, please check the address and try again": "Unable to connect to Lisk Service, please check the address and try again",
"Unable to connect to the node, no response from the server.": "Unable to connect to the node, no response from the server.",
"Unable to connect to the node, please check the address and try again": "Unable to connect to the node, please check the address and try again",
"Undo": "Undo",
"Unlock": "Unlock",
"Unnamed account": "Unnamed account",
Expand Down
6 changes: 3 additions & 3 deletions src/components/screens/login/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import styles from './login.css';
class Login extends React.Component {
constructor() { // eslint-disable-line max-statements
super();
const { liskCoreUrl } = getAutoLogInData();
const { liskServiceUrl } = getAutoLogInData();
let loginNetwork = findMatchingLoginNetwork();
let address = '';

if (!loginNetwork) {
loginNetwork = liskCoreUrl ? networks.customNode : networks[networkKeys.mainNet];
address = liskCoreUrl || '';
loginNetwork = liskServiceUrl ? networks.customNode : networks[networkKeys.mainNet];
address = liskServiceUrl || '';
}

this.state = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ const getNetwork = (name, url) => {
};

const getInitialState = (address) => {
const { liskCoreUrl } = getAutoLogInData();
const { liskServiceUrl } = getAutoLogInData();
return {
address: liskCoreUrl || address,
address: liskServiceUrl || address,
connected: true,
isValid: true,
isCustomSelected: false,
Expand Down Expand Up @@ -115,7 +115,7 @@ const NetworkSelector = ({
isValidationLoading,
} = state;

const validationError = isValid ? '' : t('Unable to connect to the node, please check the address and try again');
const validationError = isValid ? '' : t('Unable to connect to Lisk Service, please check the address and try again');

return (
<DropdownButton
Expand Down
1 change: 1 addition & 0 deletions src/constants/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const settings = {
keys: {
loginKey: 'loginKey',
liskCoreUrl: 'liskCoreUrl',
liskServiceUrl: 'liskServiceUrl',
},
};
export default settings;
4 changes: 2 additions & 2 deletions src/store/middlewares/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ const autoLogInIfNecessary = async ({ dispatch, getState }) => {
} = getState().settings;
const autoLoginData = getAutoLogInData();

const address = autoLoginData[settings.keys.liskCoreUrl];
const address = autoLoginData[settings.keys.liskServiceUrl];
const network = address
? { name: networkKeys.customNode, address }
: { name: networkKeys.mainNet, address: networks.mainnet.nodes[0] };
: { name: networkKeys.mainNet, address: networks.mainnet.serviceUrl };
dispatch(networkSelected(network));
dispatch(networkStatusUpdated({ online: true }));

Expand Down
9 changes: 1 addition & 8 deletions src/utils/api/network/lsk.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,7 @@ const getServiceUrl = ({ name, address = 'http://localhost:4000' }) => {
if ([networkKeys.mainNet, networkKeys.testNet].includes(name)) {
return networks[name].serviceUrl;
}
if (name === networkKeys.customNode) {
const serviceUrl = window.localStorage.getItem('serviceUrl');
if (serviceUrl) {
return serviceUrl;
}
return address.replace(/:\d{2,4}/, ':9901');
}
throw Error('The node url entered does not have a corresponding service url');
return address;
};

/**
Expand Down
8 changes: 4 additions & 4 deletions src/utils/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ export const validateUrl = (value) => {
// Ignore coverage because this is only development feature
export const getAutoLogInData = /* istanbul ignore next */ () => ({
[settings.keys.loginKey]: localStorage.getItem(settings.keys.loginKey),
[settings.keys.liskCoreUrl]: localStorage.getItem(settings.keys.liskCoreUrl),
[settings.keys.liskServiceUrl]: localStorage.getItem(settings.keys.liskServiceUrl),
});

// Ignore coverage because this is only development feature
export const shouldAutoLogIn = /* istanbul ignore next */ autologin =>
autologin[settings.keys.liskCoreUrl] && autologin[settings.keys.liskCoreUrl] !== ''
autologin[settings.keys.liskServiceUrl] && autologin[settings.keys.liskServiceUrl] !== ''
&& autologin[settings.keys.loginKey] && autologin[settings.keys.loginKey] !== '';

export const findMatchingLoginNetwork = () => {
const { liskCoreUrl } = getAutoLogInData();
const { liskServiceUrl } = getAutoLogInData();
return Object.values(networks).find(({ nodes }) =>
(Array.isArray(nodes) ? nodes.includes(liskCoreUrl) : false));
(Array.isArray(nodes) ? nodes.includes(liskServiceUrl) : false));
};
2 changes: 1 addition & 1 deletion test/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ Cypress.Commands.add('addObjectToLocalStorage', (item, key, value) => {
});

Cypress.Commands.add('autologin', (passphrase, network) => {
localStorage.setItem('liskCoreUrl', network);
localStorage.setItem('liskServiceUrl', network);
localStorage.setItem('loginKey', passphrase);
});