Merge pull request #198 from Bitcoin-com/wallet/task/409

Bug - 409 - "Generate new address" copies "bitcoincash:null" to the clipboard instead of a new address
This commit is contained in:
Jean-Baptiste Dominguez 2018-07-03 11:26:54 +09:00 committed by GitHub
commit d6222623e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 23 deletions

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('tabReceiveController', function($rootScope, $scope, $timeout, $log, $ionicModal, $state, $ionicHistory, $ionicPopover, storageService, platformInfo, walletService, profileService, configService, lodash, gettextCatalog, popupService, bwcError, bitcoinCashJsService, $ionicNavBarDelegate, txFormatService) { angular.module('copayApp.controllers').controller('tabReceiveController', function($rootScope, $scope, $timeout, $log, $ionicModal, $state, $ionicHistory, $ionicPopover, storageService, platformInfo, walletService, profileService, configService, lodash, gettextCatalog, popupService, bwcError, bitcoinCashJsService, $ionicNavBarDelegate, txFormatService, clipboardService) {
var listeners = []; var listeners = [];
$scope.bchAddressType = { type: 'cashaddr' }; $scope.bchAddressType = { type: 'cashaddr' };
@ -74,6 +74,12 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi
paymentSubscriptionObj.addr = $scope.addr paymentSubscriptionObj.addr = $scope.addr
} }
try {
clipboardService.copyToClipboard($scope.wallet.coin == 'bch' && $scope.bchAddressType.type == 'cashaddr' ? 'bitcoincash:' + $scope.addr : $scope.addr);
} catch (error) {
$log.debug("Error copying to clipboard:");
$log.debug(error);
}
// create subscription // create subscription
var msg = JSON.stringify(paymentSubscriptionObj); var msg = JSON.stringify(paymentSubscriptionObj);
currentAddressSocket.onopen = function (event) { currentAddressSocket.onopen = function (event) {

View file

@ -1,38 +1,26 @@
'use strict'; 'use strict';
angular.module('copayApp.directives') angular.module('copayApp.directives')
.directive('copyToClipboard', function(platformInfo, nodeWebkitService, gettextCatalog, ionicToast, clipboard) { .directive('copyToClipboard', function(clipboardService, ionicToast, gettextCatalog) {
return { return {
restrict: 'A', restrict: 'A',
scope: { scope: {
copyToClipboard: '=copyToClipboard' copyToClipboard: '=copyToClipboard'
}, },
link: function(scope, elem, attrs, ctrl) { link: function(scope, elem, attrs, ctrl) {
var isCordova = platformInfo.isCordova;
var isChromeApp = platformInfo.isChromeApp;
var isNW = platformInfo.isNW;
elem.bind('mouseover', function() { elem.bind('mouseover', function() {
elem.css('cursor', 'pointer'); elem.css('cursor', 'pointer');
}); });
var msg = gettextCatalog.getString('Copied to clipboard');
elem.bind('click', function() { elem.bind('click', function() {
var data = scope.copyToClipboard; var data = scope.copyToClipboard;
if (!data) return; clipboardService.copyToClipboard(data);
if (isCordova) { var msg = gettextCatalog.getString('Copied to clipboard');
cordova.plugins.clipboard.copy(data); scope.$apply(function () {
} else if (isNW) {
nodeWebkitService.writeToClipboard(data);
} else if (clipboard.supported) {
clipboard.copyText(data);
} else {
// No supported
return;
}
scope.$apply(function() {
ionicToast.show(msg, 'bottom', false, 1000); ionicToast.show(msg, 'bottom', false, 1000);
}); });
}); });
} }
} }

View file

@ -0,0 +1,24 @@
'use strict';
angular.module('copayApp.services').factory('clipboardService', function ($http, $log, platformInfo, nodeWebkitService, gettextCatalog, ionicToast, clipboard) {
var root = {};
root.copyToClipboard = function (data) {
if (!data) return;
$log.debug("Copy '"+data+"' to clipboard");
if (platformInfo.isCordova) {
cordova.plugins.clipboard.copy(data);
} else if (platformInfo.isNW) {
nodeWebkitService.writeToClipboard(data);
} else if (clipboard.supported) {
clipboard.copyText(data);
} else {
// No supported
return;
}
};
return root;
});

View file

@ -46,11 +46,11 @@
<span class="ellipsis">{{addr}}</span> <span class="ellipsis">{{addr}}</span>
<ion-spinner ng-show="!addr" class="spinner-dark" icon="crescent"></ion-spinner> <ion-spinner ng-show="!addr" class="spinner-dark" icon="crescent"></ion-spinner>
</div> </div>
<div> </div>
<button ng-show="addr" class="button-address" ng-click="setAddress(true)"> <div>
<span translate>Generate new address</span> <button ng-show="addr" class="button-address" ng-click="setAddress(true)">
</button><br/> <span translate>Generate new address</span>
</div> </button><br/>
</div> </div>
</div> </div>
<!-- animation for payment received --> <!-- animation for payment received -->