diff --git a/src/js/controllers/tab-receive.js b/src/js/controllers/tab-receive.js index cfdcc5de9..4bea0add2 100644 --- a/src/js/controllers/tab-receive.js +++ b/src/js/controllers/tab-receive.js @@ -1,6 +1,6 @@ '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 = []; $scope.bchAddressType = { type: 'cashaddr' }; @@ -74,6 +74,12 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi 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 var msg = JSON.stringify(paymentSubscriptionObj); currentAddressSocket.onopen = function (event) { diff --git a/src/js/directives/copyToClipboard.js b/src/js/directives/copyToClipboard.js index 5de40f23e..c81e0bd60 100644 --- a/src/js/directives/copyToClipboard.js +++ b/src/js/directives/copyToClipboard.js @@ -1,38 +1,26 @@ 'use strict'; angular.module('copayApp.directives') - .directive('copyToClipboard', function(platformInfo, nodeWebkitService, gettextCatalog, ionicToast, clipboard) { + .directive('copyToClipboard', function(clipboardService, ionicToast, gettextCatalog) { return { restrict: 'A', scope: { copyToClipboard: '=copyToClipboard' }, link: function(scope, elem, attrs, ctrl) { - var isCordova = platformInfo.isCordova; - var isChromeApp = platformInfo.isChromeApp; - var isNW = platformInfo.isNW; elem.bind('mouseover', function() { elem.css('cursor', 'pointer'); }); - var msg = gettextCatalog.getString('Copied to clipboard'); elem.bind('click', function() { var data = scope.copyToClipboard; - if (!data) return; + clipboardService.copyToClipboard(data); - if (isCordova) { - cordova.plugins.clipboard.copy(data); - } else if (isNW) { - nodeWebkitService.writeToClipboard(data); - } else if (clipboard.supported) { - clipboard.copyText(data); - } else { - // No supported - return; - } - scope.$apply(function() { + var msg = gettextCatalog.getString('Copied to clipboard'); + scope.$apply(function () { ionicToast.show(msg, 'bottom', false, 1000); }); + }); } } diff --git a/src/js/services/clipboardService.js b/src/js/services/clipboardService.js new file mode 100644 index 000000000..e2e0e5fb3 --- /dev/null +++ b/src/js/services/clipboardService.js @@ -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; +}); \ No newline at end of file diff --git a/www/views/tab-receive.html b/www/views/tab-receive.html index 1ddc65e0a..824ad0d0a 100644 --- a/www/views/tab-receive.html +++ b/www/views/tab-receive.html @@ -46,11 +46,11 @@ {{addr}} -
-
-
+ +
+