From 727bf8524aaf0bfdda8f3c130d9e1895c591ca5d Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Thu, 12 Jun 2014 17:42:26 -0300 Subject: [PATCH] implement BITS + tests --- css/main.css | 8 ++++ index.html | 51 +++++++++++---------- js/controllers/import.js | 10 +---- js/controllers/send.js | 43 +++++++++++------- js/controllers/transactions.js | 9 ++-- js/models/core/Wallet.js | 11 ++--- js/services/controllerUtils.js | 26 ++++++----- karma.conf.js | 2 +- test/index.html | 2 +- test/mocks/FakeBlockchain.js | 2 +- test/mocks/FakeWallet.js | 34 ++++++++++++++ test/test.Wallet.js | 56 ++++++++++++++++++++++++ test/unit/controllers/controllersSpec.js | 1 + test/unit/services/servicesSpec.js | 45 +++++++++++++------ 14 files changed, 217 insertions(+), 83 deletions(-) create mode 100644 test/mocks/FakeWallet.js diff --git a/css/main.css b/css/main.css index f2ff8044c..fb69c1d96 100644 --- a/css/main.css +++ b/css/main.css @@ -219,6 +219,14 @@ small.has-error { font-weight: bold; } + +.totalAmount { + font-weight: bold; + line-height: 120%; + margin-top:2px; +} + + .small { font-size: 60%; line-height: inherit; diff --git a/index.html b/index.html index aeb16d94b..5345fdf3e 100644 --- a/index.html +++ b/index.html @@ -31,21 +31,19 @@ ng-click="signout()">
- Balance: + Balance
- {{totalBalance || 0}} - + {{totalBalance || 0 |number}} bits
- Available to Spend: + Available to Spend
- {{availableBalance || 0}} - + {{availableBalance || 0|number}} bits
@@ -383,13 +381,11 @@ - {{$root.balanceByAddr[addr.address] || 0}} - + {{$root.balanceByAddr[addr.address] || 0|number}} bits - {{addr.balance || 0}} - + {{addr.balance || 0|number}} bits @@ -407,14 +403,12 @@ - {{balanceByAddr[selectedAddr.address] || 0}} - + {{balanceByAddr[selectedAddr.address] || 0 | number}} {{selectedAddr.address}}
- {{selectedAddr.balance || 0}} - + {{selectedAddr.balance || 0|number}} bits

@@ -445,7 +439,7 @@
-
{{out.value}}
+
{{out.value | number}} bits
{{out.address}}
@@ -527,7 +521,7 @@

{{tx.missingSignatures}} signatures missing

- Fee: {{tx.fee}} + Fee: {{tx.fee|number}} bits Proposal ID: {{tx.ntxid}}
@@ -571,7 +565,7 @@
- {{vin.value}} + {{vin.value| number}} bits

{{vin.addr}}

@@ -580,7 +574,7 @@
- {{vout.value}} + {{vout.value| number}} bits

{{vout.addr}}

@@ -588,9 +582,9 @@
-
Fees: {{btx.fees}}
+
Fees: {{btx.fees | number}} bits
Confirmations: {{btx.confirmations || 0}}
-
Total: {{btx.valueOut}}
+
Total: {{btx.valueOut| number}} bits
@@ -661,13 +655,26 @@
+ min="0.0001" max="10000000" enough-amount required + autocomplete="off" + >
- BTC + bits
+
+ + Total amount for this transaction: + +
+ {{amount + defaultFee |number}} bits +
+ + Including fee of {{defaultFee|number}} bits + +
diff --git a/js/controllers/import.js b/js/controllers/import.js index eb4c9b8f6..639f6a4a1 100644 --- a/js/controllers/import.js +++ b/js/controllers/import.js @@ -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); }); }; diff --git a/js/controllers/send.js b/js/controllers/send.js index 0e72e3e5e..74524a9da 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -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); }; diff --git a/js/controllers/transactions.js b/js/controllers/transactions.js index 744e64aaf..cd318ff4a 100644 --- a/js/controllers/transactions.js +++ b/js/controllers/transactions.js @@ -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 - @@ -26,6 +25,7 @@ +