implement BITS + tests

This commit is contained in:
Matias Alejo Garcia 2014-06-12 17:42:26 -03:00
commit 727bf8524a
14 changed files with 213 additions and 79 deletions

View file

@ -20,15 +20,7 @@ angular.module('copayApp.controllers').controller('ImportController',
}
$rootScope.wallet = w;
controllerUtils.startNetwork($rootScope.wallet);
$rootScope.wallet.on('connectionError', function() {
var message = "Looks like you are already connected to this wallet, please logout from it and try importing it again.";
$rootScope.$flashMessage = { message: message, type: 'error'};
});
$rootScope.wallet.on('serverError', function() {
$rootScope.$flashMessage = { message: 'The PeerJS server is not responding, please try again', type: 'error'};
controllerUtils.onErrorDigest();
});
controllerUtils.startNetwork($rootScope.wallet, $scope);
});
};

View file

@ -1,29 +1,32 @@
'use strict';
var bitcore = require('bitcore');
angular.module('copayApp.controllers').controller('SendController',
function($scope, $rootScope, $window, $location, $timeout) {
$scope.title = 'Send';
$scope.loading = false;
$scope.defaultFee = bitcore.TransactionBuilder.FEE_PER_1000B_SAT / bitcore.util.BIT;
// TODO this shouldnt be on a particular controller.
// Detect mobile devices
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
@ -32,27 +35,29 @@ angular.module('copayApp.controllers').controller('SendController',
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
$scope.isMobile = isMobile.any();
$scope.unitIds = ['BTC','mBTC'];
$scope.selectedUnit = $scope.unitIds[0];
$scope.submitForm = function(form) {
if (form.$invalid) {
$rootScope.$flashMessage = { message: 'You can not send a proposal transaction. Please, try again', type: 'error'};
$rootScope.$flashMessage = {
message: 'You can not send a proposal transaction. Please, try again',
type: 'error'
};
return;
}
$scope.loading = true;
var address = form.address.$modelValue;
var amount = (form.amount.$modelValue * 100000000).toFixed(); // satoshi to string
var comment = form.comment.$modelValue;
var amount = (form.amount.$modelValue * 100) | 0;
var w = $rootScope.wallet;
w.createTx(address, amount, comment, function() {
$scope.loading = false;
$rootScope.$flashMessage = { message: 'The transaction proposal has been created', type: 'success'};
$rootScope.$flashMessage = {
message: 'The transaction proposal has been created',
type: 'success'
};
$rootScope.$digest();
});
@ -81,7 +86,11 @@ angular.module('copayApp.controllers').controller('SendController',
reader.onload = (function(theFile) {
return function(e) {
var mpImg = new MegaPixImage(file);
mpImg.render(canvas, { maxWidth: 200, maxHeight: 200, orientation: 6 });
mpImg.render(canvas, {
maxWidth: 200,
maxHeight: 200,
orientation: 6
});
$timeout(function() {
qrcode.width = canvas.width;
@ -107,7 +116,7 @@ angular.module('copayApp.controllers').controller('SendController',
try {
qrcode.decode();
} catch(e) {
} catch (e) {
//qrcodeError(e);
}
}
@ -168,7 +177,9 @@ angular.module('copayApp.controllers').controller('SendController',
canvas.height = 225;
context.clearRect(0, 0, 300, 225);
navigator.getUserMedia({video: true}, _successCallback, _videoError);
navigator.getUserMedia({
video: true
}, _successCallback, _videoError);
}
}, 500);
};

View file

@ -1,4 +1,5 @@
'use strict';
var bitcore = require('bitcore');
angular.module('copayApp.controllers').controller('TransactionsController',
function($scope, $rootScope, $timeout, controllerUtils) {
@ -10,8 +11,6 @@ angular.module('copayApp.controllers').controller('TransactionsController',
$scope.txpCurrentPage = 1;
$scope.txpItemsPerPage = 4;
var COIN = 100000000;
$scope.blockchain_txs = [];
$scope.update = function () {
@ -81,14 +80,14 @@ angular.module('copayApp.controllers').controller('TransactionsController',
tmp[addr].doubleSpentIndex = tmp[addr].doubleSpentIndex || items[i].doubleSpentIndex;
tmp[addr].unconfirmedInput += items[i].unconfirmedInput;
tmp[addr].dbError = tmp[addr].dbError || items[i].dbError;
tmp[addr].valueSat += Math.round(items[i].value * COIN);
tmp[addr].valueSat += (items[i].value * bitcore.util.COIN)|0;
tmp[addr].items.push(items[i]);
tmp[addr].notAddr = notAddr;
tmp[addr].count++;
}
angular.forEach(tmp, function(v) {
v.value = v.value || parseInt(v.valueSat) / COIN;
v.value = (v.valueSat|0) / bitcore.util.BIT;
ret.push(v);
});
return ret;
@ -150,6 +149,8 @@ angular.module('copayApp.controllers').controller('TransactionsController',
for (var i=0; i<txs.length;i++) {
txs[i].vinSimple = _aggregateItems(txs[i].vin);
txs[i].voutSimple = _aggregateItems(txs[i].vout);
txs[i].valueOut = ((txs[i].valueOut * bitcore.util.COIN)|0) / bitcore.util.BIT;
txs[i].fees = ((txs[i].fees * bitcore.util.COIN)|0) / bitcore.util.BIT;
$scope.blockchain_txs.push(txs[i]);
}
$scope.loading = false;