mirror of https://github.com/BTCPrivate/copay.git
Merge pull request #3270 from javierbitpay/feat/paperWallet
Feat/paper wallet
This commit is contained in:
commit
82ee52c6fe
|
@ -8,7 +8,7 @@
|
|||
],
|
||||
"dependencies": {
|
||||
"angular": "1.4.6",
|
||||
"angular-bitcore-wallet-client": "0.4.4",
|
||||
"angular-bitcore-wallet-client": "0.6.4",
|
||||
"angular-foundation": "0.7.0",
|
||||
"angular-gettext": "2.1.0",
|
||||
"angular-moment": "0.10.1",
|
||||
|
@ -23,4 +23,4 @@
|
|||
"ng-lodash": "0.2.3",
|
||||
"qrcode-decoder-js": "*"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
<div
|
||||
class="topbar-container"
|
||||
ng-include="'views/includes/topbar.html'"
|
||||
ng-init="titleSection='Sweep paper wallet'; goBackToState = 'preferencesAdvanced';">
|
||||
</div>
|
||||
|
||||
<div class="content p20v" ng-controller="paperWalletController as paperWallet">
|
||||
<div class="onGoingProcess" ng-show="paperWallet.scanning || paperWallet.sending">
|
||||
<div class="onGoingProcess-content" ng-style="{'background-color':index.backgroundColor}">
|
||||
<div class="spinner">
|
||||
<div class="rect1"></div>
|
||||
<div class="rect2"></div>
|
||||
<div class="rect3"></div>
|
||||
<div class="rect4"></div>
|
||||
<div class="rect5"></div>
|
||||
</div>
|
||||
<span ng-show="paperWallet.scanning" translate>Scanning wallet funds...</span>
|
||||
<span ng-show="paperWallet.sending" translate>Sending funds...</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="box-notification text-warning" ng-show="paperWallet.error">
|
||||
<i class="fi-alert size-12"></i>
|
||||
<span>{{paperWallet.error|translate}}</span>
|
||||
</div>
|
||||
<div ng-show="!paperWallet.balance" class="row">
|
||||
<div class="large-12 medium-12 columns">
|
||||
<div class="input">
|
||||
<label for="privateKey" translate>Paper Wallet Private Key</label>
|
||||
<input type="text" placeholder="{{'Paste your paper wallet private key here'|translate}}" ng-model="privateKey" id="privateKey">
|
||||
<div class="qr-scanner-input">
|
||||
<qr-scanner on-scan="paperWallet.onQrCodeScanned(data)"></qr-scanner>
|
||||
</div>
|
||||
<label for="passphrase">
|
||||
<span translate>Passphrase (if you have one)</span>
|
||||
</label>
|
||||
<input id="passphrase" type="password" name="passphrase" placeholder="{{'Passphrase'|translate}}" ng-model="passphrase">
|
||||
<p ng-show="index.isCordova" translate class="size-12 text-gray">
|
||||
Decrypting a paper wallet could take around 5 minutes on this device. please be patient and keep the app open.
|
||||
</p>
|
||||
<button
|
||||
ng-disabled="paperWallet.scanning || !privateKey"
|
||||
ng-style="{'background-color':index.backgroundColor}"
|
||||
class="button black round expand"
|
||||
ng-click="paperWallet.createTx(privateKey, passphrase)"
|
||||
translate>Scan Wallet Funds
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div ng-show="paperWallet.balance" class="row">
|
||||
<div class="large-12 medium-12 columns">
|
||||
<div class="text-center m20b">
|
||||
<h4 class="text-bold" translate>Funds founds</h4>
|
||||
<div class="size-24">
|
||||
{{paperWallet.balance}} BTC
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
ng-disabled="paperWallet.sending"
|
||||
ng-style="{'background-color':index.backgroundColor}"
|
||||
class="button black round expand"
|
||||
ng-click="paperWallet.transaction()"
|
||||
translate>Sweep Wallet
|
||||
</button>
|
||||
<div class="text-center">
|
||||
<div class="size-12 text-gray" translate>Funds will be transfered to</div>
|
||||
<b>{{index.alias || index.walletName}}</b>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="extra-margin-bottom"></div>
|
|
@ -16,6 +16,11 @@
|
|||
<li class="line-b p20" ng-click="index.retryScan(); $root.go('walletHome'); ">
|
||||
<span translate>Scan addresses for funds</span>
|
||||
</li>
|
||||
|
||||
<li class="line-b p20" ng-click="$root.go('paperWallet')">
|
||||
<i class="icon-arrow-right3 size-24 right text-gray"></i>
|
||||
<span translate>Sweep paper wallet</span>
|
||||
</li>
|
||||
|
||||
<li class="line-b p20" ng-click="$root.go('export')">
|
||||
<i class="icon-arrow-right3 size-24 right text-gray"></i>
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
angular.module('copayApp.controllers').controller('paperWalletController',
|
||||
function($scope, $http, $timeout, profileService, go, addressService, bitcore) {
|
||||
self = this;
|
||||
var fc = profileService.focusedClient;
|
||||
var rawTx;
|
||||
|
||||
self.onQrCodeScanned = function(data) {
|
||||
$scope.privateKey = data;
|
||||
}
|
||||
|
||||
self.createTx = function(privateKey, passphrase) {
|
||||
if (privateKey.charAt(0) != 6) {
|
||||
var isValidKey = self.checkPrivateKey(privateKey);
|
||||
|
||||
if (!isValidKey) return;
|
||||
}
|
||||
|
||||
self.error = null;
|
||||
self.scanning = true;
|
||||
$timeout(function() {
|
||||
self.getRawTx(privateKey, passphrase, function(err, rawtx, utxos) {
|
||||
self.scanning = false;
|
||||
|
||||
if (err)
|
||||
self.error = err.toString();
|
||||
else {
|
||||
self.balance = (utxos / 1e8).toFixed(8);
|
||||
rawTx = rawtx;
|
||||
}
|
||||
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
}, 1);
|
||||
});
|
||||
}, 100);
|
||||
};
|
||||
|
||||
self.checkPrivateKey = function(privateKey) {
|
||||
try {
|
||||
new bitcore.PrivateKey(privateKey, 'livenet');
|
||||
} catch (err) {
|
||||
self.error = err.toString();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
self.getRawTx = function(privateKey, passphrase, cb) {
|
||||
if (privateKey.charAt(0) == 6) {
|
||||
fc.decryptBIP38PrivateKey(privateKey, passphrase, null, function(err, privateKey) {
|
||||
if (err) return cb(err);
|
||||
|
||||
fc.getBalanceFromPrivateKey(privateKey, function(err, utxos) {
|
||||
if (err) return cb(err);
|
||||
|
||||
addressService.getAddress(fc.credentials.walletId, true, function(err, destinationAddress) {
|
||||
if (err) return cb(err);
|
||||
|
||||
fc.buildTxFromPrivateKey(privateKey, destinationAddress, null, function(err, tx) {
|
||||
if (err) return cb(err);
|
||||
return cb(null, tx.serialize(), utxos);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
fc.getBalanceFromPrivateKey(privateKey, function(err, utxos) {
|
||||
if (err) return cb(err)
|
||||
|
||||
addressService.getAddress(fc.credentials.walletId, true, function(err, destinationAddress) {
|
||||
if (err) return cb(err);
|
||||
|
||||
fc.buildTxFromPrivateKey(privateKey, destinationAddress, null, function(err, tx) {
|
||||
if (err) return cb(err);
|
||||
return cb(null, tx.serialize(), utxos);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
self.transaction = function() {
|
||||
self.error = null;
|
||||
self.sending = true;
|
||||
$timeout(function() {
|
||||
self.doTransaction(rawTx).then(function(err, response) {
|
||||
self.sending = false;
|
||||
self.goHome();
|
||||
},
|
||||
function(err) {
|
||||
self.sending = false;
|
||||
self.error = err.toString();
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
}, 1);
|
||||
});
|
||||
}, 100);
|
||||
};
|
||||
|
||||
self.goHome = function() {
|
||||
go.walletHome();
|
||||
};
|
||||
|
||||
self.doTransaction = function(rawTx) {
|
||||
return $http.post('https://insight.bitpay.com/api/tx/send', {
|
||||
rawtx: rawTx
|
||||
});
|
||||
};
|
||||
});
|
|
@ -2,4 +2,5 @@
|
|||
|
||||
angular.module('copayApp.controllers').controller('preferencesAdvancedController',
|
||||
function($scope) {
|
||||
});
|
||||
|
||||
});
|
117
src/js/routes.js
117
src/js/routes.js
|
@ -44,7 +44,7 @@ angular
|
|||
v = JSON.stringify(v);
|
||||
}
|
||||
// Trim output in mobile
|
||||
if ( window.cordova ) {
|
||||
if (window.cordova) {
|
||||
v = v.toString();
|
||||
if (v.length > 1000) {
|
||||
v = v.substr(0, 997) + '...';
|
||||
|
@ -85,7 +85,7 @@ angular
|
|||
}
|
||||
});
|
||||
|
||||
$stateProvider
|
||||
$stateProvider
|
||||
.state('translators', {
|
||||
url: '/translators',
|
||||
walletShouldBeComplete: true,
|
||||
|
@ -275,27 +275,27 @@ angular
|
|||
})
|
||||
|
||||
.state('preferencesGlidera', {
|
||||
url: '/preferencesGlidera',
|
||||
walletShouldBeComplete: true,
|
||||
needProfile: true,
|
||||
views: {
|
||||
'main': {
|
||||
templateUrl: 'views/preferencesGlidera.html'
|
||||
},
|
||||
}
|
||||
})
|
||||
url: '/preferencesGlidera',
|
||||
walletShouldBeComplete: true,
|
||||
needProfile: true,
|
||||
views: {
|
||||
'main': {
|
||||
templateUrl: 'views/preferencesGlidera.html'
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
.state('preferencesAdvanced', {
|
||||
url: '/preferencesAdvanced',
|
||||
templateUrl: 'views/preferencesAdvanced.html',
|
||||
walletShouldBeComplete: true,
|
||||
needProfile: true,
|
||||
views: {
|
||||
'main': {
|
||||
templateUrl: 'views/preferencesAdvanced.html'
|
||||
},
|
||||
}
|
||||
})
|
||||
url: '/preferencesAdvanced',
|
||||
templateUrl: 'views/preferencesAdvanced.html',
|
||||
walletShouldBeComplete: true,
|
||||
needProfile: true,
|
||||
views: {
|
||||
'main': {
|
||||
templateUrl: 'views/preferencesAdvanced.html'
|
||||
},
|
||||
}
|
||||
})
|
||||
.state('preferencesColor', {
|
||||
url: '/preferencesColor',
|
||||
templateUrl: 'views/preferencesColor.html',
|
||||
|
@ -309,16 +309,16 @@ angular
|
|||
})
|
||||
|
||||
.state('preferencesAltCurrency', {
|
||||
url: '/preferencesAltCurrency',
|
||||
templateUrl: 'views/preferencesAltCurrency.html',
|
||||
walletShouldBeComplete: true,
|
||||
needProfile: true,
|
||||
views: {
|
||||
'main': {
|
||||
templateUrl: 'views/preferencesAltCurrency.html'
|
||||
},
|
||||
}
|
||||
})
|
||||
url: '/preferencesAltCurrency',
|
||||
templateUrl: 'views/preferencesAltCurrency.html',
|
||||
walletShouldBeComplete: true,
|
||||
needProfile: true,
|
||||
views: {
|
||||
'main': {
|
||||
templateUrl: 'views/preferencesAltCurrency.html'
|
||||
},
|
||||
}
|
||||
})
|
||||
.state('preferencesAlias', {
|
||||
url: '/preferencesAlias',
|
||||
templateUrl: 'views/preferencesAlias.html',
|
||||
|
@ -376,18 +376,18 @@ angular
|
|||
},
|
||||
}
|
||||
})
|
||||
|
||||
.state('about', {
|
||||
url: '/about',
|
||||
templateUrl: 'views/preferencesAbout.html',
|
||||
walletShouldBeComplete: true,
|
||||
needProfile: true,
|
||||
views: {
|
||||
'main': {
|
||||
templateUrl: 'views/preferencesAbout.html'
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
.state('about', {
|
||||
url: '/about',
|
||||
templateUrl: 'views/preferencesAbout.html',
|
||||
walletShouldBeComplete: true,
|
||||
needProfile: true,
|
||||
views: {
|
||||
'main': {
|
||||
templateUrl: 'views/preferencesAbout.html'
|
||||
},
|
||||
}
|
||||
})
|
||||
.state('logs', {
|
||||
url: '/logs',
|
||||
templateUrl: 'views/preferencesLogs.html',
|
||||
|
@ -410,6 +410,17 @@ angular
|
|||
},
|
||||
}
|
||||
})
|
||||
.state('paperWallet', {
|
||||
url: '/paperWallet',
|
||||
templateUrl: 'views/paperWallet.html',
|
||||
walletShouldBeComplete: true,
|
||||
needProfile: true,
|
||||
views: {
|
||||
'main': {
|
||||
templateUrl: 'views/paperWallet.html'
|
||||
},
|
||||
}
|
||||
})
|
||||
.state('backup', {
|
||||
url: '/backup',
|
||||
templateUrl: 'views/backup.html',
|
||||
|
@ -435,14 +446,14 @@ angular
|
|||
})
|
||||
|
||||
.state('add', {
|
||||
url: '/add',
|
||||
needProfile: true,
|
||||
views: {
|
||||
'main': {
|
||||
templateUrl: 'views/add.html'
|
||||
},
|
||||
}
|
||||
})
|
||||
url: '/add',
|
||||
needProfile: true,
|
||||
views: {
|
||||
'main': {
|
||||
templateUrl: 'views/add.html'
|
||||
},
|
||||
}
|
||||
})
|
||||
.state('cordova', {
|
||||
url: '/cordova/:status/:isHome',
|
||||
views: {
|
||||
|
@ -450,7 +461,7 @@ angular
|
|||
controller: function($rootScope, $state, $stateParams, $timeout, go, isCordova) {
|
||||
switch ($stateParams.status) {
|
||||
case 'resume':
|
||||
$rootScope.$emit('Local/Resume');
|
||||
$rootScope.$emit('Local/Resume');
|
||||
break;
|
||||
case 'backbutton':
|
||||
if (isCordova && $stateParams.isHome == 'true' && !$rootScope.modalOpened) {
|
||||
|
@ -534,4 +545,4 @@ angular
|
|||
}, 50);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue