2015-03-06 12:00:10 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
angular.module('copayApp.controllers').controller('joinController',
|
2015-10-16 13:00:41 -03:00
|
|
|
function($scope, $rootScope, $timeout, go, notification, profileService, configService, isCordova, $modal, gettext, lodash, ledger, trezor) {
|
2015-03-06 12:00:10 -03:00
|
|
|
|
|
|
|
|
var self = this;
|
2015-10-16 13:00:41 -03:00
|
|
|
var defaults = configService.getDefaults();
|
|
|
|
|
var defaults = configService.getDefaults();
|
|
|
|
|
$scope.bwsurl = defaults.bws.url;
|
2015-07-17 15:53:50 +02:00
|
|
|
|
2015-09-28 01:20:16 -03:00
|
|
|
this.onQrCodeScanned = function(data) {
|
|
|
|
|
$scope.secret = data;
|
|
|
|
|
$scope.joinForm.secret.$setViewValue(data);
|
|
|
|
|
$scope.joinForm.secret.$render();
|
2015-03-06 12:00:10 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.join = function(form) {
|
|
|
|
|
if (form && form.$invalid) {
|
2015-04-29 19:19:10 -03:00
|
|
|
self.error = gettext('Please enter the required fields');
|
2015-03-06 12:00:10 -03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
self.loading = true;
|
|
|
|
|
|
2015-07-17 15:53:50 +02:00
|
|
|
var opts = {
|
|
|
|
|
secret: form.secret.$modelValue,
|
2015-09-04 12:25:54 -03:00
|
|
|
myName: form.myName.$modelValue,
|
2015-07-17 15:53:50 +02:00
|
|
|
}
|
2015-09-04 12:25:54 -03:00
|
|
|
|
2015-09-03 01:49:48 -03:00
|
|
|
var setSeed = form.setSeed.$modelValue;
|
2015-10-16 13:00:41 -03:00
|
|
|
if (setSeed) {
|
2015-09-05 00:11:14 -03:00
|
|
|
var words = form.privateKey.$modelValue;
|
|
|
|
|
if (words.indexOf(' ') == -1 && words.indexOf('prv') == 1 && words.length > 108) {
|
|
|
|
|
opts.extendedPrivateKey = words;
|
|
|
|
|
} else {
|
|
|
|
|
opts.mnemonic = words;
|
|
|
|
|
}
|
2015-09-03 01:49:48 -03:00
|
|
|
opts.passphrase = form.passphrase.$modelValue;
|
|
|
|
|
} else {
|
|
|
|
|
opts.passphrase = form.createPassphrase.$modelValue;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-05 00:11:14 -03:00
|
|
|
if (setSeed && !opts.mnemonic && !opts.extendedPrivateKey) {
|
2015-09-03 01:49:48 -03:00
|
|
|
this.error = gettext('Please enter the wallet seed');
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-10-16 13:00:41 -03:00
|
|
|
|
2015-09-29 12:45:06 -03:00
|
|
|
if (form.hwLedger.$modelValue || form.hwTrezor.$modelValue) {
|
2015-10-16 13:00:41 -03:00
|
|
|
self.hwWallet = form.hwLedger.$modelValue ? 'Ledger' : 'TREZOR';
|
|
|
|
|
var src = form.hwLedger.$modelValue ? ledger : trezor;
|
2015-09-29 12:45:06 -03:00
|
|
|
|
|
|
|
|
var account = 0;
|
|
|
|
|
src.getInfoForNewWallet(account, function(err, lopts) {
|
|
|
|
|
self.hwWallet = false;
|
2015-09-04 12:25:54 -03:00
|
|
|
if (err) {
|
|
|
|
|
self.error = err;
|
2015-07-17 15:53:50 +02:00
|
|
|
$scope.$apply();
|
2015-09-04 12:25:54 -03:00
|
|
|
return;
|
2015-07-17 15:53:50 +02:00
|
|
|
}
|
2015-09-04 12:25:54 -03:00
|
|
|
opts = lodash.assign(lopts, opts);
|
|
|
|
|
self._join(opts);
|
2015-07-17 15:53:50 +02:00
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
self._join(opts);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this._join = function(opts) {
|
2015-03-06 12:00:10 -03:00
|
|
|
$timeout(function() {
|
2015-07-17 15:53:50 +02:00
|
|
|
profileService.joinWallet(opts, function(err) {
|
2015-03-06 12:00:10 -03:00
|
|
|
if (err) {
|
2015-04-27 02:38:48 -03:00
|
|
|
self.loading = false;
|
2015-08-12 11:08:33 -03:00
|
|
|
self.error = err;
|
2015-04-24 03:37:18 -03:00
|
|
|
$rootScope.$apply();
|
2015-04-27 02:38:48 -03:00
|
|
|
return
|
2015-03-06 12:00:10 -03:00
|
|
|
}
|
2015-04-27 03:03:08 -03:00
|
|
|
$timeout(function() {
|
2015-09-02 17:11:59 -03:00
|
|
|
var fc = profileService.focusedClient;
|
2015-10-16 13:00:41 -03:00
|
|
|
|
|
|
|
|
var opts_ = {
|
|
|
|
|
bws: {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
opts_.bws[fc.credentials.walletId] = $scope.bwsurl;
|
|
|
|
|
configService.set(opts_, function(err) {
|
|
|
|
|
if (err) console.log(err);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (fc.isComplete() && (opts.mnemonic || opts.externalSource || opts.extendedPrivateKey)) {
|
2015-09-02 17:11:59 -03:00
|
|
|
$rootScope.$emit('Local/WalletImported', fc.credentials.walletId);
|
|
|
|
|
} else {
|
|
|
|
|
go.walletHome();
|
|
|
|
|
}
|
2015-04-27 03:03:08 -03:00
|
|
|
}, 2000);
|
2015-03-06 12:00:10 -03:00
|
|
|
});
|
|
|
|
|
}, 100);
|
2015-07-17 15:53:50 +02:00
|
|
|
};
|
2015-03-06 12:00:10 -03:00
|
|
|
});
|