fix export/import

This commit is contained in:
Matias Alejo Garcia 2016-08-18 19:23:58 -03:00
commit 5435200968
No known key found for this signature in database
GPG key ID: 02470DB551277AB3
6 changed files with 97 additions and 118 deletions

View file

@ -1,5 +1,5 @@
<ion-view ng-controller="exportController" cache-view="false" ng-init="init(index.prevState)"> <ion-view ng-controller="exportController" cache-view="false" ng-init="init()">
<ion-nav-bar class="bar-stable"> <ion-nav-bar class="bar-stable">
<ion-nav-title>Export Wallet</ion-nav-title> <ion-nav-title>Export Wallet</ion-nav-title>
<ion-nav-buttons side="primary"> <ion-nav-buttons side="primary">
@ -9,8 +9,10 @@
  </ion-nav-buttons>   </ion-nav-buttons>
</ion-nav-bar> </ion-nav-bar>
<ion-content class="has-header"> <ion-content class="has-header">
<div ng-show="!index.canSign"><h4></h4></div> <h4>{{wallet.name}}</h4>
<div ng-show="index.canSign" class="create-tab small-only-text-center">
<div ng-show="!canSign"><h4></h4></div>
<div ng-show="canSign" class="create-tab small-only-text-center">
<div class="row"> <div class="row">
<div class="tab-container small-6 columns" <div class="tab-container small-6 columns"
ng-class="{'selected':!exportQR}" ng-class="{'selected':!exportQR}"
@ -60,7 +62,7 @@
<div class="text-center size-12 m10" translate>Exporting via QR not supported for this wallet</div> <div class="text-center size-12 m10" translate>Exporting via QR not supported for this wallet</div>
</div> </div>
<div class="row" ng-show="!exportQR && index.canSign"> <div class="row" ng-show="!exportQR && canSign">
<div class="columns m15t"> <div class="columns m15t">
<a class="button outline light-gray expand tiny p10i" ng-click="showAdvanced = !showAdvanced"> <a class="button outline light-gray expand tiny p10i" ng-click="showAdvanced = !showAdvanced">
<i class="fi-widget m3r"></i> <i class="fi-widget m3r"></i>
@ -78,7 +80,7 @@
</ion-toggle> </ion-toggle>
</div> </div>
<div class="box-notification p15l" ng-show="!index.canSign"> <div class="box-notification p15l" ng-show="!canSign">
<span class="text-warning size-14"> <span class="text-warning size-14">
<i class="fi-alert"></i> <i class="fi-alert"></i>
<span translate> <span translate>
@ -100,12 +102,12 @@
<div class="columns"> <div class="columns">
<button class="black round expand m20t" ng-click="downloadWalletBackup()" <button class="black round expand m20t" ng-click="downloadWalletBackup()"
ng-disabled="(!password || password != repeatpassword)" ng-disabled="(!password || password != repeatpassword)"
ng-style="{'background-color':index.backgroundColor}" ng-style="{'background-color':wallet.color}"
ng-show="!isSafari && !isCordova"><i class="fi-download"></i> ng-show="!isSafari && !isCordova"><i class="fi-download"></i>
<span translate>Download</span></button> <span translate>Download</span></button>
<button class="black round expand m20t" ng-click="viewWalletBackup()" <button class="black round expand m20t" ng-click="viewWalletBackup()"
ng-disabled="(!password || password != repeatpassword)" ng-disabled="(!password || password != repeatpassword)"
ng-style="{'background-color':index.backgroundColor}" ng-style="{'background-color':wallet.color}"
ng-show="isSafari && !isCordova"><i class="fi-eye"></i> ng-show="isSafari && !isCordova"><i class="fi-eye"></i>
<span translate>View</span></button> <span translate>View</span></button>
<div ng-show="isCordova"> <div ng-show="isCordova">

View file

@ -68,9 +68,9 @@
spellcheck="false"></textarea> spellcheck="false"></textarea>
</label> </label>
</div> </div>
<div class="col text-center"> <div class="qr-scanner-input-import">
<qr-scanner class="qr-icon size-24" on-scan="join.onQrCodeScanned(data)"></qr-scanner> <qr-scanner on-scan="processWalletInfo(data)"></qr-scanner>
</div> </div>
</div> </div>
<ion-toggle ng-model="showAdv" toggle-class="toggle-stable"> <ion-toggle ng-model="showAdv" toggle-class="toggle-stable">

View file

@ -12,12 +12,6 @@
<div class="item item-divider"> <div class="item item-divider">
Wallet Information Wallet Information
</div> </div>
<div class="item">
<span translate>BETA: Android Key Derivation Test:</span>
<span class="item-note">
{{androidTest}}
</span>
</div>
<div class="item" ng-click="saveBlack()"> <div class="item" ng-click="saveBlack()">
<span translate>Wallet Name (at creation)</span> <span translate>Wallet Name (at creation)</span>
<span class="item-note"> <span class="item-note">
@ -54,22 +48,22 @@
{{derivationStrategy}} {{derivationStrategy}}
</span> </span>
</div> </div>
<div class="item" ng-show="index.externalSource"> <div class="item" ng-show="wallet.isPrivKeyExternal()">
<span translate>Hardware Wallet</span> <span translate>Hardware Wallet</span>
<span class="item-note"> <span class="item-note">
{{index.externalSource}} {{wallet.getPrivKeyExternalSourceName()}}
</span> </span>
</div> </div>
<div class="item" ng-show="!index.externalSource && !index.canSign"> <div class="item" ng-show="!wallet.isPrivKeyExternal() && !wallet.canSign()">
<span translate></span> <span translate></span>
<span class="item-note"> <span class="item-note">
No private key No private key
</span> </span>
</div> </div>
<div class="item" ng-show="index.account"> <div class="item" ng-show="wallet.credentials.account">
<span translate>Account</span>({{derivationStrategy}}) <span translate>Account</span>({{derivationStrategy}})
<span class="item-note"> <span class="item-note">
#{{index.account}} #{{wallet.credentials.account}}
</span> </span>
</div> </div>
@ -77,9 +71,9 @@
Copayers Copayers
</div> </div>
<div class="item item-icon-right" ng-repeat="copayer in index.copayers"> <div class="item item-icon-right" ng-repeat="copayer in wallet.copayers">
<span ng-show="copayer.id == index.copayerId" translate>{{copayer.name}} ({{'Me'|translate}})</span> <span ng-show="copayer.id == wallet.copayerId" translate>{{copayer.name}} ({{'Me'|translate}})</span>
<span ng-style="{'color': 'grey';}" ng-show="copayer.id != index.copayerId" translate>{{copayer.name}}</span> <span ng-style="{'color': 'grey';}" ng-show="copayer.id != wallet.copayerId" translate>{{copayer.name}}</span>
<i class="icon ion-ios-checkmark-outline"></i> <i class="icon ion-ios-checkmark-outline"></i>
</div> </div>
@ -110,21 +104,18 @@
<div translate> <div translate>
Only Main (not change) addresses are shown. The addresses on this list were not verified locally at this time. Only Main (not change) addresses are shown. The addresses on this list were not verified locally at this time.
</div> </div>
<ul class="no-bullet m0"> <button class="button button-block" ng-style="{'color':wallet.color}" href ui-sref="walletHome" ng-click="index.retryScan()" translate>
<li ng-style="{'color':index.backgroundColor}" href ui-sref="walletHome" ng-click="index.retryScan()" translate>
Scan addresses for funds Scan addresses for funds
</li> </button>
<li ng-style="{'color':index.backgroundColor}" ng-show="index.isCordova" ng-click="sendAddrs()" translate> <button class="button button-block" ng-style="{'color':wallet.color}" ng-show="isCordova" ng-click="sendAddrs()" translate>
Send addresses by email Send addresses by email
</li> </button>
</ul>
</div>
<div ng-show="index.balanceByAddress" ng-if="index.balanceByAddress[0]"> <div ng-show="wallet.balanceByAddress" ng-if="wallet.balanceByAddress[0]">
<div class="item item-divider"> <div class="item item-divider">
Balance By Address Balance By Address
</div> </div>
<div class="item" ng-repeat="a in index.balanceByAddress" ng-click="copyToClipboard(a.address)"> <div class="item" ng-repeat="a in wallet.balanceByAddress" ng-click="copyToClipboard(a.address)">
<span>{{a.address}}</span> <span>{{a.address}}</span>
<span class="item-note"> <span class="item-note">
{{(a.amount/1e8).toFixed(8)}} BTC {{(a.amount/1e8).toFixed(8)}} BTC

View file

@ -1,40 +1,39 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('exportController', 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 prevState;
var isWP = platformInfo.isWP; var isWP = platformInfo.isWP;
var isAndroid = platformInfo.isAndroid; 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.isCordova = platformInfo.isCordova;
$scope.isSafari = platformInfo.isSafari; $scope.isSafari = platformInfo.isSafari;
$scope.error = null; $scope.error = null;
$scope.init = function(state) { $scope.init = function() {
$scope.supported = true; $scope.supported = true;
$scope.exportQR = false; $scope.exportQR = false;
$scope.noSignEnabled = false; $scope.noSignEnabled = false;
$scope.showAdvanced = 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) { if (err) {
go.path(prevState); $log.warn(err);
return; return $state.go('wallet.preferencesAdvanced')
} }
handleEncryptedWallet(fc, function(err) { if (!code)
if (err) { $scope.supported = false;
go.path(prevState); else
return; $scope.exportWalletInfo = code;
}
$scope.exportWalletInfo = encodeWalletInfo(); $timeout(function() {
$timeout(function() { $scope.$apply();
$scope.$apply(); }, 1);
}, 1);
});
}); });
}; };
@ -50,62 +49,9 @@ angular.module('copayApp.controllers').controller('exportController',
*/ */
$scope.$on('$destroy', function() { $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.downloadWalletBackup = function() {
$scope.getAddressbook(function(err, localAddressBook) { $scope.getAddressbook(function(err, localAddressBook) {
if (err) { if (err) {
@ -184,11 +130,10 @@ angular.module('copayApp.controllers').controller('exportController',
}; };
$scope.sendWalletBackup = function() { $scope.sendWalletBackup = function() {
var fc = profileService.focusedClient;
window.plugins.toast.showShortCenter(gettextCatalog.getString('Preparing backup...')); window.plugins.toast.showShortCenter(gettextCatalog.getString('Preparing backup...'));
var name = (fc.credentials.walletName || fc.credentials.walletId); var name = (wallet.credentials.walletName || wallet.credentials.walletId);
if (fc.alias) { if (wallet.alias) {
name = fc.alias + ' [' + name + ']'; name = wallet.alias + ' [' + name + ']';
} }
$scope.getBackup(function(backup) { $scope.getBackup(function(backup) {
var ew = backup; var ew = backup;

View file

@ -1,19 +1,21 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('preferencesInformation', 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 base = 'xpub';
var fc = profileService.focusedClient; var wallet = profileService.getWallet($stateParams.walletId);
var c = fc.credentials; var walletId = wallet.id;
var walletId = c.walletId;
var config = configService.getSync(); var config = configService.getSync();
var b = 1; var b = 1;
var isCordova = platformInfo.isCordova; $scope.isCordova = platformInfo.isCordova;
config.colorFor = config.colorFor || {}; config.colorFor = config.colorFor || {};
$scope.init = function() { $scope.init = function() {
var c =wallet.credentials;
var basePath = c.getBaseAddressDerivationPath(); var basePath = c.getBaseAddressDerivationPath();
$scope.wallet = wallet;
$scope.walletName = c.walletName; $scope.walletName = c.walletName;
$scope.walletId = c.walletId; $scope.walletId = c.walletId;
$scope.network = c.network; $scope.network = c.network;
@ -25,7 +27,7 @@ angular.module('copayApp.controllers').controller('preferencesInformation',
$scope.pubKeys = lodash.pluck(c.publicKeyRing, 'xPubKey'); $scope.pubKeys = lodash.pluck(c.publicKeyRing, 'xPubKey');
$scope.addrs = null; $scope.addrs = null;
fc.getMainAddresses({ wallet.getMainAddresses({
doNotVerify: true doNotVerify: true
}, function(err, addrs) { }, function(err, addrs) {
if (err) { if (err) {
@ -62,7 +64,7 @@ angular.module('copayApp.controllers').controller('preferencesInformation',
}; };
$timeout(function() { $timeout(function() {
fc.getMainAddresses({ wallet.getMainAddresses({
doNotVerify: true doNotVerify: true
}, function(err, addrs) { }, function(err, addrs) {
if (err) { if (err) {
@ -113,7 +115,7 @@ angular.module('copayApp.controllers').controller('preferencesInformation',
}; };
$scope.copyToClipboard = function(data) { $scope.copyToClipboard = function(data) {
if (isCordova) { if ($scope.isCordova) {
window.cordova.plugins.clipboard.copy(data); window.cordova.plugins.clipboard.copy(data);
window.plugins.toast.showShortCenter(gettextCatalog.getString('Copied to clipboard')); window.plugins.toast.showShortCenter(gettextCatalog.getString('Copied to clipboard'));
} }

View file

@ -818,7 +818,6 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
}] }]
}); });
pass.then(function(res) { pass.then(function(res) {
console.log('Tapped!', res);
return cb(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; return root;
}); });