'use strict'; angular.module('copayApp.controllers').controller('receiveController', function($rootScope, $scope, $timeout, $modal, $log, isCordova, isMobile, profileService, storageService) { var self = this; this.isCordova = isCordova; self.addresses = []; var newAddrListener = $rootScope.$on('Local/NeedNewAddress', function() { self.getAddress(); }); $scope.$on('$destroy', newAddrListener); this.newAddress = function() { var fc = profileService.focusedClient; self.generatingAddress = true; self.error = null; fc.createAddress(function(err, addr) { self.generatingAddress = false; if (err) { $log.debug('Creating address ERROR:', err); $scope.$emit('Local/ClientError', err); self.error='Could not generate address'; } else { self.addr = addr.address; storageService.storeLastAddress(fc.credentials.walletId, addr.address, function() {}); } $scope.$digest(); }); }; this.getAddress = function() { var fc = profileService.focusedClient; $timeout(function() { storageService.getLastAddress(fc.credentials.walletId, function(err, addr) { if (addr) { self.addr = addr; } else { self.newAddress(); } }); }); }; this.copyAddress = function(addr) { if (isCordova) { window.cordova.plugins.clipboard.copy('bitcoin:' + addr); window.plugins.toast.showShortCenter('Copied to clipboard'); } }; this.shareAddress = function(addr) { if (isCordova) { if (isMobile.Android() || isMobile.Windows()) { window.ignoreMobilePause = true; } window.plugins.socialsharing.share('bitcoin:' + addr, 'Here is my bitcoin address', null, null); } }; } );