copay/js/controllers/homeWallet.js

104 lines
3.0 KiB
JavaScript
Raw Normal View History

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