2014-03-26 05:18:42 -07:00
|
|
|
'use strict';
|
|
|
|
|
2014-03-28 11:08:14 -07:00
|
|
|
angular.module('copay.send').controller('SendController',
|
2014-04-17 09:25:36 -07:00
|
|
|
function($scope, $rootScope, $location, Socket, controllerUtils) {
|
2014-03-26 05:18:42 -07:00
|
|
|
$scope.title = 'Send';
|
2014-03-31 08:48:35 -07:00
|
|
|
|
2014-04-19 00:55:32 -07:00
|
|
|
$scope.unitIds = ['BTC','mBTC'];
|
|
|
|
$scope.selectedUnit = $scope.unitIds[0];
|
|
|
|
|
2014-04-17 09:25:36 -07:00
|
|
|
if (!$rootScope.wallet || !$rootScope.wallet.id) {
|
2014-03-31 08:48:35 -07:00
|
|
|
$location.path('signin');
|
|
|
|
}
|
2014-04-17 09:25:36 -07:00
|
|
|
else {
|
2014-04-18 09:20:35 -07:00
|
|
|
controllerUtils.handleTransactionByAddress($scope);
|
2014-04-17 09:25:36 -07:00
|
|
|
}
|
2014-04-11 09:26:36 -07:00
|
|
|
|
2014-04-19 00:55:32 -07:00
|
|
|
$scope.submitForm = function(form) {
|
|
|
|
if (form.$invalid) {
|
|
|
|
$rootScope.flashMessage = { message: 'You can not send a proposal transaction. Please, try again', type: 'error'};
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var address = form.address.$modelValue;
|
|
|
|
var amount = (form.amount.$modelValue * 100000000).toString(); // satoshi to string
|
|
|
|
|
|
|
|
var w = $rootScope.wallet;
|
|
|
|
w.createTx( address, amount,function() {
|
|
|
|
$rootScope.$digest();
|
|
|
|
});
|
|
|
|
|
|
|
|
// reset fields
|
|
|
|
$scope.address = null;
|
|
|
|
$scope.amount = null;
|
|
|
|
form.address.$pristine = true;
|
|
|
|
form.amount.$pristine = true;
|
|
|
|
|
|
|
|
// TODO: check if createTx has an error.
|
2014-04-20 18:05:25 -07:00
|
|
|
$rootScope.flashMessage = { message: 'Your transaction proposal has been sent successfully', type: 'success'};
|
2014-04-19 00:55:32 -07:00
|
|
|
};
|
|
|
|
|
2014-03-26 05:18:42 -07:00
|
|
|
});
|