From 862dfa72c9fd83e8244930cc15628441b0ed3a4f Mon Sep 17 00:00:00 2001 From: Yemel Jardi Date: Fri, 29 Aug 2014 10:50:52 -0300 Subject: [PATCH] Integrate the new model --- js/models/blockchain/Insight.js | 10 +++++----- js/services/controllerUtils.js | 12 +++--------- karma.conf.js | 1 + package.json | 3 ++- util/build.js | 6 ++++++ 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/js/models/blockchain/Insight.js b/js/models/blockchain/Insight.js index 16242ddbf..5776efcd1 100644 --- a/js/models/blockchain/Insight.js +++ b/js/models/blockchain/Insight.js @@ -100,14 +100,14 @@ Insight.prototype.getSocket = function(url, opts) { /** @private */ Insight.prototype.request = function(path, cb) { - preconditions.checkArgument(url).shouldBeFunction(cb); + preconditions.checkArgument(path).shouldBeFunction(cb); request(this.url + path, cb); } /** @private */ Insight.prototype.requestPost = function(path, data, cb) { - preconditions.checkArgument(url).checkArgument(data).shouldBeFunction(cb); - request.post(this.url, cb).form(data); + preconditions.checkArgument(path).checkArgument(data).shouldBeFunction(cb); + request({method: "POST", url: this.url + path, json: data}, cb); } Insight.prototype.destroy = function() { @@ -165,7 +165,7 @@ Insight.prototype.broadcast = function(rawtx, cb) { this.requestPost('/api/tx/send', {rawtx: rawtx}, function(err, res, body) { if (err || res.statusCode != 200) cb(err || res); - cb(null, JSON.parse(body).txid); + cb(null, body.txid); }); }; @@ -219,7 +219,7 @@ Insight.prototype.getUnspent = function(addresses, cb) { this.requestPost('/api/addrs/utxo', {addrs: addresses.join(',')}, function(err, res, body) { if (err || res.statusCode != 200) return cb(err || res); - cb(null, JSON.parse(body)); + cb(null, body); }); }; diff --git a/js/services/controllerUtils.js b/js/services/controllerUtils.js index f7054383d..8404d154d 100644 --- a/js/services/controllerUtils.js +++ b/js/services/controllerUtils.js @@ -120,7 +120,7 @@ angular.module('copayApp.services') }); w.on('ready', function(myPeerID) { $rootScope.wallet = w; - root.setConnectionListeners(); + root.setConnectionListeners($rootScope.wallet); if ($rootScope.pendingPayment) { $location.path('send'); @@ -196,13 +196,7 @@ angular.module('copayApp.services') $rootScope.updatingBalance = true; w.getBalance(function(err, balanceSat, balanceByAddrSat, safeBalanceSat) { - if (err) { - console.error('Error: ' + err.message); //TODO - root._setCommError(); - return null; - } else { - root._clearCommError(); - } + if (err) throw err; var satToUnit = 1 / config.unitToSatoshi; var COIN = bitcore.util.COIN; @@ -325,7 +319,7 @@ angular.module('copayApp.services') if (!$rootScope.wallet) return; root.updateAddressList(); - var currentAddrs = $rootScope.wallet.blockchain.getListeners(); + var currentAddrs = $rootScope.wallet.blockchain.subscribed; var allAddrs = $rootScope.addrInfos; var newAddrs = []; diff --git a/karma.conf.js b/karma.conf.js index 79314df62..69fb2faf4 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -54,6 +54,7 @@ module.exports = function(config) { 'test/lib/chai-should.js', 'test/lib/chai-expect.js', 'test/mocks/FakeWallet.js', + 'test/mocks/FakeBlockchainSocket.js', 'test/mocks/FakePayProServer.js', 'test/mocha.conf.js', diff --git a/package.json b/package.json index c67c404a8..383f137d1 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ }, "version": "0.4.7", "dependencies": { + "browser-request": "^0.3.2", "mocha": "^1.18.2", "mocha-lcov-reporter": "0.0.1", "optimist": "^0.6.1", @@ -71,7 +72,7 @@ "travis-cov": "0.2.5", "uglifyify": "1.2.3", "crypto-js": "3.1.2", - "shelljs":"0.3.0" + "shelljs": "0.3.0" }, "main": "app.js", "homepage": "https://github.com/bitpay/copay", diff --git a/util/build.js b/util/build.js index 2ea62d84c..bcd6f5ec1 100644 --- a/util/build.js +++ b/util/build.js @@ -40,6 +40,9 @@ var createBundle = function(opts) { b.require('bitcore/node_modules/browserify-buffertools/buffertools.js', { expose: 'buffertools' }); + b.require('browser-request', { + expose: 'request' + }); b.require('./copay', { expose: 'copay' @@ -88,6 +91,9 @@ var createBundle = function(opts) { b.require('./test/mocks/FakeBlockchain', { expose: './mocks/FakeBlockchain' }); + b.require('./test/mocks/FakeBlockchainSocket', { + expose: './mocks/FakeBlockchainSocket' + }); b.require('./test/mocks/FakeNetwork', { expose: './mocks/FakeNetwork' });