commit
6ab8330133
47 changed files with 699 additions and 332 deletions
|
|
@ -1,17 +1,32 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('backupController',
|
||||
function($rootScope, $scope, $timeout, $log, $state, $stateParams, lodash, fingerprintService, platformInfo, configService, profileService, gettext, bwcService, walletService, ongoingProcess) {
|
||||
function($rootScope, $scope, $timeout, $log, $state, $stateParams, $ionicPopup, uxLanguage, lodash, fingerprintService, platformInfo, configService, profileService, gettext, bwcService, walletService, ongoingProcess) {
|
||||
|
||||
var wallet = profileService.getWallet($stateParams.walletId);
|
||||
$scope.customWords = [];
|
||||
$scope.walletName = wallet.credentials.walletName;
|
||||
$scope.n = wallet.n;
|
||||
|
||||
$scope.credentialsEncrypted = wallet.isPrivKeyEncrypted;
|
||||
|
||||
var isDeletedSeed = function() {
|
||||
if (lodash.isEmpty(wallet.credentials.mnemonic) && lodash.isEmpty(wallet.credentials.mnemonicEncrypted))
|
||||
return true;
|
||||
return false;
|
||||
};
|
||||
|
||||
var handleEncryptedWallet = function(client, cb) {
|
||||
if (!walletService.isEncrypted(client)) {
|
||||
return cb();
|
||||
}
|
||||
|
||||
$rootScope.$emit('Local/NeedsPassword', false, function(err, password) {
|
||||
if (err) return cb(err);
|
||||
return cb(walletService.unlock(client, password));
|
||||
});
|
||||
};
|
||||
|
||||
$scope.init = function() {
|
||||
$scope.step = 1;
|
||||
$scope.deleted = isDeletedSeed();
|
||||
if ($scope.deleted) return;
|
||||
|
||||
|
|
@ -33,7 +48,7 @@ angular.module('copayApp.controllers').controller('backupController',
|
|||
});
|
||||
};
|
||||
|
||||
function shuffledWords(words) {
|
||||
var shuffledWords = function(words) {
|
||||
var sort = lodash.sortBy(words);
|
||||
|
||||
return lodash.map(sort, function(w) {
|
||||
|
|
@ -62,70 +77,46 @@ angular.module('copayApp.controllers').controller('backupController',
|
|||
}, 10);
|
||||
};
|
||||
|
||||
function isDeletedSeed() {
|
||||
if (lodash.isEmpty(wallet.credentials.mnemonic) && lodash.isEmpty(wallet.credentials.mnemonicEncrypted))
|
||||
return true;
|
||||
return false;
|
||||
};
|
||||
|
||||
$scope.$on('$destroy', function() {
|
||||
walletService.lock(wallet);
|
||||
});
|
||||
|
||||
$scope.goToStep = function(n) {
|
||||
if (n == 1)
|
||||
$scope.initFlow();
|
||||
if (n == 2)
|
||||
$scope.step = 2;
|
||||
if (n == 3) {
|
||||
if (!$scope.mnemonicHasPassphrase)
|
||||
finalStep();
|
||||
else
|
||||
$scope.step = 3;
|
||||
$scope.goBack = function() {
|
||||
if ($scope.step == 1) {
|
||||
if ($stateParams.fromOnboarding) $state.go('onboarding.backupRequest');
|
||||
else $state.go('wallet.preferences');
|
||||
}
|
||||
if (n == 4)
|
||||
finalStep();
|
||||
else {
|
||||
$scope.goToStep($scope.step - 1);
|
||||
}
|
||||
};
|
||||
|
||||
function finalStep() {
|
||||
ongoingProcess.set('validatingWords', true);
|
||||
confirm(function(err) {
|
||||
ongoingProcess.set('validatingWords', false);
|
||||
if (err) {
|
||||
backupError(err);
|
||||
}
|
||||
$timeout(function() {
|
||||
$scope.step = 4;
|
||||
return;
|
||||
}, 1);
|
||||
});
|
||||
var backupError = function(err) {
|
||||
ongoingProcess.set('validatingWords', false);
|
||||
$log.debug('Failed to verify backup: ', err);
|
||||
$scope.backupError = true;
|
||||
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
}, 1);
|
||||
};
|
||||
|
||||
var openPopup = function() {
|
||||
var confirmBackupPopup = $ionicPopup.show({
|
||||
templateUrl: "views/includes/confirmBackupPopup.html",
|
||||
scope: $scope,
|
||||
});
|
||||
|
||||
$scope.closePopup = function(val) {
|
||||
if (val) {
|
||||
confirmBackupPopup.close();
|
||||
if ($stateParams.fromOnboarding) $state.go('onboarding.disclaimer');
|
||||
else $state.go('tabs.home')
|
||||
}
|
||||
else {
|
||||
confirmBackupPopup.close();
|
||||
$scope.goToStep(1);
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
$scope.addButton = function(index, item) {
|
||||
var newWord = {
|
||||
word: item.word,
|
||||
prevIndex: index
|
||||
};
|
||||
$scope.customWords.push(newWord);
|
||||
$scope.shuffledMnemonicWords[index].selected = true;
|
||||
$scope.shouldContinue();
|
||||
};
|
||||
|
||||
$scope.removeButton = function(index, item) {
|
||||
if ($scope.loading) return;
|
||||
$scope.customWords.splice(index, 1);
|
||||
$scope.shuffledMnemonicWords[item.prevIndex].selected = false;
|
||||
$scope.shouldContinue();
|
||||
};
|
||||
|
||||
$scope.shouldContinue = function() {
|
||||
if ($scope.customWords.length == $scope.shuffledMnemonicWords.length)
|
||||
$scope.selectComplete = true;
|
||||
else
|
||||
$scope.selectComplete = false;
|
||||
};
|
||||
|
||||
function confirm(cb) {
|
||||
var confirm = function(cb) {
|
||||
$scope.backupError = false;
|
||||
|
||||
var customWordList = lodash.pluck($scope.customWords, 'word');
|
||||
|
|
@ -161,25 +152,62 @@ angular.module('copayApp.controllers').controller('backupController',
|
|||
}, 1);
|
||||
};
|
||||
|
||||
function handleEncryptedWallet(client, cb) {
|
||||
if (!walletService.isEncrypted(client)) {
|
||||
$scope.credentialsEncrypted = false;
|
||||
return cb();
|
||||
}
|
||||
|
||||
$rootScope.$emit('Local/NeedsPassword', false, function(err, password) {
|
||||
if (err) return cb(err);
|
||||
return cb(walletService.unlock(client, password));
|
||||
var finalStep = function() {
|
||||
ongoingProcess.set('validatingWords', true);
|
||||
confirm(function(err) {
|
||||
ongoingProcess.set('validatingWords', false);
|
||||
if (err) {
|
||||
backupError(err);
|
||||
}
|
||||
$timeout(function() {
|
||||
openPopup();
|
||||
return;
|
||||
}, 1);
|
||||
});
|
||||
};
|
||||
|
||||
function backupError(err) {
|
||||
ongoingProcess.set('validatingWords', false);
|
||||
$log.debug('Failed to verify backup: ', err);
|
||||
$scope.backupError = true;
|
||||
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
}, 1);
|
||||
$scope.goToStep = function(n) {
|
||||
if (n == 1)
|
||||
$scope.initFlow();
|
||||
if (n == 2)
|
||||
$scope.step = 2;
|
||||
if (n == 3) {
|
||||
if (!$scope.mnemonicHasPassphrase)
|
||||
finalStep();
|
||||
else
|
||||
$scope.step = 3;
|
||||
}
|
||||
if (n == 4)
|
||||
finalStep();
|
||||
};
|
||||
|
||||
$scope.addButton = function(index, item) {
|
||||
var newWord = {
|
||||
word: item.word,
|
||||
prevIndex: index
|
||||
};
|
||||
$scope.customWords.push(newWord);
|
||||
$scope.shuffledMnemonicWords[index].selected = true;
|
||||
$scope.shouldContinue();
|
||||
};
|
||||
|
||||
$scope.removeButton = function(index, item) {
|
||||
if ($scope.loading) return;
|
||||
$scope.customWords.splice(index, 1);
|
||||
$scope.shuffledMnemonicWords[item.prevIndex].selected = false;
|
||||
$scope.shouldContinue();
|
||||
};
|
||||
|
||||
$scope.shouldContinue = function() {
|
||||
if ($scope.customWords.length == $scope.shuffledMnemonicWords.length)
|
||||
$scope.selectComplete = true;
|
||||
else
|
||||
$scope.selectComplete = false;
|
||||
};
|
||||
|
||||
|
||||
$scope.$on('$destroy', function() {
|
||||
walletService.lock(wallet);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('importController',
|
||||
function($scope, $rootScope, $timeout, $log, $state, profileService, configService, sjcl, gettext, ledger, trezor, derivationPathHelper, platformInfo, bwcService, ongoingProcess, walletService) {
|
||||
function($scope, $rootScope, $timeout, $log, $state, $stateParams, profileService, configService, sjcl, gettext, ledger, trezor, derivationPathHelper, platformInfo, bwcService, ongoingProcess, walletService) {
|
||||
|
||||
var isChromeApp = platformInfo.isChromeApp;
|
||||
var isDevel = platformInfo.isDevel;
|
||||
|
|
|
|||
21
src/js/controllers/onboarding/backupRequest.js
Normal file
21
src/js/controllers/onboarding/backupRequest.js
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('backupRequestController', function($rootScope, $scope, $state, $ionicPopup, $stateParams, profileService, walletService) {
|
||||
|
||||
$scope.openPopup = function() {
|
||||
var backupLaterPopup = $ionicPopup.show({
|
||||
templateUrl: "views/includes/backupLaterPopup.html",
|
||||
scope: $scope,
|
||||
});
|
||||
|
||||
$scope.goBack = function() {
|
||||
backupLaterPopup.close();
|
||||
};
|
||||
|
||||
$scope.continue = function() {
|
||||
backupLaterPopup.close();
|
||||
$state.go('onboarding.disclaimer');
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
21
src/js/controllers/onboarding/backupWarning.js
Normal file
21
src/js/controllers/onboarding/backupWarning.js
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('backupWarningController', function($rootScope, $scope, $state, $ionicPopup, $stateParams, profileService, walletService) {
|
||||
|
||||
$scope.openPopup = function() {
|
||||
var backupWarningPopup = $ionicPopup.show({
|
||||
templateUrl: "views/includes/backupWarningPopup.html",
|
||||
scope: $scope,
|
||||
});
|
||||
|
||||
$scope.close = function() {
|
||||
backupWarningPopup.close();
|
||||
var wallet = profileService.getWallets()[0];
|
||||
$state.go('wallet.backup', {
|
||||
walletId: wallet.credentials.walletId,
|
||||
fromOnboarding: true
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
17
src/js/controllers/onboarding/collectEmail.js
Normal file
17
src/js/controllers/onboarding/collectEmail.js
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('collectEmailController', function($rootScope, $scope, $state, $stateParams, $timeout, $ionicModal, profileService, walletService) {
|
||||
|
||||
$scope.save = function(form) {
|
||||
var wallet = profileService.getWallet($stateParams.walletId);
|
||||
var email = $scope.email || '';
|
||||
|
||||
walletService.updateRemotePreferences(wallet, {
|
||||
email: email,
|
||||
}, function(err) {
|
||||
if (err) $log.warn(err);
|
||||
$state.go('onboarding.notifications');
|
||||
});
|
||||
};
|
||||
|
||||
});
|
||||
24
src/js/controllers/onboarding/disclaimer.js
Normal file
24
src/js/controllers/onboarding/disclaimer.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('disclaimerController', function($scope, $state, $log, $ionicModal, profileService) {
|
||||
|
||||
$scope.confirm = function() {
|
||||
profileService.setDisclaimerAccepted(function(err) {
|
||||
if (err) $log.error(err);
|
||||
else {
|
||||
$state.go('tabs.home');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
this.openModal = function() {
|
||||
|
||||
$ionicModal.fromTemplateUrl('views/modals/addressbook.html', {
|
||||
scope: $scope
|
||||
}).then(function(modal) {
|
||||
$scope.addressbookModal = modal;
|
||||
$scope.addressbookModal.show();
|
||||
});
|
||||
};
|
||||
|
||||
});
|
||||
12
src/js/controllers/onboarding/notifications.js
Normal file
12
src/js/controllers/onboarding/notifications.js
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('notificationsController', function($scope, $state, platformInfo) {
|
||||
|
||||
if (!platformInfo.isCordova) $state.go('onboarding.backupRequest');
|
||||
|
||||
$scope.allowNotif = function() {
|
||||
// T O D O
|
||||
$state.go('onboarding.backupRequest');
|
||||
}
|
||||
|
||||
});
|
||||
15
src/js/controllers/onboarding/terms.js
Normal file
15
src/js/controllers/onboarding/terms.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('termsController', function($scope, $log, $state, uxLanguage, profileService) {
|
||||
$scope.lang = uxLanguage.currentLanguage;
|
||||
|
||||
$scope.confirm = function() {
|
||||
profileService.setDisclaimerAccepted(function(err) {
|
||||
if (err) $log.error(err);
|
||||
else {
|
||||
$state.go('tabs.home');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
});
|
||||
71
src/js/controllers/onboarding/tour.js
Normal file
71
src/js/controllers/onboarding/tour.js
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
'use strict';
|
||||
angular.module('copayApp.controllers').controller('tourController',
|
||||
function($scope, $stateParams, $state, $log, $timeout, ongoingProcess, storageService, profileService) {
|
||||
|
||||
$scope.init = function() {
|
||||
|
||||
$scope.data = {
|
||||
index: 0
|
||||
};
|
||||
|
||||
$scope.options = {
|
||||
loop: false,
|
||||
effect: 'flip',
|
||||
speed: 500,
|
||||
spaceBetween: 100
|
||||
}
|
||||
};
|
||||
|
||||
$scope.createProfile = function(opts) {
|
||||
var tries = 0;
|
||||
opts = opts || {};
|
||||
$log.debug('Creating profile');
|
||||
ongoingProcess.set('creatingWallet', true);
|
||||
profileService.create(opts, function(err) {
|
||||
if (err) {
|
||||
$log.warn(err);
|
||||
$scope.error = err;
|
||||
$scope.$apply();
|
||||
|
||||
return $timeout(function() {
|
||||
$log.warn('Retrying to create profile......');
|
||||
if (tries == 3) {
|
||||
tries == 0;
|
||||
return $scope.createProfile({
|
||||
noWallet: true
|
||||
});
|
||||
} else {
|
||||
tries += 1;
|
||||
return $scope.createProfile();
|
||||
}
|
||||
}, 3000);
|
||||
};
|
||||
$scope.error = "";
|
||||
ongoingProcess.set('creatingWallet', false);
|
||||
var wallet = profileService.getWallets()[0];
|
||||
$state.go('onboarding.collectEmail', {
|
||||
walletId: wallet.credentials.walletId
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
$scope.goBack = function() {
|
||||
if ($scope.data.index != 0) $scope.slider.slidePrev();
|
||||
else $state.go('onboarding.welcome');
|
||||
}
|
||||
|
||||
$scope.slideNext = function() {
|
||||
if ($scope.data.index != 2) $scope.slider.slideNext();
|
||||
else $state.go('onboarding.welcome');
|
||||
}
|
||||
|
||||
$scope.$on("$ionicSlides.sliderInitialized", function(event, data) {
|
||||
$scope.slider = data.slider;
|
||||
});
|
||||
|
||||
$scope.$on("$ionicSlides.slideChangeStart", function(event, data) {
|
||||
$scope.data.index = data.slider.activeIndex;
|
||||
});
|
||||
|
||||
$scope.$on("$ionicSlides.slideChangeEnd", function(event, data) {});
|
||||
});
|
||||
|
|
@ -127,7 +127,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
url: $stateParams.url
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
.state('uripayment', {
|
||||
url: '/uri-payment/:url',
|
||||
|
|
@ -146,6 +146,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
templateUrl: 'views/activity.html'
|
||||
})
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Wallet
|
||||
|
|
@ -153,7 +154,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
*/
|
||||
|
||||
.state('wallet', {
|
||||
url: '/wallet/{walletId}',
|
||||
url: '/wallet/{walletId}/{fromOnboarding}',
|
||||
abstract: true,
|
||||
template: '<ion-nav-view name="wallet"></ion-nav-view>'
|
||||
})
|
||||
|
|
@ -528,11 +529,11 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
}
|
||||
}
|
||||
})
|
||||
.state('settings.termOfUse', {
|
||||
url: '/termOfUse',
|
||||
.state('settings.termsOfUse', {
|
||||
url: '/termsOfUse',
|
||||
views: {
|
||||
'settings': {
|
||||
templateUrl: 'views/termOfUse.html',
|
||||
templateUrl: 'views/termsOfUse.html',
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
@ -545,6 +546,82 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
}
|
||||
})
|
||||
|
||||
/*
|
||||
*
|
||||
* Onboarding
|
||||
*
|
||||
*/
|
||||
|
||||
.state('onboarding', {
|
||||
url: '/onboarding',
|
||||
abstract: true,
|
||||
template: '<ion-nav-view name="onboarding"></ion-nav-view>'
|
||||
})
|
||||
.state('onboarding.welcome', {
|
||||
url: '/welcome',
|
||||
views: {
|
||||
'onboarding': {
|
||||
templateUrl: 'views/onboarding/welcome.html'
|
||||
}
|
||||
}
|
||||
})
|
||||
.state('onboarding.tour', {
|
||||
url: '/tour',
|
||||
views: {
|
||||
'onboarding': {
|
||||
templateUrl: 'views/onboarding/tour.html'
|
||||
}
|
||||
}
|
||||
})
|
||||
.state('onboarding.collectEmail', {
|
||||
url: '/collectEmail',
|
||||
views: {
|
||||
'onboarding': {
|
||||
templateUrl: 'views/onboarding/collectEmail.html'
|
||||
}
|
||||
}
|
||||
})
|
||||
.state('onboarding.notifications', {
|
||||
url: '/notifications',
|
||||
views: {
|
||||
'onboarding': {
|
||||
templateUrl: 'views/onboarding/notifications.html'
|
||||
}
|
||||
}
|
||||
})
|
||||
.state('onboarding.backupRequest', {
|
||||
url: '/backupRequest',
|
||||
views: {
|
||||
'onboarding': {
|
||||
templateUrl: 'views/onboarding/backupRequest.html'
|
||||
}
|
||||
}
|
||||
})
|
||||
.state('onboarding.backupWarning', {
|
||||
url: '/backupWarning',
|
||||
views: {
|
||||
'onboarding': {
|
||||
templateUrl: 'views/onboarding/backupWarning.html'
|
||||
}
|
||||
}
|
||||
})
|
||||
.state('onboarding.disclaimer', {
|
||||
url: '/disclaimer',
|
||||
views: {
|
||||
'onboarding': {
|
||||
templateUrl: 'views/onboarding/disclaimer.html'
|
||||
}
|
||||
}
|
||||
})
|
||||
.state('onboarding.terms', {
|
||||
url: '/terms',
|
||||
views: {
|
||||
'onboarding': {
|
||||
templateUrl: 'views/onboarding/terms.html'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
/*
|
||||
*
|
||||
* Glidera
|
||||
|
|
@ -765,10 +842,10 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
if (err) {
|
||||
if (err.message && err.message.match('NOPROFILE')) {
|
||||
$log.debug('No profile... redirecting');
|
||||
$state.transitionTo('disclaimer');
|
||||
$state.transitionTo('onboarding.welcome');
|
||||
} else if (err.message && err.message.match('NONAGREEDDISCLAIMER')) {
|
||||
$log.debug('Display disclaimer... redirecting');
|
||||
$state.transitionTo('disclaimer');
|
||||
$state.transitionTo('onboarding.disclaimer');
|
||||
} else {
|
||||
throw new Error(err); // TODO
|
||||
}
|
||||
|
|
@ -778,7 +855,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
$state.transitionTo('tabs.home');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
if (platformInfo.isNW) {
|
||||
var gui = require('nw.gui');
|
||||
|
|
|
|||
|
|
@ -953,4 +953,10 @@ input[type=number] {
|
|||
height: 24px;
|
||||
}
|
||||
|
||||
|
||||
.disclaimer {
|
||||
.item, .item-content{
|
||||
overflow: auto;
|
||||
text-overflow: initial;
|
||||
white-space: initial;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue