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

Commit

Permalink
feat(Browser): run extra check before signup, recovery and account cr…
Browse files Browse the repository at this point in the history
…eation
  • Loading branch information
Sjors committed Jun 7, 2016
1 parent 48d8b36 commit 9374bf9
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 24 deletions.
12 changes: 10 additions & 2 deletions assets/js/controllers/accountForm.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ angular
.module('walletApp')
.controller('AccountFormCtrl', AccountFormCtrl);

function AccountFormCtrl ($scope, Wallet, $uibModalInstance, $log, $translate, account) {
function AccountFormCtrl ($scope, Wallet, $uibModalInstance, $log, $translate, account, Alerts) {
$scope.accounts = Wallet.accounts;

$scope.fields = {
Expand Down Expand Up @@ -34,7 +34,15 @@ function AccountFormCtrl ($scope, Wallet, $uibModalInstance, $log, $translate, a

const cancel = () => $scope.status.busy = false;

Wallet.createAccount($scope.fields.name, success, error, cancel);
$scope.$$postDigest(() => {
if (!Wallet.my.browserCheck()) {
$scope.status.busy = false;
Alerts.displayError($translate.instant('UNSUITABLE_BROWSER'), true);
$scope.close();
} else {
Wallet.createAccount($scope.fields.name, success, error, cancel);
}
});
};

$scope.updateAccount = () => {
Expand Down
14 changes: 12 additions & 2 deletions assets/js/controllers/recoverFunds.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,18 @@ function RecoverFundsCtrl ($scope, $rootScope, $state, $timeout, $translate, $co
};

$scope.nextStep = () => {
$scope.currentStep++;
$scope.fields.confirmation = '';
$scope.working = true;
$scope.$$postDigest(() => {
if (!Wallet.my.browserCheck()) {
$scope.working = false;
$scope.browser.disabled = true;
$scope.browser.msg = $translate.instant('UNSUITABLE_BROWSER');
} else {
$scope.working = false;
$scope.currentStep++;
$scope.fields.confirmation = '';
}
});
};

$scope.goBack = () => {
Expand Down
30 changes: 19 additions & 11 deletions assets/js/controllers/signup.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ angular
.module('walletApp')
.controller('SignupCtrl', SignupCtrl);

SignupCtrl.$inject = ['$scope', '$state', '$cookies', '$filter', '$translate', '$uibModal', 'Wallet', 'Alerts', 'currency', 'languages'];
SignupCtrl.$inject = ['$scope', '$state', '$cookies', '$filter', '$translate', '$uibModal', 'Wallet', 'Alerts', 'currency', 'languages', 'MyWallet'];

function SignupCtrl ($scope, $state, $cookies, $filter, $translate, $uibModal, Wallet, Alerts, currency, languages) {
function SignupCtrl ($scope, $state, $cookies, $filter, $translate, $uibModal, Wallet, Alerts, currency, languages, MyWallet) {
$scope.working = false;
$scope.alerts = Alerts.alerts;
$scope.status = Wallet.status;
Expand Down Expand Up @@ -58,16 +58,24 @@ function SignupCtrl ($scope, $state, $cookies, $filter, $translate, $uibModal, W
$scope.signup = () => {
if ($scope.signupForm.$valid) {
$scope.working = true;
$scope.createWallet((uid, sessionToken) => {
$scope.working = false;
if (uid != null) {
$cookies.put('uid', uid);
$cookies.put('session', sessionToken);
$scope.$$postDigest(() => {
if (!MyWallet.browserCheck()) {
$scope.browser.disabled = true;
$scope.browser.msg = $translate.instant('UNSUITABLE_BROWSER');
$scope.working = false;
} else {
$scope.createWallet((uid, sessionToken) => {
$scope.working = false;
if (uid != null) {
$cookies.put('uid', uid);
$cookies.put('session', sessionToken);
}
if ($scope.autoReload) {
$cookies.put('password', $scope.fields.password);
}
$scope.close('');
});
}
if ($scope.autoReload) {
$cookies.put('password', $scope.fields.password);
}
$scope.close('');
});
}
};
Expand Down
3 changes: 3 additions & 0 deletions tests/controllers/account_form_ctrl_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe "AccountFormCtrl", ->
angular.mock.inject ($injector) ->
Wallet = $injector.get("Wallet")
MyWallet = $injector.get("MyWallet")
Wallet.my.browserCheck = () -> true

Wallet.accounts = () -> accounts

Expand Down Expand Up @@ -68,11 +69,13 @@ describe "AccountFormCtrl", ->
it "should be created", inject((Wallet) ->
before = Wallet.accounts().length
scope.createAccount()
scope.$digest()
expect(Wallet.accounts().length).toBe(before + 1)
)

it "should have a name", inject((Wallet) ->
scope.createAccount()
scope.$digest()
expect(Wallet.accounts()[Wallet.accounts().length - 1].label).toBe("New Account")
)

Expand Down
18 changes: 9 additions & 9 deletions tests/controllers/recover_funds_ctrl_spec.coffee
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
describe "RecoverFundsCtrl", ->
scope = undefined
Wallet = undefined
MyWallet = undefined

beforeEach angular.mock.module("walletApp")

beforeEach ->
angular.mock.inject ($injector, $rootScope, $controller) ->
Wallet = $injector.get("Wallet")
MyWallet = $injector.get("MyWallet")

Wallet.login = (guid, pw, success, error) -> success()
Wallet.my.recoverFromMnemonic = (email, password, mnemonic, bip39, success, error) ->
Wallet.my.recoverFromMnemonic = (email, password, mnemonic, bip39, success, error) ->
success({email,password,mnemonic,bip39})


Wallet.my.browserCheck = () -> true

scope = $rootScope.$new()

$controller "RecoverFundsCtrl",
$scope: scope

scope.$digest()

scope.fields = {
mnemonic: 'bitcoin is not just a currency it is a way of life'
}

return

return
Expand All @@ -40,11 +40,12 @@ describe "RecoverFundsCtrl", ->

it "should be able to increase steps", ->
scope.nextStep()
scope.$digest()
expect(scope.currentStep).toBe(2)

it "should be able to go back steps", ->
scope.goBack()
expect(scope.currentStep).toBe(0)
expect(scope.currentStep).toBe(0)

describe "performImport function", ->

Expand All @@ -54,4 +55,3 @@ describe "RecoverFundsCtrl", ->
expect(scope.working).toBe(false)
$timeout.flush()
)

8 changes: 8 additions & 0 deletions tests/controllers/signup_controller_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ describe "SignupCtrl", ->
beforeEach ->
angular.mock.inject ($injector, $rootScope, $controller, $compile, $templateCache) ->
Wallet = $injector.get("Wallet")

Wallet.my.browserCheck = () -> true

$state = $injector.get("$state") # This is a mock
$state.params = {email: ''}

Expand Down Expand Up @@ -54,6 +57,7 @@ describe "SignupCtrl", ->
scope.$digest()

scope.signup()
scope.$digest()
expect(scope.createWallet).not.toHaveBeenCalled()

describe "password", ->
Expand Down Expand Up @@ -107,6 +111,8 @@ describe "SignupCtrl", ->
it "should call createWallet()", ->
spyOn(scope, "createWallet")
scope.signup()
scope.$digest()

expect(scope.createWallet).toHaveBeenCalled()

it "should not call createWallet() if validation failed", ->
Expand All @@ -127,6 +133,7 @@ describe "SignupCtrl", ->
it "should add uid to cookies", inject(($cookies) ->
spyOn($cookies, 'put')
scope.signup()
scope.$digest()
expect($cookies.put).toHaveBeenCalledWith('uid', "new_guid")
)

Expand All @@ -136,6 +143,7 @@ describe "SignupCtrl", ->
scope.fields.password = "testing"

scope.signup()
scope.$digest()
expect($cookies.put).toHaveBeenCalledWith('password', "testing")
)

Expand Down

0 comments on commit 9374bf9

Please sign in to comment.