one view/controller
This commit is contained in:
parent
945233363a
commit
3cd1498512
9 changed files with 295 additions and 379 deletions
|
|
@ -1,11 +1,21 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('backupController',
|
||||
function($rootScope, $scope, $timeout, $log, $compile, lodash, profileService, go, gettext, confirmDialog, notification, bwsError) {
|
||||
function($rootScope, $scope, $timeout, $log, $state, $compile, go, lodash, profileService, bwcService, bwsError) {
|
||||
|
||||
var self = this;
|
||||
var fc = profileService.focusedClient;
|
||||
var customWords = [];
|
||||
var mnemonic = null;
|
||||
self.xPrivKey = null;
|
||||
self.step1 = true;
|
||||
self.step2 = false;
|
||||
self.step3 = false;
|
||||
self.step4 = false;
|
||||
self.deleted = false;
|
||||
self.credentialsEncrypted = false;
|
||||
self.selectComplete = false;
|
||||
self.backupNoOk = false;
|
||||
|
||||
if (fc.credentials && !fc.credentials.mnemonicEncrypted && !fc.credentials.mnemonic)
|
||||
self.deleted = true;
|
||||
|
|
@ -14,7 +24,52 @@ angular.module('copayApp.controllers').controller('backupController',
|
|||
self.credentialsEncrypted = true;
|
||||
passwordRequest();
|
||||
} else
|
||||
setWords(fc.getMnemonic());
|
||||
setWords(getMnemonic());
|
||||
|
||||
function getMnemonic() {
|
||||
mnemonic = fc.getMnemonic();
|
||||
self.xPrivKey = fc.credentials.xPrivKey;
|
||||
profileService.lockFC();
|
||||
return mnemonic;
|
||||
}
|
||||
|
||||
self.goToStep2 = function() {
|
||||
self.step1 = false;
|
||||
self.step2 = true;
|
||||
self.step3 = false;
|
||||
self.step4 = false;
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
}, 1);
|
||||
}
|
||||
|
||||
self.goToStep3 = function() {
|
||||
if (self.mnemonicHasPassphrase) {
|
||||
self.step1 = false;
|
||||
self.step2 = false;
|
||||
self.step3 = true;
|
||||
self.step4 = false;
|
||||
} else {
|
||||
self.step1 = false;
|
||||
self.step2 = false;
|
||||
self.step3 = false;
|
||||
self.step4 = true;
|
||||
}
|
||||
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
}, 1);
|
||||
}
|
||||
|
||||
self.goToStep4 = function() {
|
||||
self.step1 = false;
|
||||
self.step2 = false;
|
||||
self.step3 = false;
|
||||
self.step4 = true;
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
}, 1);
|
||||
}
|
||||
|
||||
function setWords(words) {
|
||||
if (words) {
|
||||
|
|
@ -24,9 +79,20 @@ angular.module('copayApp.controllers').controller('backupController',
|
|||
}
|
||||
};
|
||||
|
||||
self.toggle = function() {
|
||||
self.error = "";
|
||||
|
||||
if (self.credentialsEncrypted)
|
||||
passwordRequest();
|
||||
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
}, 1);
|
||||
};
|
||||
|
||||
function passwordRequest() {
|
||||
try {
|
||||
setWords(fc.getMnemonic());
|
||||
setWords(getMnemonic());
|
||||
} catch (e) {
|
||||
if (e.message && e.message.match(/encrypted/) && fc.isPrivKeyEncrypted()) {
|
||||
|
||||
|
|
@ -42,9 +108,94 @@ angular.module('copayApp.controllers').controller('backupController',
|
|||
}
|
||||
|
||||
self.credentialsEncrypted = false;
|
||||
setWords(fc.getMnemonic());
|
||||
setWords(getMnemonic());
|
||||
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
}, 1);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.enableButton = function(word) {
|
||||
document.getElementById(word).disabled = false;
|
||||
lodash.remove(customWords, function(v) {
|
||||
return v == word;
|
||||
});
|
||||
}
|
||||
|
||||
self.disableButton = function(word) {
|
||||
document.getElementById(word).disabled = true;
|
||||
customWords.push(word);
|
||||
self.addButton(word);
|
||||
}
|
||||
|
||||
self.addButton = function(word) {
|
||||
var btnhtml = '<button class="button radius tiny"' +
|
||||
'ng-style="{\'background-color\':index.backgroundColor}"' +
|
||||
'data-ng-click="wordsC.removeButton($event)" id="_' + word + '" > ' + word + ' </button>';
|
||||
var temp = $compile(btnhtml)($scope);
|
||||
angular.element(document.getElementById('addWord')).append(temp);
|
||||
self.shouldContinue();
|
||||
}
|
||||
|
||||
self.removeButton = function(event) {
|
||||
var id = (event.target.id);
|
||||
var element = document.getElementById(id);
|
||||
element.remove();
|
||||
self.enableButton(id.substring(1));
|
||||
self.shouldContinue();
|
||||
}
|
||||
|
||||
self.shouldContinue = function() {
|
||||
if (customWords.length == 12)
|
||||
self.selectComplete = true;
|
||||
else
|
||||
self.selectComplete = false;
|
||||
}
|
||||
|
||||
self.confirm = function() {
|
||||
self.backupNoOk = false;
|
||||
|
||||
var walletClient = bwcService.getClient();
|
||||
|
||||
try {
|
||||
var formatedCustomWords = '';
|
||||
|
||||
lodash.each(customWords, function(d) {
|
||||
return formatedCustomWords += ' ' + d;
|
||||
});
|
||||
|
||||
var passphrase = $scope.passphrase || '';
|
||||
|
||||
walletClient.seedFromMnemonic(formatedCustomWords.trim(), {
|
||||
network: fc.credentials.network,
|
||||
passphrase: passphrase,
|
||||
account: fc.credentials.account
|
||||
})
|
||||
|
||||
if (walletClient.credentials.xPrivKey != self.xPrivKey)
|
||||
throw 'Private key mismatch';
|
||||
|
||||
} catch (err) {
|
||||
$log.debug('Failed to verify backup: ', err);
|
||||
self.backupNoOk = true;
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
}, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('OK');
|
||||
|
||||
var words = lodash.map(mnemonic.split(' '), function(d) {
|
||||
return d;
|
||||
});
|
||||
|
||||
if (lodash.isEqual(words, customWords)) {
|
||||
$rootScope.$emit('Local/BackupDone');
|
||||
go.walletHome();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('backupConfirmController',
|
||||
function($rootScope, $scope, $timeout, $log, $compile, lodash, profileService, go, gettext, confirmDialog, notification, bwsError) {
|
||||
|
||||
var self = this;
|
||||
var fc = profileService.focusedClient;
|
||||
|
||||
setWords(fc.getMnemonic());
|
||||
|
||||
function setWords(words) {
|
||||
if (words) {
|
||||
self.mnemonicWords = words.split(/[\u3000\s]+/);
|
||||
self.mnemonicHasPassphrase = fc.mnemonicHasPassphrase();
|
||||
self.useIdeograms = words.indexOf("\u3000") >= 0;
|
||||
}
|
||||
};
|
||||
|
||||
self.confirm = function() {
|
||||
$rootScope.$emit('Local/BackupDone');
|
||||
}
|
||||
});
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('backupPassphraseController',
|
||||
function($rootScope, $scope, $timeout, $log, $compile, bwcService, lodash, profileService, go, gettext, confirmDialog, notification, bwsError) {
|
||||
|
||||
var self = this;
|
||||
var fc = profileService.focusedClient;
|
||||
self.passphraseSuccess = false;
|
||||
self.checkingPassphrase = false;
|
||||
self.error = "";
|
||||
|
||||
setWords(fc.getMnemonic());
|
||||
var words = fc.getMnemonic();
|
||||
|
||||
self.changePassphrase = function() {
|
||||
self.passphraseSuccess = false;
|
||||
$timeout(function() {
|
||||
$rootScope.$apply();
|
||||
}, 1);
|
||||
}
|
||||
|
||||
function setWords(words) {
|
||||
if (words) {
|
||||
self.mnemonicWords = words.split(/[\u3000\s]+/);
|
||||
self.mnemonicHasPassphrase = fc.mnemonicHasPassphrase();
|
||||
self.useIdeograms = words.indexOf("\u3000") >= 0;
|
||||
}
|
||||
};
|
||||
|
||||
self.confirm = function() {
|
||||
self.checkingPassphrase = true;
|
||||
self.error = "";
|
||||
|
||||
var walletClient = bwcService.getClient();
|
||||
|
||||
walletClient.importFromMnemonic(words, {
|
||||
network: 'livenet',
|
||||
passphrase: $scope.passphrase,
|
||||
account: 0,
|
||||
}, function(err) {
|
||||
self.checkingPassphrase = false;
|
||||
if (err) {
|
||||
self.error = err.message;
|
||||
$timeout(function() {
|
||||
$rootScope.$apply();
|
||||
}, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
self.passphraseSuccess = true;
|
||||
$timeout(function() {
|
||||
$rootScope.$apply();
|
||||
}, 1);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('backupWordsController',
|
||||
function($rootScope, $scope, $timeout, $log, $compile, lodash, profileService, go, gettext, confirmDialog, notification, bwsError) {
|
||||
|
||||
var self = this;
|
||||
var fc = profileService.focusedClient;
|
||||
var customSortWords = [];
|
||||
self.sorted = false;
|
||||
|
||||
setWords(fc.getMnemonic());
|
||||
|
||||
function setWords(words) {
|
||||
if (words) {
|
||||
self.mnemonicWords = words.split(/[\u3000\s]+/);
|
||||
self.mnemonicHasPassphrase = fc.mnemonicHasPassphrase();
|
||||
self.useIdeograms = words.indexOf("\u3000") >= 0;
|
||||
}
|
||||
};
|
||||
|
||||
self.enableButton = function(word) {
|
||||
document.getElementById(word).disabled = false;
|
||||
lodash.remove(customSortWords, function(v) {
|
||||
return v == word;
|
||||
});
|
||||
}
|
||||
|
||||
self.disableButton = function(word) {
|
||||
document.getElementById(word).disabled = true;
|
||||
customSortWords.push(word);
|
||||
self.addButton(word);
|
||||
}
|
||||
|
||||
self.addButton = function(word) {
|
||||
var btnhtml = '<button class="button radius tiny"' +
|
||||
'ng-style="{\'background-color\':index.backgroundColor}"' +
|
||||
'data-ng-click="backupWordsC.removeButton($event)" id="_' + word + '" > ' + word + ' </button>';
|
||||
var temp = $compile(btnhtml)($scope);
|
||||
angular.element(document.getElementById('addWord')).append(temp);
|
||||
self.shouldContinue(customSortWords);
|
||||
}
|
||||
|
||||
self.removeButton = function(event) {
|
||||
var id = (event.target.id);
|
||||
var element = document.getElementById(id);
|
||||
element.remove();
|
||||
self.enableButton(id.substring(1));
|
||||
self.shouldContinue(customSortWords);
|
||||
}
|
||||
|
||||
self.shouldContinue = function(customSortWords) {
|
||||
if (lodash.isEqual(self.mnemonicWords, customSortWords))
|
||||
self.sorted = true;
|
||||
else
|
||||
self.sorted = false;
|
||||
}
|
||||
});
|
||||
|
|
@ -445,17 +445,6 @@ angular
|
|||
},
|
||||
}
|
||||
})
|
||||
.state('backupConfirm', {
|
||||
url: '/backupConfirm',
|
||||
templateUrl: 'views/backupConfirm.html',
|
||||
walletShouldBeComplete: true,
|
||||
needProfile: true,
|
||||
views: {
|
||||
'main': {
|
||||
templateUrl: 'views/backupConfirm.html'
|
||||
},
|
||||
}
|
||||
})
|
||||
.state('backupPassphrase', {
|
||||
url: '/backupPassphrase',
|
||||
templateUrl: 'views/backupPassphrase.html',
|
||||
|
|
@ -467,6 +456,17 @@ angular
|
|||
},
|
||||
}
|
||||
})
|
||||
.state('backupConfirm', {
|
||||
url: '/backupConfirm',
|
||||
templateUrl: 'views/backupConfirm.html',
|
||||
walletShouldBeComplete: true,
|
||||
needProfile: true,
|
||||
views: {
|
||||
'main': {
|
||||
templateUrl: 'views/backupConfirm.html'
|
||||
},
|
||||
}
|
||||
})
|
||||
.state('preferencesGlobal', {
|
||||
url: '/preferencesGlobal',
|
||||
needProfile: true,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue