2014-10-31 11:49:52 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
2015-02-13 18:05:09 -03:00
|
|
|
angular.module('copayApp.controllers').controller('HomeWalletController', function($scope, $rootScope, $timeout, $filter, $modal, rateService, notification, txStatus, identityService, isCordova) {
|
2014-12-09 14:27:09 -03:00
|
|
|
|
2014-12-09 15:13:17 -03:00
|
|
|
$scope.openTxModal = function(tx) {
|
2014-12-09 14:27:09 -03:00
|
|
|
var ModalInstanceCtrl = function($scope, $modalInstance) {
|
2014-12-11 21:14:56 -03:00
|
|
|
var w = $rootScope.wallet;
|
2015-02-12 12:14:37 -03:00
|
|
|
$scope.error = null;
|
2014-12-09 15:13:17 -03:00
|
|
|
$scope.tx = tx;
|
2015-02-11 10:47:54 -03:00
|
|
|
$scope.registeredCopayerIds = w.getRegisteredCopayerIds();
|
2014-12-11 21:14:56 -03:00
|
|
|
$scope.loading = null;
|
|
|
|
|
|
2015-02-12 12:14:37 -03:00
|
|
|
$scope.getShortNetworkName = function() {
|
|
|
|
|
var w = $rootScope.wallet;
|
|
|
|
|
return w.getNetworkName().substring(0, 4);
|
|
|
|
|
};
|
|
|
|
|
|
2014-12-11 02:01:12 -03:00
|
|
|
$scope.sign = function(ntxid) {
|
2015-02-13 18:05:09 -03:00
|
|
|
if (isCordova) {
|
|
|
|
|
window.plugins.spinnerDialog.show(null, 'Signing transaction...', true);
|
|
|
|
|
}
|
2014-12-11 21:14:56 -03:00
|
|
|
$scope.loading = true;
|
2015-02-12 12:14:37 -03:00
|
|
|
$scope.error = null;
|
2014-12-11 21:14:56 -03:00
|
|
|
$timeout(function() {
|
|
|
|
|
w.signAndSend(ntxid, function(err, id, status) {
|
2015-02-13 18:05:09 -03:00
|
|
|
if (isCordova) {
|
|
|
|
|
window.plugins.spinnerDialog.hide();
|
|
|
|
|
}
|
2014-12-11 21:14:56 -03:00
|
|
|
$scope.loading = false;
|
2015-02-12 12:14:37 -03:00
|
|
|
if (err) {
|
|
|
|
|
$scope.error = 'Transaction could not send. Please try again.';
|
|
|
|
|
$scope.$digest();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$modalInstance.close(status);
|
|
|
|
|
}
|
2014-12-11 21:14:56 -03:00
|
|
|
});
|
|
|
|
|
}, 100);
|
2014-12-11 02:01:12 -03:00
|
|
|
};
|
2014-12-11 21:14:56 -03:00
|
|
|
|
2014-12-11 02:01:12 -03:00
|
|
|
$scope.reject = function(ntxid) {
|
2015-02-13 18:05:09 -03:00
|
|
|
if (isCordova) {
|
|
|
|
|
window.plugins.spinnerDialog.show(null, 'Rejecting transaction...', true);
|
|
|
|
|
}
|
2014-12-11 21:14:56 -03:00
|
|
|
$scope.loading = true;
|
2015-02-12 12:14:37 -03:00
|
|
|
$scope.error = null;
|
2014-12-11 21:14:56 -03:00
|
|
|
$timeout(function() {
|
|
|
|
|
w.reject(ntxid, function(err, status) {
|
2015-02-13 18:05:09 -03:00
|
|
|
if (isCordova) {
|
|
|
|
|
window.plugins.spinnerDialog.hide();
|
|
|
|
|
}
|
2014-12-11 21:14:56 -03:00
|
|
|
$scope.loading = false;
|
2015-02-12 12:14:37 -03:00
|
|
|
if (err) {
|
|
|
|
|
$scope.error = err;
|
|
|
|
|
$scope.$digest();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$modalInstance.close(status);
|
|
|
|
|
}
|
2014-12-11 21:14:56 -03:00
|
|
|
});
|
|
|
|
|
}, 100);
|
2014-12-09 14:27:09 -03:00
|
|
|
};
|
2014-12-11 21:14:56 -03:00
|
|
|
|
|
|
|
|
$scope.broadcast = function(ntxid) {
|
2015-02-13 18:05:09 -03:00
|
|
|
if (isCordova) {
|
|
|
|
|
window.plugins.spinnerDialog.show(null, 'Sending transaction...', true);
|
|
|
|
|
}
|
2014-12-11 21:14:56 -03:00
|
|
|
$scope.loading = true;
|
2015-02-12 12:14:37 -03:00
|
|
|
$scope.error = null;
|
2014-12-11 21:14:56 -03:00
|
|
|
$timeout(function() {
|
|
|
|
|
w.issueTx(ntxid, function(err, txid, status) {
|
2015-02-13 18:05:09 -03:00
|
|
|
if (isCordova) {
|
|
|
|
|
window.plugins.spinnerDialog.hide();
|
|
|
|
|
}
|
2014-12-11 21:14:56 -03:00
|
|
|
$scope.loading = false;
|
2015-02-12 12:14:37 -03:00
|
|
|
if (err) {
|
|
|
|
|
$scope.error = 'Transaction could not send. Please try again.';
|
|
|
|
|
$scope.$digest();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$modalInstance.close(status);
|
|
|
|
|
}
|
2014-12-11 21:14:56 -03:00
|
|
|
});
|
|
|
|
|
}, 100);
|
|
|
|
|
};
|
|
|
|
|
|
2014-12-09 14:27:09 -03:00
|
|
|
$scope.cancel = function() {
|
|
|
|
|
$modalInstance.dismiss('cancel');
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2014-12-11 21:14:56 -03:00
|
|
|
var modalInstance = $modal.open({
|
2014-12-09 15:13:17 -03:00
|
|
|
templateUrl: 'views/modals/txp-details.html',
|
2014-12-11 16:07:43 -03:00
|
|
|
windowClass: 'medium',
|
2014-12-09 14:27:09 -03:00
|
|
|
controller: ModalInstanceCtrl,
|
|
|
|
|
});
|
2014-12-11 21:14:56 -03:00
|
|
|
|
|
|
|
|
modalInstance.result.then(function(status) {
|
|
|
|
|
txStatus.notify(status);
|
|
|
|
|
});
|
|
|
|
|
|
2014-12-09 14:27:09 -03:00
|
|
|
};
|
2014-12-02 14:33:46 -03:00
|
|
|
});
|