Skip to content

Commit

Permalink
Merge pull request #3802 from LiskHQ/3784-bugfix-network-selector
Browse files Browse the repository at this point in the history
Update fallback network to mainnet when cache and settings is not available - Closes #3784
  • Loading branch information
ManuGowda authored Sep 20, 2021
2 parents b0819b3 + a54e35a commit e0dd4d9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 17 deletions.
3 changes: 2 additions & 1 deletion app/src/modules/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const setConfig = ({
};

export const readConfig = () => {
const value = storage.get('config');
// Ensure to return empty config if storage does not hold any value
const value = storage.get('config') || {};
win.send({ event: 'configRetrieved', value });
};
25 changes: 25 additions & 0 deletions app/src/modules/storage.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { expect } from 'chai';
import { spy } from 'sinon';
import win from './win';
import { readConfig } from './storage';

jest.mock('electron-store');

describe('Storage', () => {
const winSendSpy = spy(win, 'send');

afterEach(() => {
win.eventStack.length = 0;
winSendSpy.restore();
});

describe('readConfig', () => {
it('should return empty config if storage has no config set', () => {
// Act
readConfig();

// Assert
expect(winSendSpy).to.have.been.calledWith({ event: 'configRetrieved', value: {} });
});
});
});
2 changes: 1 addition & 1 deletion src/utils/api/network/lsk.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const getNetworkStatus = ({
network,
});

const getServiceUrl = ({ name = networkKeys.mainNet, address = 'http://localhost:4000' }) => {
const getServiceUrl = ({ name, address = 'http://localhost:4000' }) => {
if ([networkKeys.mainNet, networkKeys.testNet].includes(name)) {
return networks[name].serviceUrl;
}
Expand Down
3 changes: 2 additions & 1 deletion src/utils/getNetwork.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export const getNetworksList = () =>
name,
}));

export const getNetworkName = network => network.name || 'customNode';
// Return mainnet as back off network name when cache/local storage does not exists
export const getNetworkName = network => network.name || networkKeys.mainNet;

/**
* Returns human readable error messages
Expand Down
28 changes: 14 additions & 14 deletions src/utils/getNetwork.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,31 @@ describe('Utils: getNetwork', () => {
});
});

describe.skip('getNetworkName', () => {
it('should discover mainnet', () => {
describe('getNetworkName', () => {
it('should return mainnet if network config does not have name set', () => {
const network = {};
expect(getNetworkName(network)).toEqual('mainnet');
});

it('should return customNode', () => {
const network = {
name: 'customNode',
};
expect(getNetworkName(network, 'LSK')).toEqual('mainnet');
expect(getNetworkName(network)).toEqual(network.name);
});

it('should discover testnet', () => {
it('should return testnet', () => {
const network = {
name: 'customNode',
name: 'testnet',
};
expect(getNetworkName(network, 'LSK')).toEqual('testnet');
expect(getNetworkName(network)).toEqual(network.name);
});

it('should mark as customNode otherwise', () => {
it('should return mainnet', () => {
const network = {
name: 'customNode',
networks: {
LSK: {
nethash: 'sample_hash',
},
},
name: 'mainnet',
};
expect(getNetworkName(network, 'LSK')).toEqual('customNode');
expect(getNetworkName(network)).toEqual(network.name);
});
});

Expand Down

0 comments on commit e0dd4d9

Please sign in to comment.