63 lines
1.8 KiB
JavaScript
63 lines
1.8 KiB
JavaScript
'use strict';
|
|
|
|
angular.module('copayApp.controllers').controller('receiveController',
|
|
function($rootScope, $scope, $timeout, $modal, $log, isCordova, isMobile, profileService, storageService) {
|
|
var self = this;
|
|
var fc = profileService.focusedClient;
|
|
|
|
|
|
this.isCordova = isCordova;
|
|
self.addresses = [];
|
|
|
|
var newAddrListener = $rootScope.$on('Local/NeedNewAddress', function() {
|
|
self.getAddress();
|
|
});
|
|
$scope.$on('$destroy', newAddrListener);
|
|
|
|
this.newAddress = function() {
|
|
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() {
|
|
$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, null, null, null);
|
|
}
|
|
};
|
|
|
|
}
|
|
);
|