sweep paper wallet from scanner tab
This commit is contained in:
parent
b665922e7a
commit
ec6d78237c
8 changed files with 10119 additions and 175 deletions
|
|
@ -1,16 +1,6 @@
|
|||
angular.module('copayApp.controllers').controller('paperWalletController',
|
||||
function($scope, $timeout, $log, $ionicModal, $ionicHistory, popupService, gettextCatalog, platformInfo, configService, profileService, $state, bitcore, ongoingProcess, txFormatService, $stateParams, walletService) {
|
||||
|
||||
$scope.onQrCodeScannedPaperWallet = function(data) {
|
||||
$scope.formData.inputData = data;
|
||||
$scope.onData(data);
|
||||
};
|
||||
|
||||
$scope.onData = function(data) {
|
||||
$scope.scannedKey = data;
|
||||
$scope.isPkEncrypted = (data.substring(0, 2) == '6P');
|
||||
};
|
||||
|
||||
function _scanFunds(cb) {
|
||||
function getPrivateKey(scannedKey, isPkEncrypted, passphrase, cb) {
|
||||
if (!isPkEncrypted) return cb(null, scannedKey);
|
||||
|
|
@ -42,9 +32,6 @@ angular.module('copayApp.controllers').controller('paperWalletController',
|
|||
};
|
||||
|
||||
$scope.scanFunds = function() {
|
||||
$scope.privateKey = '';
|
||||
$scope.balanceSat = 0;
|
||||
|
||||
ongoingProcess.set('scanning', true);
|
||||
$timeout(function() {
|
||||
_scanFunds(function(err, privateKey, balance) {
|
||||
|
|
@ -52,14 +39,15 @@ angular.module('copayApp.controllers').controller('paperWalletController',
|
|||
if (err) {
|
||||
$log.error(err);
|
||||
popupService.showAlert(gettextCatalog.getString('Error scanning funds:'), err || err.toString());
|
||||
$state.go('tabs.home');
|
||||
} else {
|
||||
$scope.privateKey = privateKey;
|
||||
$scope.balanceSat = balance;
|
||||
if ($scope.balanceSat <= 0)
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Not funds found'));
|
||||
var config = configService.getSync().wallet.settings;
|
||||
$scope.balance = txFormatService.formatAmount(balance) + ' ' + config.unitName;
|
||||
$scope.scanned = true;
|
||||
}
|
||||
|
||||
$scope.$apply();
|
||||
});
|
||||
}, 100);
|
||||
|
|
@ -95,45 +83,61 @@ angular.module('copayApp.controllers').controller('paperWalletController',
|
|||
$log.error(err);
|
||||
popupService.showAlert(gettextCatalog.getString('Error sweeping wallet:'), err || err.toString());
|
||||
} else {
|
||||
$scope.openStatusModal('broadcasted', function() {
|
||||
$ionicHistory.removeBackView();
|
||||
$state.go('tabs.home');
|
||||
});
|
||||
$scope.sendStatus = 'success';
|
||||
}
|
||||
$scope.$apply();
|
||||
});
|
||||
}, 100);
|
||||
};
|
||||
|
||||
$scope.openStatusModal = function(type, cb) {
|
||||
$scope.tx = {};
|
||||
$scope.tx.amountStr = $scope.balance;
|
||||
$scope.type = type;
|
||||
$scope.color = $scope.wallet.backgroundColor;
|
||||
$scope.cb = cb;
|
||||
|
||||
$ionicModal.fromTemplateUrl('views/modals/tx-status.html', {
|
||||
scope: $scope
|
||||
}).then(function(modal) {
|
||||
$scope.txStatusModal = modal;
|
||||
$scope.txStatusModal.show();
|
||||
});
|
||||
$scope.onSuccessConfirm = function() {
|
||||
$state.go('tabs.home');
|
||||
};
|
||||
|
||||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||
var wallet = profileService.getWallet($stateParams.walletId);
|
||||
$scope.$on('Wallet/Changed', function(event, wallet) {
|
||||
if (!wallet) {
|
||||
$log.debug('No wallet provided');
|
||||
return;
|
||||
}
|
||||
if (wallet == $scope.wallet) {
|
||||
$log.debug('No change in wallet');
|
||||
return;
|
||||
}
|
||||
$scope.wallet = wallet;
|
||||
$scope.needsBackup = wallet.needsBackup;
|
||||
$scope.walletAlias = wallet.name;
|
||||
$scope.walletName = wallet.credentials.walletName;
|
||||
$scope.formData = {};
|
||||
$scope.formData.inputData = null;
|
||||
$scope.scannedKey = null;
|
||||
$scope.balance = null;
|
||||
$scope.balanceSat = null;
|
||||
$scope.scanned = false;
|
||||
$log.debug('Wallet changed: ' + wallet.name);
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
}, 10);
|
||||
});
|
||||
});
|
||||
|
||||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||
$scope.scannedKey = (data.stateParams && data.stateParams.privateKey) ? data.stateParams.privateKey : null;
|
||||
$scope.isPkEncrypted = $scope.scannedKey ? ($scope.scannedKey.substring(0, 2) == '6P') : null;
|
||||
$scope.sendStatus = null;
|
||||
$scope.error = false;
|
||||
|
||||
$scope.wallets = profileService.getWallets({
|
||||
onlyComplete: true,
|
||||
network: 'livenet',
|
||||
});
|
||||
|
||||
if (!$scope.wallets || !$scope.wallets.length) {
|
||||
$scope.noMatchingWallet = true;
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
$scope.$on("$ionicView.enter", function(event, data) {
|
||||
$scope.wallet = $scope.wallets[0];
|
||||
if (!$scope.wallet) return;
|
||||
if (!$scope.isPkEncrypted) $scope.scanFunds();
|
||||
else {
|
||||
var message = gettextCatalog.getString('Private key encrypted. Enter password');
|
||||
popupService.showPrompt(null, message, null, function(res) {
|
||||
$scope.passphrase = res;
|
||||
$scope.scanFunds();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ angular.module('copayApp.directives')
|
|||
scope.showMenu = true;
|
||||
scope.https = false;
|
||||
|
||||
if(scope.type === 'url') {
|
||||
if(scope.data.indexOf('https://') === 0) {
|
||||
if (scope.type === 'url') {
|
||||
if (scope.data.indexOf('https://') === 0) {
|
||||
scope.https = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -24,14 +24,16 @@ angular.module('copayApp.directives')
|
|||
scope.showMenu = false;
|
||||
$rootScope.$broadcast('incomingDataMenu.menuHidden');
|
||||
};
|
||||
scope.goToUrl = function(url){
|
||||
scope.goToUrl = function(url) {
|
||||
externalLinkService.open(url);
|
||||
};
|
||||
scope.sendPaymentToAddress = function(bitcoinAddress) {
|
||||
scope.showMenu = false;
|
||||
$state.go('tabs.send').then(function() {
|
||||
$timeout(function() {
|
||||
$state.transitionTo('tabs.send.amount', {toAddress: bitcoinAddress});
|
||||
$state.transitionTo('tabs.send.amount', {
|
||||
toAddress: bitcoinAddress
|
||||
});
|
||||
}, 50);
|
||||
});
|
||||
};
|
||||
|
|
@ -40,11 +42,23 @@ angular.module('copayApp.directives')
|
|||
$timeout(function() {
|
||||
$state.go('tabs.send').then(function() {
|
||||
$timeout(function() {
|
||||
$state.transitionTo('tabs.send.addressbook', {addressbookEntry: bitcoinAddress});
|
||||
$state.transitionTo('tabs.send.addressbook', {
|
||||
addressbookEntry: bitcoinAddress
|
||||
});
|
||||
});
|
||||
});
|
||||
}, 100);
|
||||
};
|
||||
scope.scanPaperWallet = function(privateKey) {
|
||||
scope.showMenu = false;
|
||||
$state.go('tabs.home').then(function() {
|
||||
$timeout(function() {
|
||||
$state.transitionTo('tabs.home.paperWallet', {
|
||||
privateKey: privateKey
|
||||
});
|
||||
}, 50);
|
||||
});
|
||||
};
|
||||
}
|
||||
};
|
||||
});
|
||||
|
|
|
|||
|
|
@ -555,15 +555,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
}
|
||||
}
|
||||
})
|
||||
.state('tabs.preferences.paperWallet', {
|
||||
url: '/paperWallet',
|
||||
views: {
|
||||
'tab-settings@tabs': {
|
||||
controller: 'paperWalletController',
|
||||
templateUrl: 'views/paperWallet.html'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
/*
|
||||
*
|
||||
|
|
@ -642,10 +633,25 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
|
||||
/*
|
||||
*
|
||||
* Onboarding
|
||||
* Paper Wallet
|
||||
*
|
||||
*/
|
||||
|
||||
.state('tabs.home.paperWallet', {
|
||||
url: '/paperWallet/:privateKey',
|
||||
views: {
|
||||
'tab-home@tabs': {
|
||||
controller: 'paperWalletController',
|
||||
templateUrl: 'views/paperWallet.html'
|
||||
}
|
||||
}
|
||||
})
|
||||
/*
|
||||
*
|
||||
* Onboarding
|
||||
*
|
||||
*/
|
||||
|
||||
.state('onboarding', {
|
||||
url: '/onboarding',
|
||||
abstract: true,
|
||||
|
|
|
|||
|
|
@ -31,17 +31,31 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
|
|||
if (!url) return;
|
||||
name = name.replace(/[\[\]]/g, "\\$&");
|
||||
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
|
||||
results = regex.exec(url);
|
||||
results = regex.exec(url);
|
||||
if (!results) return null;
|
||||
if (!results[2]) return '';
|
||||
return decodeURIComponent(results[2].replace(/\+/g, " "));
|
||||
}
|
||||
|
||||
function checkPrivateKey(privateKey) {
|
||||
try {
|
||||
new bitcore.PrivateKey(privateKey, 'livenet');
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// data extensions for Payment Protocol with non-backwards-compatible request
|
||||
if ((/^bitcoin:\?r=[\w+]/).exec(data)) {
|
||||
data = decodeURIComponent(data.replace('bitcoin:?r=', ''));
|
||||
$state.go('tabs.send', {}, {'reload': true, 'notify': $state.current.name == 'tabs.send' ? false : true}).then(function() {
|
||||
$state.transitionTo('tabs.send.confirm', {paypro: data});
|
||||
$state.go('tabs.send', {}, {
|
||||
'reload': true,
|
||||
'notify': $state.current.name == 'tabs.send' ? false : true
|
||||
}).then(function() {
|
||||
$state.transitionTo('tabs.send.confirm', {
|
||||
paypro: data
|
||||
});
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
|
@ -55,31 +69,43 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
|
|||
var addr = parsed.address ? parsed.address.toString() : '';
|
||||
var message = parsed.message;
|
||||
|
||||
var amount = parsed.amount ? parsed.amount : '';
|
||||
var amount = parsed.amount ? parsed.amount : '';
|
||||
|
||||
if (parsed.r) {
|
||||
payproService.getPayProDetails(parsed.r, function(err, details) {
|
||||
handlePayPro(details);
|
||||
});
|
||||
} else {
|
||||
$state.go('tabs.send', {}, {'reload': true, 'notify': $state.current.name == 'tabs.send' ? false : true});
|
||||
$state.go('tabs.send', {}, {
|
||||
'reload': true,
|
||||
'notify': $state.current.name == 'tabs.send' ? false : true
|
||||
});
|
||||
// Timeout is required to enable the "Back" button
|
||||
$timeout(function() {
|
||||
if (amount) {
|
||||
$state.transitionTo('tabs.send.confirm', {toAmount: amount, toAddress: addr, description:message});
|
||||
$state.transitionTo('tabs.send.confirm', {
|
||||
toAmount: amount,
|
||||
toAddress: addr,
|
||||
description: message
|
||||
});
|
||||
} else {
|
||||
$state.transitionTo('tabs.send.amount', {toAddress: addr});
|
||||
$state.transitionTo('tabs.send.amount', {
|
||||
toAddress: addr
|
||||
});
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
return true;
|
||||
|
||||
// Plain URL
|
||||
// Plain URL
|
||||
} else if (/^https?:\/\//.test(data)) {
|
||||
|
||||
payproService.getPayProDetails(data, function(err, details) {
|
||||
if(err) {
|
||||
root.showMenu({data: data, type: 'url'});
|
||||
if (err) {
|
||||
root.showMenu({
|
||||
data: data,
|
||||
type: 'url'
|
||||
});
|
||||
return;
|
||||
}
|
||||
handlePayPro(details);
|
||||
|
|
@ -87,47 +113,75 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
|
|||
});
|
||||
// Plain Address
|
||||
} else if (bitcore.Address.isValid(data, 'livenet') || bitcore.Address.isValid(data, 'testnet')) {
|
||||
if($state.includes('tabs.scan')) {
|
||||
root.showMenu({data: data, type: 'bitcoinAddress'});
|
||||
if ($state.includes('tabs.scan')) {
|
||||
root.showMenu({
|
||||
data: data,
|
||||
type: 'bitcoinAddress'
|
||||
});
|
||||
} else {
|
||||
goToAmountPage(data);
|
||||
}
|
||||
} else if (data && data.indexOf($window.appConfig.name + '://glidera') === 0) {
|
||||
return $state.go('uriglidera', {url: data});
|
||||
return $state.go('uriglidera', {
|
||||
url: data
|
||||
});
|
||||
} else if (data && data.indexOf($window.appConfig.name + '://coinbase') === 0) {
|
||||
return $state.go('uricoinbase', {url: data});
|
||||
return $state.go('uricoinbase', {
|
||||
url: data
|
||||
});
|
||||
|
||||
// BitPayCard Authentication
|
||||
} else if (data && data.indexOf($window.appConfig.name + '://') === 0) {
|
||||
var secret = getParameterByName('secret', data);
|
||||
var email = getParameterByName('email', data);
|
||||
var otp = getParameterByName('otp', data);
|
||||
$state.go('tabs.home', {}, {'reload': true, 'notify': $state.current.name == 'tabs.home' ? false : true}).then(function() {
|
||||
$state.transitionTo('tabs.bitpayCardIntro', {
|
||||
secret: secret,
|
||||
email: email,
|
||||
otp: otp
|
||||
});
|
||||
var secret = getParameterByName('secret', data);
|
||||
var email = getParameterByName('email', data);
|
||||
var otp = getParameterByName('otp', data);
|
||||
$state.go('tabs.home', {}, {
|
||||
'reload': true,
|
||||
'notify': $state.current.name == 'tabs.home' ? false : true
|
||||
}).then(function() {
|
||||
$state.transitionTo('tabs.bitpayCardIntro', {
|
||||
secret: secret,
|
||||
email: email,
|
||||
otp: otp
|
||||
});
|
||||
return true;
|
||||
});
|
||||
return true;
|
||||
|
||||
// Join
|
||||
// Join
|
||||
} else if (data && data.match(/^copay:[0-9A-HJ-NP-Za-km-z]{70,80}$/)) {
|
||||
$state.go('tabs.home', {}, {'reload': true, 'notify': $state.current.name == 'tabs.home' ? false : true}).then(function() {
|
||||
$state.transitionTo('tabs.add.join', {url: data});
|
||||
$state.go('tabs.home', {}, {
|
||||
'reload': true,
|
||||
'notify': $state.current.name == 'tabs.home' ? false : true
|
||||
}).then(function() {
|
||||
$state.transitionTo('tabs.add.join', {
|
||||
url: data
|
||||
});
|
||||
});
|
||||
return true;
|
||||
|
||||
// Old join
|
||||
// Old join
|
||||
} else if (data && data.match(/^[0-9A-HJ-NP-Za-km-z]{70,80}$/)) {
|
||||
$state.go('tabs.home', {}, {'reload': true, 'notify': $state.current.name == 'tabs.home' ? false : true}).then(function() {
|
||||
$state.transitionTo('tabs.add.join', {url: data});
|
||||
$state.go('tabs.home', {}, {
|
||||
'reload': true,
|
||||
'notify': $state.current.name == 'tabs.home' ? false : true
|
||||
}).then(function() {
|
||||
$state.transitionTo('tabs.add.join', {
|
||||
url: data
|
||||
});
|
||||
});
|
||||
return true;
|
||||
} else if (data && (data.substring(0, 2) == '6P' || checkPrivateKey(data))) {
|
||||
root.showMenu({
|
||||
data: data,
|
||||
type: 'privateKey'
|
||||
});
|
||||
} else {
|
||||
|
||||
if($state.includes('tabs.scan')) {
|
||||
root.showMenu({data: data, type: 'text'});
|
||||
if ($state.includes('tabs.scan')) {
|
||||
root.showMenu({
|
||||
data: data,
|
||||
type: 'text'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -136,13 +190,18 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
|
|||
};
|
||||
|
||||
function goToAmountPage(toAddress) {
|
||||
$state.go('tabs.send', {}, {'reload': true, 'notify': $state.current.name == 'tabs.send' ? false : true});
|
||||
$state.go('tabs.send', {}, {
|
||||
'reload': true,
|
||||
'notify': $state.current.name == 'tabs.send' ? false : true
|
||||
});
|
||||
$timeout(function() {
|
||||
$state.transitionTo('tabs.send.amount', {toAddress: toAddress});
|
||||
$state.transitionTo('tabs.send.amount', {
|
||||
toAddress: toAddress
|
||||
});
|
||||
}, 100);
|
||||
}
|
||||
|
||||
function handlePayPro(payProDetails){
|
||||
function handlePayPro(payProDetails) {
|
||||
var stateParams = {
|
||||
toAmount: payProDetails.amount,
|
||||
toAddress: payProDetails.toAddress,
|
||||
|
|
@ -150,7 +209,10 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
|
|||
paypro: payProDetails
|
||||
};
|
||||
scannerService.pausePreview();
|
||||
$state.go('tabs.send', {}, {'reload': true, 'notify': $state.current.name == 'tabs.send' ? false : true}).then(function() {
|
||||
$state.go('tabs.send', {}, {
|
||||
'reload': true,
|
||||
'notify': $state.current.name == 'tabs.send' ? false : true
|
||||
}).then(function() {
|
||||
$timeout(function() {
|
||||
$state.transitionTo('tabs.send.confirm', stateParams);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue