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

Commit

Permalink
Merge branch 'development' into 148_fix-new-account-cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
karmacoma authored May 5, 2017
2 parents 99f81e0 + bd93b7b commit 9b00113
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 103 deletions.
7 changes: 1 addition & 6 deletions src/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
"no-restricted-properties": "off",
"no-return-assign": "off",
"no-underscore-dangle": "off",
"no-param-reassign": [
"error", {
"props": true,
"ignorePropertyModificationsFor": ["scope", "$scope", "rootScope", "$rootScope"]
}
]
"no-param-reassign": "off"
}
}
46 changes: 33 additions & 13 deletions src/app/components/login/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,38 @@ app.component('login', {
/* eslint no-param-reassign: ["error", { "props": false }] */

constructor($scope, $rootScope, $timeout, $document, $mdMedia,
$cookies, $peers, Passphrase, $state, Account) {
$cookies, $location, Passphrase, $state, Account) {
this.$scope = $scope;
this.$rootScope = $rootScope;
this.$timeout = $timeout;
this.$document = $document;
this.$mdMedia = $mdMedia;
this.$cookies = $cookies;
this.$peers = $peers;
this.$location = $location;
this.$state = $state;
this.account = Account;

this.Passphrase = Passphrase;
this.generatingNewPassphrase = false;

this.networks = [{
name: 'Mainnet',
}, {
name: 'Testnet',
testnet: true,
}, {
name: 'Custom Node',
custom: true,
address: 'http://localhost:8000',
}];
this.network = this.networks[0];

this.$scope.$watch('$ctrl.input_passphrase', val => this.valid = this.Passphrase.isValidPassphrase(val));
this.$timeout(this.devTestAccount.bind(this), 200);

this.$scope.$watch(() => this.$mdMedia('xs') || this.$mdMedia('sm'), (wantsFullScreen) => {
this.$scope.customFullscreen = wantsFullScreen === true;
});
this.$scope.$watch('$ctrl.$peers.currentPeerConfig', () => {
this.$peers.setActive(this.$peers.currentPeerConfig);
});
this.$scope.$watch('$ctrl.$peers.stack', (val) => {
if (val && !this.$peers.currentPeerConfig.node) {
this.$peers.setActive($peers.stack.official[0]);
}
});

this.$scope.$on('onAfterSignup', (ev, args) => {
if (args.target === 'primary-pass') {
Expand All @@ -46,7 +50,10 @@ app.component('login', {

passConfirmSubmit(_passphrase = this.input_passphrase) {
if (this.Passphrase.normalize.constructor === Function) {
this.account.set({ passphrase: this.Passphrase.normalize(_passphrase) });
this.account.set({
passphrase: this.Passphrase.normalize(_passphrase),
network: this.network,
});

this.$state.go('main');
}
Expand All @@ -57,10 +64,23 @@ app.component('login', {
}

devTestAccount() {
const passphrase = this.$cookies.get('passphrase');
const peerStack = this.$location.search().peerStack || this.$cookies.get('peerStack');
if (peerStack === 'localhost') {
this.network = this.networks[2];
angular.merge(this.network, {
address: 'http://localhost:4000',
testnet: true,
nethash: '198f2b61a8eb95fbeed58b8216780b68f697f26b849acf00c8c93bb9b24f783d',
});
} else if (peerStack === 'testnet') {
this.network = this.networks[1];
}
const passphrase = this.$location.search().passphrase || this.$cookies.get('passphrase');
if (passphrase) {
this.input_passphrase = passphrase;
// this.$timeout(this.passConfirmSubmit.bind(this), 10);
if (this.$rootScope.logged === undefined) {
this.$timeout(this.passConfirmSubmit.bind(this), 10);
}
}
}
},
Expand Down
15 changes: 9 additions & 6 deletions src/app/components/login/login.pug
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ md-card
span.md-title Sign In
md-card-content(flex='100', flex-gt-sm='70', flex-offset-gt-sm='15')
form(ng-submit='$ctrl.passConfirmSubmit()')
md-input-container.md-block(md-is-error='$ctrl.valid === 0')
label.select Choose a peer
md-select(ng-model='$ctrl.$peers.currentPeerConfig', aria-label='Peer')
md-optgroup(ng-repeat='(name, peers) in $ctrl.$peers.stack', ng-if='peers.length', label='{{ name }}')
md-option(ng-repeat='peer in peers', ng-value='peer') {{ peer.node }}{{ peer.port ? ':' + peer.port : '' }}
md-input-container.md-block
label.select Network
md-select(ng-model='$ctrl.network', aria-label='Peer')
md-option(ng-repeat='network in $ctrl.networks', ng-value='network') {{ network.name }}
div(ng-if='$ctrl.network.custom')
md-input-container.md-block
label.pass Node address
input(type="text", ng-model="$ctrl.network.address")
md-input-container.md-block(md-is-error='$ctrl.valid === 0')
label.pass Enter your passphrase
input(type="{{ $ctrl.show_passphrase ? 'text' : 'password' }}", ng-model='$ctrl.input_passphrase', ng-disabled='$ctrl.generatingNewPassphrase', autofocus)
Expand All @@ -18,4 +21,4 @@ md-card
// md-button(ng-disabled='$ctrl.generatingNewPassphrase', ng-click='$ctrl.devTestAccount()') Dev Test Account
md-button.md-primary(ng-disabled='$ctrl.random || $ctrl.generatingNewPassphrase', ng-click='$ctrl.generatePassphrase()') NEW ACCOUNT
md-button.md-raised.md-primary(md-autofocus, ng-disabled='$ctrl.valid != undefined && $ctrl.valid !== 1', type='submit') Login
passphrase(ng-if='$ctrl.generatingNewPassphrase', data-on-login='$ctrl.onLogin', data-target='primary-pass')
passphrase(ng-if='$ctrl.generatingNewPassphrase', data-on-login='$ctrl.onLogin', data-target='primary-pass')
7 changes: 4 additions & 3 deletions src/app/components/top/top.pug
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ md-content(layout='column', layout-gt-xs='row')
i.material-icons.online(ng-show='$ctrl.$peers.online') check circle
span.md-title.title Peer
div.active-peer.value
span(ng-bind="$ctrl.$peers.currentPeerConfig.node")
span(ng-if="$ctrl.$peers.currentPeerConfig.port") :
span(ng-bind="$ctrl.$peers.currentPeerConfig.port")
span(ng-bind="$ctrl.$peers.active.currentPeer")
span(ng-if="$ctrl.$peers.active.port && $ctrl.$peers.active.port != '8000' ")
span :
span(ng-bind="$ctrl.$peers.active.port")
md-card.offline-hide(flex-gt-xs=33)
md-card-content(layout='column', layout-align='center center')
span.md-title.title Balance
Expand Down
61 changes: 18 additions & 43 deletions src/app/services/peers/peers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ import lisk from 'lisk-js';

const UPDATE_INTERVAL_CHECK = 10000;

app.factory('$peers', ($timeout, $cookies, $location, $q) => {
app.factory('$peers', ($timeout, $cookies, $location, $q, $rootScope, Account) => {
class $peers {
constructor() {
this.check();

$rootScope.$on('onAccountChange', () => {
this.setActive();
});
}

reset(active) {
Expand All @@ -16,40 +20,22 @@ app.factory('$peers', ($timeout, $cookies, $location, $q) => {
}
}

setActive(peerConf) {
const peerStack = $location.search().peerStack || $cookies.get('peerStack') || 'official';
let conf = peerConf || { };
const localhostConf = {
node: 'localhost',
port: 4000,
testnet: true,
nethash: '198f2b61a8eb95fbeed58b8216780b68f697f26b849acf00c8c93bb9b24f783d',
};
if (peerStack === 'localhost' && !peerConf) {
conf = localhostConf;
} else if (peerStack === 'testnet' && !peerConf) {
conf.testnet = true;
setActive() {
let conf = { };
const network = Account.get().network;
if (network) {
conf = network;
if (network.address) {
conf.node = network.address.split(':')[1].replace('//', '');
conf.port = network.address.match(/:([0-9]{1,5})$/)[1];
conf.ssl = network.address.split(':')[0] === 'https';
}
if (conf.testnet === undefined && conf.port !== undefined) {
conf.testnet = conf.port === '7000';
}
}

this.setPeerAPIObject(conf);
if (!this.stack) {
this.stack = this.active.listPeers();
this.stack.localhost = [localhostConf, {
node: 'localhost',
port: 7000,
testnet: true,
}, {
node: 'localhost',
port: 8000,
}];
this.peerByName = {};
Object.keys(this.stack).forEach((key) => {
this.stack[key].forEach(peer => this.peerByName[peer.node + (peer.port || '')] = peer);
});
}
this.currentPeerConfig = this.peerByName[this.active.currentPeer + this.active.port] ||
this.peerByName[this.active.currentPeer];

this.check();
}

Expand Down Expand Up @@ -104,17 +90,6 @@ app.factory('$peers', ($timeout, $cookies, $location, $q) => {
return deferred.promise;
};

this.active.listTransactionsPromise = (address, limit, offset) => {
const deferred = $q.defer();
this.active.listTransactions(address, limit, offset, (data) => {
if (data.success) {
return deferred.resolve(data);
}
return deferred.reject(data);
});
return deferred.promise;
};

this.active.setSignature = (secondSecret, publicKey, secret) => {
const deferred = $q.defer();
this.active.sendRequest('signatures', { secondSecret, publicKey, secret }, (res) => {
Expand Down
18 changes: 9 additions & 9 deletions src/test/components/forging/forging.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ describe('Forging component', () => {
vote: '9999982470000000',
};

account.set({
passphrase: delegate.passphrase,
balance: lsk.from(100),
});

$peers.active = { sendRequest() {} };
const mock = sinon.mock($peers.active);
mock.expects('sendRequest').withArgs('blocks').callsArgWith(2, {
Expand All @@ -53,10 +58,6 @@ describe('Forging component', () => {
mock.expects('sendRequest').withArgs('delegates/forging/getForgedByAccount').exactly(5);

$scope = $rootScope.$new();
account.set({
passphrase: delegate.passphrase,
balance: lsk.from(100),
});
element = $compile('<forging account="account"></forging>')($scope);
$scope.$digest();
});
Expand Down Expand Up @@ -91,15 +92,13 @@ describe('forging component controller', () => {
let controller;
let $componentController;
let activePeerMock;
let $peers;
let delegate;
let blocks;
let account;

beforeEach(inject((_$componentController_, _$rootScope_, _$peers_, _Account_) => {
beforeEach(inject((_$componentController_, _$rootScope_, _Account_) => {
$componentController = _$componentController_;
$rootScope = _$rootScope_;
$peers = _$peers_;
account = _Account_;
}));

Expand All @@ -122,8 +121,6 @@ describe('forging component controller', () => {
vote: '9999982470000000',
};

$peers.active = { sendRequest() {} };
activePeerMock = sinon.mock($peers.active);

$scope = $rootScope.$new();
account.set({
Expand All @@ -136,6 +133,9 @@ describe('forging component controller', () => {
// balance: '10000',
// },
});

controller.$peers.active = { sendRequest() {} };
activePeerMock = sinon.mock(controller.$peers.active);
});

describe('updateDelegate()', () => {
Expand Down
23 changes: 1 addition & 22 deletions src/test/components/login/login.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Login component', () => {
expect(element.find('form md-input-container label.pass').text()).to.equal(PASS_LABEL_TEXT);
});

const SELECT_LABEL_TEXT = 'Choose a peer';
const SELECT_LABEL_TEXT = 'Network';
it(`should contain a select element with label saying "${SELECT_LABEL_TEXT}"`, () => {
expect(element.find('form md-input-container label.select').text()).to.equal(SELECT_LABEL_TEXT);
});
Expand Down Expand Up @@ -92,27 +92,6 @@ describe('Login controller', () => {
});

describe('controller()', () => {
it('should define a watcher for $ctrl.$peers.currentPeerConfig', () => {
$scope.$apply();
const peers = controller.$peers;
const spy = sinon.spy(peers, 'setActive');
peers.currentPeerConfig = peers.stack.localhost[0];
$scope.$apply();
peers.currentPeerConfig = peers.stack.official[0];
$scope.$apply();
expect(spy).to.have.been.calledWith();
});

it('should be able to change the active peer', () => {
$scope.$apply();
controller.$peers.setActive(controller.$peers.stack.localhost[0]);
$scope.$apply();
expect(controller.$peers.currentPeerConfig).to.equal(controller.$peers.stack.localhost[0]);
controller.$peers.setActive(controller.$peers.stack.official[0]);
$scope.$apply();
expect(controller.$peers.currentPeerConfig).to.equal(controller.$peers.stack.official[0]);
});

it('should define a watcher for $ctrl.input_passphrase', () => {
$scope.$apply();
const spy = sinon.spy(Passphrase, 'isValidPassphrase');
Expand Down
2 changes: 1 addition & 1 deletion src/test/services/peers/peers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Factory: $peers', () => {
expect($peers.active).to.equal(undefined);
$peers.setActive();
expect($peers.active).not.to.equal(undefined);
expect($peers.stack.official).to.include({ node: $peers.active.currentPeer });
expect($peers.active.currentPeer).not.to.equal(undefined);
});
});

Expand Down

0 comments on commit 9b00113

Please sign in to comment.