This repository has been archived by the owner on Apr 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #278 from LiskHQ/189-refactor-new-passphrase-modal
Refactor save passphrase modal into a component - Closes #189
- Loading branch information
Showing
14 changed files
with
200 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import './login.less'; | ||
import './save.less'; | ||
|
||
app.component('login', { | ||
template: require('./login.pug')(), | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import './savePassphrase.less'; | ||
|
||
app.component('savePassphrase', { | ||
template: require('./savePassphrase.pug')(), | ||
bindings: { | ||
passphrase: '<', | ||
}, | ||
controller: class savePassphrase { | ||
constructor($scope, $state, $mdDialog) { | ||
this.$mdDialog = $mdDialog; | ||
this.$state = $state; | ||
|
||
$scope.$watch('$ctrl.missing_input', () => { | ||
this.missing_ok = this.missing_input && this.missing_input === this.missing_word; | ||
}); | ||
} | ||
|
||
next() { | ||
this.enter = true; | ||
|
||
const words = this.passphrase.split(' '); | ||
const missingNumber = parseInt(Math.random() * words.length, 10); | ||
|
||
this.missing_word = words[missingNumber]; | ||
this.pre = words.slice(0, missingNumber).join(' '); | ||
this.pos = words.slice(missingNumber + 1).join(' '); | ||
} | ||
|
||
ok() { | ||
this.$mdDialog.hide(); | ||
this.$state.reload(); | ||
} | ||
|
||
close() { | ||
this.$mdDialog.cancel(); | ||
this.$state.reload(); | ||
} | ||
}, | ||
}); | ||
|
2 changes: 1 addition & 1 deletion
2
src/components/login/save.less → ...components/passphrase/savePassphrase.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
.dialog-save { | ||
save-passphrase { | ||
.missing { | ||
padding: 0 5px 0; | ||
font-weight: bold; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
form | ||
md-toolbar | ||
.md-toolbar-tools | ||
h2 | ||
span(ng-if="!$ctrl.enter") Save your passphrase in a safe place! | ||
span(ng-if="$ctrl.enter") Enter the missing word to continue | ||
md-dialog-content | ||
.md-dialog-content | ||
md-input-container.md-block(ng-if="!$ctrl.enter") | ||
textarea.passphrase(ng-bind='$ctrl.passphrase', md-autofocus, readonly) | ||
div(ng-if="$ctrl.enter") | ||
p.passphrase | ||
span {{ $ctrl.pre }} | ||
span.missing ----- | ||
span {{ $ctrl.pos }} | ||
md-input-container.md-block(md-is-error='!$ctrl.missing_ok') | ||
label Enter the missing word | ||
input(ng-model='$ctrl.missing_input') | ||
md-dialog-actions(layout='row') | ||
md-button.close-button(ng-click="$ctrl.close()") Close | ||
span(flex) | ||
md-button.yes-its-save-button(ng-click="$ctrl.next()", ng-show='!$ctrl.enter') Yes! It's safe! | ||
md-button.ok-button(ng-click="$ctrl.ok()", ng-show='$ctrl.enter', ng-disabled='!$ctrl.missing_ok') OK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,40 @@ | ||
import './index.less'; | ||
|
||
import './theme/theme'; | ||
import './util/animateOnChange/animateOnChange'; | ||
import './components/delegateRegistration/delegateRegistration'; | ||
import './components/delegates/delegates'; | ||
import './components/delegates/vote'; | ||
import './components/forging/forging'; | ||
import './components/header/header'; | ||
import './components/login/login'; | ||
import './components/lsk/lsk'; | ||
import './components/main/main'; | ||
import './components/main/setSecondPassService'; | ||
import './components/main/setSecondPassDirective'; | ||
import './components/login/login'; | ||
import './components/login/passphrase'; | ||
import './components/top/top'; | ||
import './components/header/header'; | ||
import './components/main/setSecondPassService'; | ||
import './components/passphrase/passphrase'; | ||
import './components/passphrase/passphraseService'; | ||
import './components/passphrase/savePassphrase'; | ||
import './components/send/send'; | ||
import './components/send/sendModalService'; | ||
import './components/send/sendModalDirective'; | ||
import './components/transactions/transactions'; | ||
import './components/timestamp/timestamp'; | ||
import './components/lsk/lsk'; | ||
import './components/forging/forging'; | ||
import './components/delegates/delegates'; | ||
import './components/delegates/vote'; | ||
import './components/send/sendModalService'; | ||
import './components/signVerify/signMessage'; | ||
import './components/signVerify/verifyMessage'; | ||
import './components/delegateRegistration/delegateRegistration'; | ||
import './components/timestamp/timestamp'; | ||
import './components/top/top'; | ||
import './components/transactions/transactions'; | ||
import './theme/theme'; | ||
import './util/animateOnChange/animateOnChange'; | ||
|
||
import './services/api/peers'; | ||
import './services/lsk'; | ||
import './services/dialog'; | ||
import './services/passphrase'; | ||
import './services/signVerify'; | ||
import './services/account'; | ||
import './services/api/accountApi'; | ||
import './services/api/delegateApi'; | ||
import './services/api/forgingApi'; | ||
import './services/api/accountApi'; | ||
import './services/api/peers'; | ||
import './services/dialog'; | ||
import './services/lsk'; | ||
import './services/signVerify'; | ||
import './services/sync'; | ||
|
||
import './filters/lsk'; | ||
|
||
import './states'; | ||
import './run'; | ||
import './states'; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
const chai = require('chai'); | ||
const sinon = require('sinon'); | ||
const sinonChai = require('sinon-chai'); | ||
|
||
const expect = chai.expect; | ||
chai.use(sinonChai); | ||
const PASSPHRASE = 'illegal symbol search tree deposit youth mixture craft amazing tool soon unit'; | ||
|
||
describe('Save passphrase component', () => { | ||
let $compile; | ||
let $rootScope; | ||
let element; | ||
let $scope; | ||
|
||
beforeEach(angular.mock.module('app')); | ||
|
||
beforeEach(inject((_$compile_, _$rootScope_) => { | ||
$compile = _$compile_; | ||
$rootScope = _$rootScope_; | ||
})); | ||
|
||
beforeEach(() => { | ||
$scope = $rootScope.$new(); | ||
$scope.passphrase = PASSPHRASE; | ||
element = $compile('<save-passphrase passphrase="passphrase"></save-passphrase>')($scope); | ||
$rootScope.$digest(); | ||
}); | ||
|
||
it('should contain an input field with the passphrase', () => { | ||
expect(element.find('textarea').val()).to.equal(PASSPHRASE); | ||
}); | ||
|
||
it('should ask for a missing word when "yes-its-save-button" clicked', () => { | ||
element.find('.yes-its-save-button').click(); | ||
expect(element.find('label').text()).to.equal('Enter the missing word'); | ||
}); | ||
|
||
describe('Save passphrase component controller', () => { | ||
let controller; | ||
let $componentController; | ||
let dialogMock; | ||
let stateMock; | ||
|
||
beforeEach(inject((_$componentController_) => { | ||
$componentController = _$componentController_; | ||
})); | ||
|
||
beforeEach(() => { | ||
$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', () => { | ||
dialogMock.expects('hide'); | ||
stateMock.expects('reload'); | ||
|
||
controller.ok(); | ||
}); | ||
}); | ||
|
||
describe('close()', () => { | ||
it('calls $mdDialog.cancel and $state.reload', () => { | ||
dialogMock.expects('cancel'); | ||
stateMock.expects('reload'); | ||
|
||
controller.close(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters