2016-09-12 11:57:20 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
2018-07-16 15:52:33 +09:00
|
|
|
angular.module('copayApp.controllers').controller('addressbookAddController', function($scope, $state, $stateParams, $timeout, $ionicHistory, gettextCatalog, addressbookService, popupService, configService, bitcoinCashJsService, platformInfo) {
|
2017-11-02 15:40:21 +09:00
|
|
|
|
|
|
|
|
var config = configService.getSync();
|
|
|
|
|
var defaults = configService.getDefaults();
|
|
|
|
|
|
|
|
|
|
$scope.bitcoinAlias = (config.bitcoinAlias || defaults.bitcoinAlias).toUpperCase();
|
|
|
|
|
$scope.bitcoinCashAlias = (config.bitcoinCashAlias || defaults.bitcoinCashAlias).toUpperCase();
|
2016-09-21 15:13:22 -03:00
|
|
|
|
|
|
|
|
$scope.fromSendTab = $stateParams.fromSendTab;
|
2016-09-12 11:57:20 -03:00
|
|
|
|
|
|
|
|
$scope.addressbookEntry = {
|
2016-09-21 15:13:22 -03:00
|
|
|
'address': $stateParams.addressbookEntry || '',
|
2016-09-12 11:57:20 -03:00
|
|
|
'name': '',
|
2017-11-02 15:40:21 +09:00
|
|
|
'email': '',
|
2018-01-11 19:07:12 +09:00
|
|
|
'coin': 'bch'
|
2016-09-12 11:57:20 -03:00
|
|
|
};
|
|
|
|
|
|
2016-12-29 14:37:31 -03:00
|
|
|
$scope.onQrCodeScannedAddressBook = function(data, addressbookForm) {
|
2016-09-12 11:57:20 -03:00
|
|
|
$timeout(function() {
|
|
|
|
|
var form = addressbookForm;
|
|
|
|
|
if (data && form) {
|
2017-09-09 19:23:46 -03:00
|
|
|
data = data.replace(/^bitcoin(cash)?:/, '');
|
2016-09-12 11:57:20 -03:00
|
|
|
form.address.$setViewValue(data);
|
|
|
|
|
form.address.$isValid = true;
|
|
|
|
|
form.address.$render();
|
|
|
|
|
}
|
|
|
|
|
$scope.$digest();
|
|
|
|
|
}, 100);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.add = function(addressbook) {
|
2018-01-11 19:07:12 +09:00
|
|
|
if ($scope.addressbookEntry.coin == 'bch') {
|
|
|
|
|
var translated = bitcoinCashJsService.readAddress(addressbook.address);
|
|
|
|
|
addressbook.address = translated.legacy;
|
|
|
|
|
}
|
2018-07-13 17:19:31 +09:00
|
|
|
|
|
|
|
|
var channel = "firebase";
|
|
|
|
|
if (platformInfo.isNW) {
|
|
|
|
|
channel = "ga";
|
|
|
|
|
}
|
|
|
|
|
var log = new window.BitAnalytics.LogEvent("contact_created", [{
|
|
|
|
|
"coin": $scope.addressbookEntry.coin
|
|
|
|
|
}], [channel]);
|
|
|
|
|
window.BitAnalytics.LogEventHandlers.postEvent(log);
|
|
|
|
|
|
2016-09-12 11:57:20 -03:00
|
|
|
$timeout(function() {
|
|
|
|
|
addressbookService.add(addressbook, function(err, ab) {
|
|
|
|
|
if (err) {
|
2016-10-26 17:10:21 -03:00
|
|
|
popupService.showAlert(gettextCatalog.getString('Error'), err);
|
2016-09-12 11:57:20 -03:00
|
|
|
return;
|
|
|
|
|
}
|
2016-09-21 15:13:22 -03:00
|
|
|
if ($scope.fromSendTab) $scope.goHome();
|
2016-09-23 17:10:34 -03:00
|
|
|
else $ionicHistory.goBack();
|
2016-09-12 11:57:20 -03:00
|
|
|
});
|
|
|
|
|
}, 100);
|
|
|
|
|
};
|
|
|
|
|
|
2016-09-21 15:13:22 -03:00
|
|
|
$scope.goHome = function() {
|
2016-09-23 12:42:33 -03:00
|
|
|
$ionicHistory.removeBackView();
|
2016-09-21 15:13:22 -03:00
|
|
|
$state.go('tabs.home');
|
|
|
|
|
};
|
|
|
|
|
|
2016-09-12 11:57:20 -03:00
|
|
|
});
|