diff --git a/public/views/export.html b/public/views/export.html index 9fcf01a17..4140609a1 100644 --- a/public/views/export.html +++ b/public/views/export.html @@ -1,5 +1,5 @@ - + Export Wallet @@ -9,8 +9,10 @@ - - + {{wallet.name}} + + + Exporting via QR not supported for this wallet - + @@ -78,7 +80,7 @@ - + @@ -100,12 +102,12 @@ Download View diff --git a/public/views/import.html b/public/views/import.html index 5c048895b..d2451d9a5 100644 --- a/public/views/import.html +++ b/public/views/import.html @@ -68,9 +68,9 @@ spellcheck="false"> - - - + + + diff --git a/public/views/preferencesInformation.html b/public/views/preferencesInformation.html index 4b65250cc..47c129b32 100644 --- a/public/views/preferencesInformation.html +++ b/public/views/preferencesInformation.html @@ -12,12 +12,6 @@ Wallet Information - - BETA: Android Key Derivation Test: - - {{androidTest}} - - Wallet Name (at creation) @@ -54,22 +48,22 @@ {{derivationStrategy}} - + Hardware Wallet - {{index.externalSource}} + {{wallet.getPrivKeyExternalSourceName()}} - + No private key - + Account({{derivationStrategy}}) - #{{index.account}} + #{{wallet.credentials.account}} @@ -77,9 +71,9 @@ Copayers - - {{copayer.name}} ({{'Me'|translate}}) - {{copayer.name}} + + {{copayer.name}} ({{'Me'|translate}}) + {{copayer.name}} @@ -110,21 +104,18 @@ Only Main (not change) addresses are shown. The addresses on this list were not verified locally at this time. - - + Scan addresses for funds - - + + Send addresses by email - - - + - + Balance By Address - + {{a.address}} {{(a.amount/1e8).toFixed(8)}} BTC diff --git a/src/js/controllers/export.js b/src/js/controllers/export.js index e34866f46..dbde2ff61 100644 --- a/src/js/controllers/export.js +++ b/src/js/controllers/export.js @@ -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; diff --git a/src/js/controllers/preferencesInformation.js b/src/js/controllers/preferencesInformation.js index b11e07108..2b6a157e4 100644 --- a/src/js/controllers/preferencesInformation.js +++ b/src/js/controllers/preferencesInformation.js @@ -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')); } diff --git a/src/js/services/walletService.js b/src/js/services/walletService.js index 00fd0c854..dd25b0c5c 100644 --- a/src/js/services/walletService.js +++ b/src/js/services/walletService.js @@ -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; });