Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
Merge pull request #291 from LiskHQ/280-persist-network-on-new-account
Browse files Browse the repository at this point in the history
Keep selected network on new account cancellation - Closes #280
  • Loading branch information
slaweet authored Jun 2, 2017
2 parents ef7aa90 + a90e985 commit 3231e43
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
16 changes: 16 additions & 0 deletions src/components/login/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,19 @@ app.component('login', {
custom: true,
address: 'http://localhost:8000',
}];

this.network = this.networks[0];
try {
const network = JSON.parse(this.$cookies.get('network'));
if (network.custom) {
this.networks[2].address = network.address;
this.network = this.networks[2];
} else if (network.testnet) {
this.network = this.networks[1];
}
} catch (e) {
this.$cookies.remove('network');
}

this.$scope.$watch('$ctrl.input_passphrase', val => this.valid = this.Passphrase.isValidPassphrase(val));
this.$timeout(this.devTestAccount.bind(this), 200);
Expand All @@ -51,6 +63,9 @@ app.component('login', {
this.passConfirmSubmit(args.passphrase);
}
});
this.$scope.$on('onSignupCancel', () => {
this.generatingNewPassphrase = false;
});
}

/**
Expand All @@ -68,6 +83,7 @@ app.component('login', {
passphrase: this.Passphrase.normalize(_passphrase),
network: this.network,
});
this.$cookies.put('network', JSON.stringify(this.network));
this.$state.go(this.$rootScope.landingUrl || 'main.transactions');
} else {
this.dialog.errorToast(`Failed to connect to node ${this.network.address}`);
Expand Down
7 changes: 3 additions & 4 deletions src/components/passphrase/savePassphrase.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ app.component('savePassphrase', {
okButtonLabel: '<',
},
controller: class savePassphrase {
constructor($scope, $state, $mdDialog) {
constructor($scope, $rootScope, $mdDialog) {
this.$mdDialog = $mdDialog;
this.$state = $state;
this.$rootScope = $rootScope;

this.step = 1;

Expand All @@ -31,7 +31,6 @@ app.component('savePassphrase', {

ok() {
this.$mdDialog.hide();
this.$state.reload();
}

back() {
Expand All @@ -40,7 +39,7 @@ app.component('savePassphrase', {

close() {
this.$mdDialog.cancel();
this.$state.reload();
this.$rootScope.$broadcast('onSignupCancel');
}
},
});
Expand Down
13 changes: 2 additions & 11 deletions test/components/passphrase/savePassphrase.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ describe('Save passphrase component', () => {
let controller;
let $componentController;
let dialogMock;
let stateMock;

beforeEach(inject((_$componentController_) => {
$componentController = _$componentController_;
Expand All @@ -49,32 +48,24 @@ describe('Save passphrase component', () => {
$scope = $rootScope.$new();
$scope.passphrase = PASSPHRASE;
controller = $componentController('savePassphrase', $scope, {});

dialogMock = sinon.mock(controller.$mdDialog);
stateMock = sinon.mock(controller.$state);
});

afterEach(() => {
dialogMock.verify();
dialogMock.restore();
stateMock.verify();
stateMock.restore();
});

describe('ok()', () => {
it('calls $mdDialog.hide and $state.reload', () => {
it('calls $mdDialog.hide', () => {
dialogMock.expects('hide');
stateMock.expects('reload');

controller.ok();
});
});

describe('close()', () => {
it('calls $mdDialog.cancel and $state.reload', () => {
it('calls $mdDialog.cancel', () => {
dialogMock.expects('cancel');
stateMock.expects('reload');

controller.close();
});
});
Expand Down

0 comments on commit 3231e43

Please sign in to comment.