clipboard features

This commit is contained in:
Sebastiaan Pasma 2018-07-10 11:08:03 +02:00
commit 94e6dd7dac
3 changed files with 27 additions and 12 deletions

View file

@ -2,6 +2,7 @@
angular.module('copayApp.controllers').controller('tabSendV2Controller', function($scope, $rootScope, $log, $timeout, $ionicScrollDelegate, addressbookService, profileService, lodash, $state, walletService, incomingData, popupService, platformInfo, bwcError, gettextCatalog, scannerService, configService, bitcoinCashJsService, $ionicNavBarDelegate, clipboardService) { angular.module('copayApp.controllers').controller('tabSendV2Controller', function($scope, $rootScope, $log, $timeout, $ionicScrollDelegate, addressbookService, profileService, lodash, $state, walletService, incomingData, popupService, platformInfo, bwcError, gettextCatalog, scannerService, configService, bitcoinCashJsService, $ionicNavBarDelegate, clipboardService) {
var clipboardHasAddress = false; var clipboardHasAddress = false;
var clipboardHasContent = false;
$scope.addContact = function() { $scope.addContact = function() {
$state.go('tabs.settings').then(function() { $state.go('tabs.settings').then(function() {
@ -12,19 +13,28 @@ angular.module('copayApp.controllers').controller('tabSendV2Controller', functio
}; };
$scope.pasteClipboard = function() { $scope.pasteClipboard = function() {
clipboardService.readFromClipboard(function(text) { if ($scope.clipboardHasAddress || $scope.clipboardHasContent) {
$scope.formData.search = text; clipboardService.readFromClipboard(function(text) {
$scope.findContact($scope.formData.search); $scope.formData.search = text;
}); $scope.findContact($scope.formData.search);
} });
}
};
$scope.$on("$ionicView.enter", function(event, data) { $scope.$on("$ionicView.enter", function(event, data) {
clipboardService.readFromClipboard(function(text) { clipboardService.readFromClipboard(function(text) {
if (text.length > 200) {
text = text.substring(0, 200);
}
$scope.clipboardHasAddress = false; $scope.clipboardHasAddress = false;
$scope.clipboardHasContent = false;
if ((text.indexOf('bitcoincash:') === 0 || text[0] === 'C' || text[0] === 'H' || text[0] === 'p' || text[0] === 'q') && text.replace('bitcoincash:', '').length === 42) { // CashAddr if ((text.indexOf('bitcoincash:') === 0 || text[0] === 'C' || text[0] === 'H' || text[0] === 'p' || text[0] === 'q') && text.replace('bitcoincash:', '').length === 42) { // CashAddr
$scope.clipboardHasAddress = true; $scope.clipboardHasAddress = true;
} else if ((text[0] === "1" || text[0] === "3" || text.substring(0, 3) === "bc1") && text.length >= 26 && text.length <= 35) { // Legacy Addresses } else if ((text[0] === "1" || text[0] === "3" || text.substring(0, 3) === "bc1") && text.length >= 26 && text.length <= 35) { // Legacy Addresses
$scope.clipboardHasAddress = true; $scope.clipboardHasAddress = true;
} else if (text.length > 1) {
$scope.clipboardHasContent = true;
} }
}); });

View file

@ -62,7 +62,10 @@
display: inline-block; display: inline-block;
margin-bottom: 4px; margin-bottom: 4px;
} }
&.contains-address { &.contains-address, &.contains-content {
.address {
display: none;
}
background: #FAB915; background: #FAB915;
color: #FFF !important; color: #FFF !important;
border: 0; border: 0;
@ -70,11 +73,13 @@
.icon { .icon {
background: url(../img/icon-clipboard-paste-white.svg); background: url(../img/icon-clipboard-paste-white.svg);
} }
.address { &.contains-address {
display: inline; .address {
} display: inline;
.non-address { }
display: none; .non-address {
display: none;
}
} }
} }
} }

View file

@ -15,7 +15,7 @@
<div class="buttons"> <div class="buttons">
<div class="row"> <div class="row">
<div class="col-40"> <div class="col-40">
<button class="button button-standard button-primary button-outline button-clipboard-paste" ng-click="pasteClipboard()" ng-class="{'contains-address': clipboardHasAddress}"> <button class="button button-standard button-primary button-outline button-clipboard-paste" ng-click="pasteClipboard()" ng-class="{'contains-address': clipboardHasAddress, 'contains-content': clipboardHasContent}">
<span class="icon"></span><br/> <span class="icon"></span><br/>
<span class="non-address" translate>Paste Clipboard</span> <span class="non-address" translate>Paste Clipboard</span>
<span class="address" translate>Paste Address</span> <span class="address" translate>Paste Address</span>