fix export/import
This commit is contained in:
parent
6c1f9f5387
commit
5435200968
6 changed files with 97 additions and 118 deletions
|
|
@ -1,40 +1,39 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('exportController',
|
||||
function($rootScope, $scope, $timeout, $log, lodash, backupService, walletService, fingerprintService, configService, storageService, profileService, platformInfo, notification, go, gettext, gettextCatalog) {
|
||||
function($rootScope, $scope, $timeout, $log, lodash, backupService, walletService, storageService, profileService, platformInfo, notification, go, gettext, gettextCatalog, $state, $stateParams) {
|
||||
var prevState;
|
||||
var isWP = platformInfo.isWP;
|
||||
var isAndroid = platformInfo.isAndroid;
|
||||
var fc = profileService.focusedClient;
|
||||
$scope.isEncrypted = fc.isPrivKeyEncrypted();
|
||||
|
||||
var wallet = profileService.getWallet($stateParams.walletId);
|
||||
$scope.isEncrypted = wallet.isPrivKeyEncrypted();
|
||||
$scope.isCordova = platformInfo.isCordova;
|
||||
$scope.isSafari = platformInfo.isSafari;
|
||||
$scope.error = null;
|
||||
|
||||
$scope.init = function(state) {
|
||||
$scope.init = function() {
|
||||
$scope.supported = true;
|
||||
$scope.exportQR = false;
|
||||
$scope.noSignEnabled = false;
|
||||
$scope.showAdvanced = false;
|
||||
prevState = state || 'walletHome';
|
||||
$scope.wallet = wallet;
|
||||
$scope.canSign = wallet.canSign();
|
||||
|
||||
fingerprintService.check(fc, function(err) {
|
||||
walletService.getEncodedWalletInfo(wallet, function(err, code) {
|
||||
if (err) {
|
||||
go.path(prevState);
|
||||
return;
|
||||
$log.warn(err);
|
||||
return $state.go('wallet.preferencesAdvanced')
|
||||
}
|
||||
|
||||
handleEncryptedWallet(fc, function(err) {
|
||||
if (err) {
|
||||
go.path(prevState);
|
||||
return;
|
||||
}
|
||||
if (!code)
|
||||
$scope.supported = false;
|
||||
else
|
||||
$scope.exportWalletInfo = code;
|
||||
|
||||
$scope.exportWalletInfo = encodeWalletInfo();
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
}, 1);
|
||||
});
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
}, 1);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -50,62 +49,9 @@ angular.module('copayApp.controllers').controller('exportController',
|
|||
*/
|
||||
|
||||
$scope.$on('$destroy', function() {
|
||||
walletService.lock(fc);
|
||||
walletService.lock(wallet);
|
||||
});
|
||||
|
||||
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));
|
||||
});
|
||||
};
|
||||
|
||||
function encodeWalletInfo() {
|
||||
var c = fc.credentials;
|
||||
var derivationPath = fc.credentials.getBaseAddressDerivationPath();
|
||||
var encodingType = {
|
||||
mnemonic: 1,
|
||||
xpriv: 2,
|
||||
xpub: 3
|
||||
};
|
||||
var info;
|
||||
|
||||
$scope.supported = (c.derivationStrategy == 'BIP44' && c.canSign());
|
||||
|
||||
if ($scope.supported) {
|
||||
if (c.mnemonic) {
|
||||
info = {
|
||||
type: encodingType.mnemonic,
|
||||
data: c.mnemonic,
|
||||
}
|
||||
} else {
|
||||
info = {
|
||||
type: encodingType.xpriv,
|
||||
data: c.xPrivKey
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
EXPORT WITHOUT PRIVATE KEY - PENDING
|
||||
|
||||
info = {
|
||||
type: encodingType.xpub,
|
||||
data: c.xPubKey
|
||||
}
|
||||
*/
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
var code = info.type + '|' + info.data + '|' + c.network.toLowerCase() + '|' + derivationPath + '|' + (c.mnemonicHasPassphrase);
|
||||
return code;
|
||||
};
|
||||
|
||||
$scope.downloadWalletBackup = function() {
|
||||
$scope.getAddressbook(function(err, localAddressBook) {
|
||||
if (err) {
|
||||
|
|
@ -184,11 +130,10 @@ angular.module('copayApp.controllers').controller('exportController',
|
|||
};
|
||||
|
||||
$scope.sendWalletBackup = function() {
|
||||
var fc = profileService.focusedClient;
|
||||
window.plugins.toast.showShortCenter(gettextCatalog.getString('Preparing backup...'));
|
||||
var name = (fc.credentials.walletName || fc.credentials.walletId);
|
||||
if (fc.alias) {
|
||||
name = fc.alias + ' [' + name + ']';
|
||||
var name = (wallet.credentials.walletName || wallet.credentials.walletId);
|
||||
if (wallet.alias) {
|
||||
name = wallet.alias + ' [' + name + ']';
|
||||
}
|
||||
$scope.getBackup(function(backup) {
|
||||
var ew = backup;
|
||||
|
|
|
|||
|
|
@ -1,19 +1,21 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('preferencesInformation',
|
||||
function($scope, $log, $timeout, platformInfo, gettextCatalog, lodash, profileService, configService, go) {
|
||||
function($scope, $log, $timeout, platformInfo, gettextCatalog, lodash, profileService, configService, go, $stateParams) {
|
||||
var base = 'xpub';
|
||||
var fc = profileService.focusedClient;
|
||||
var c = fc.credentials;
|
||||
var walletId = c.walletId;
|
||||
var wallet = profileService.getWallet($stateParams.walletId);
|
||||
var walletId = wallet.id;
|
||||
|
||||
var config = configService.getSync();
|
||||
var b = 1;
|
||||
var isCordova = platformInfo.isCordova;
|
||||
$scope.isCordova = platformInfo.isCordova;
|
||||
config.colorFor = config.colorFor || {};
|
||||
|
||||
$scope.init = function() {
|
||||
var c =wallet.credentials;
|
||||
var basePath = c.getBaseAddressDerivationPath();
|
||||
|
||||
$scope.wallet = wallet;
|
||||
$scope.walletName = c.walletName;
|
||||
$scope.walletId = c.walletId;
|
||||
$scope.network = c.network;
|
||||
|
|
@ -25,7 +27,7 @@ angular.module('copayApp.controllers').controller('preferencesInformation',
|
|||
$scope.pubKeys = lodash.pluck(c.publicKeyRing, 'xPubKey');
|
||||
$scope.addrs = null;
|
||||
|
||||
fc.getMainAddresses({
|
||||
wallet.getMainAddresses({
|
||||
doNotVerify: true
|
||||
}, function(err, addrs) {
|
||||
if (err) {
|
||||
|
|
@ -62,7 +64,7 @@ angular.module('copayApp.controllers').controller('preferencesInformation',
|
|||
};
|
||||
|
||||
$timeout(function() {
|
||||
fc.getMainAddresses({
|
||||
wallet.getMainAddresses({
|
||||
doNotVerify: true
|
||||
}, function(err, addrs) {
|
||||
if (err) {
|
||||
|
|
@ -113,7 +115,7 @@ angular.module('copayApp.controllers').controller('preferencesInformation',
|
|||
};
|
||||
|
||||
$scope.copyToClipboard = function(data) {
|
||||
if (isCordova) {
|
||||
if ($scope.isCordova) {
|
||||
window.cordova.plugins.clipboard.copy(data);
|
||||
window.plugins.toast.showShortCenter(gettextCatalog.getString('Copied to clipboard'));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -818,7 +818,6 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
|
|||
}]
|
||||
});
|
||||
pass.then(function(res) {
|
||||
console.log('Tapped!', res);
|
||||
return cb(res);
|
||||
});
|
||||
};
|
||||
|
|
@ -911,7 +910,47 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
|
|||
});
|
||||
});
|
||||
};
|
||||
root.getEncodedWalletInfo = function(wallet,cb){
|
||||
|
||||
var getCode = function() {
|
||||
var derivationPath = wallet.credentials.getBaseAddressDerivationPath();
|
||||
var encodingType = {
|
||||
mnemonic: 1,
|
||||
xpriv: 2,
|
||||
xpub: 3
|
||||
};
|
||||
var info;
|
||||
|
||||
// not supported yet
|
||||
if (wallet.credentials.derivationStrategy != 'BIP44' || !wallet.canSign())
|
||||
return null;
|
||||
|
||||
if (wallet.mnemonic) {
|
||||
info = {
|
||||
type: encodingType.mnemonic,
|
||||
data: wallet.mnemonic,
|
||||
}
|
||||
} else {
|
||||
info = {
|
||||
type: encodingType.xpriv,
|
||||
data: wallet.xPrivKey
|
||||
}
|
||||
}
|
||||
return info.type + '|' + info.data + '|' + wallet.credentials.network.toLowerCase() + '|' + derivationPath + '|' + (wallet.credentials.mnemonicHasPassphrase);
|
||||
};
|
||||
|
||||
fingerprintService.check(wallet, function(err) {
|
||||
if (err) return cb(err);
|
||||
|
||||
root.handleEncryptedWallet(wallet, function(err) {
|
||||
if (err) return cb(err);
|
||||
|
||||
var code = getCode();
|
||||
console.log('[walletService.js.948:code:]',code); //TODO
|
||||
return cb(null, code);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return root;
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue