mirror of https://github.com/BTCPrivate/copay.git
Merge pull request #545 from cmgustavo/bug/tx-list-insight
Bug/tx list insight
This commit is contained in:
commit
cf5e61cfcb
|
@ -309,12 +309,7 @@ hr { margin: 2.25rem 0;}
|
|||
|
||||
.tx-copayers {
|
||||
overflow: hidden;
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
.tx-copayers {
|
||||
overflow: hidden;
|
||||
padding: 0.5rem;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.box-copayers {
|
||||
|
|
61
index.html
61
index.html
|
@ -520,14 +520,16 @@
|
|||
</div>
|
||||
<div class="large-12 columns">
|
||||
<h4>Last transactions</h4>
|
||||
<a class="size-12" ng-click="toogleLast()" ng-disabled="loading" loading="Updating" ng-hide="lastShowed && !loading">Show</a>
|
||||
<a class="size-12" ng-click="toogleLast()" ng-disabled="loading" loading="Updating" ng-show="lastShowed && !loading">Hide</a>
|
||||
<div class="m10b size-12">
|
||||
<a class="text-gray active" ng-click="toogleLast()" ng-disabled="loading" loading="Loading" ng-hide="lastShowed && !loading">[ Show ]</a>
|
||||
<a class="text-gray" ng-click="toogleLast()" ng-disabled="loading" loading="Loading" ng-show="lastShowed && !loading">[ Hide ]</a>
|
||||
</div>
|
||||
<div class="btransactions" ng-if="lastShowed">
|
||||
<div ng-if="!blockchain_txs[0].txid && !loading">
|
||||
No transactions yet.
|
||||
</div>
|
||||
<div class="panel radius" ng-repeat="btx in blockchain_txs | orderBy: 'firstSeenTs':true">
|
||||
<div class="m15">
|
||||
<div class="m10 size-12">
|
||||
<div class="row">
|
||||
<div class="large-8 columns">
|
||||
<a class="ellipsis" href="http://{{getShortNetworkName()}}.insight.is/tx/{{btx.txid}}" target="blank">
|
||||
|
@ -535,36 +537,37 @@
|
|||
</a>
|
||||
</div>
|
||||
<div class="large-4 columns text-right">
|
||||
{{btx.firstSeenTs * 1000 | amCalendar}} </h6>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tx-copayers">
|
||||
<div class="large-5 small-5 columns">
|
||||
<div ng-repeat="vin in btx.vin track by $index | groupByAddress">
|
||||
<p class="small-8 ellipsis left text-gray size-12"> {{vin.addr}} </p>
|
||||
<small class="small-4 right">{{vin.value}}</small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="large-1 small-1 columns text-center">
|
||||
<i class="fi-arrow-right"></i>
|
||||
</div>
|
||||
<div class="large-6 small-6 columns">
|
||||
<div ng-repeat="vout in btx.vout">
|
||||
<div class="row">
|
||||
<div class="large-10 small-8 columns">
|
||||
<div ng-repeat="addr in vout.scriptPubKey.addresses">
|
||||
<p class="ellipsis text-gray size-12"> {{addr}} </p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="large-2 small-4 columns">
|
||||
<small>{{vout.value}}</small>
|
||||
</div>
|
||||
<div data-ng-show="btx.firstSeenTs">
|
||||
first seen at
|
||||
<time>{{btx.firstSeenTs * 1000 | amCalendar}}</time>
|
||||
</div>
|
||||
<div data-ng-show="btx.time && !btx.firstSeenTs">
|
||||
mined at
|
||||
<time>{{btx.time * 1000 | amCalendar}}</time>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="m15 size-12 text-gray">
|
||||
<div class="tx-copayers">
|
||||
<div class="row">
|
||||
<div class="large-5 medium-5 small-5 columns">
|
||||
<div ng-repeat="vin in btx.vinSimple">
|
||||
<small class="right m5t">{{vin.value}}</small>
|
||||
<p class="ellipsis text-gray size-12"> {{vin.addr}} </p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="large-1 medium-1 small-1 columns text-center">
|
||||
<i class="fi-arrow-right"></i>
|
||||
</div>
|
||||
<div class="large-6 medium-6 small-6 columns">
|
||||
<div ng-repeat="vout in btx.voutSimple">
|
||||
<small class="right m5t">{{vout.value}}</small>
|
||||
<p class="ellipsis text-gray size-12"> {{vout.addr}} </p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="m10 size-12 text-gray">
|
||||
<div class="row">
|
||||
<div class="large-4 medium-4 small-4 columns">Fees: {{btx.fees}}</div>
|
||||
<div class="large-4 medium-4 small-4 columns text-center">Confirmations: {{btx.confirmations || 0}}</div>
|
||||
|
|
|
@ -10,6 +10,9 @@ angular.module('copayApp.controllers').controller('TransactionsController',
|
|||
|
||||
$scope.txpCurrentPage = 1;
|
||||
$scope.txpItemsPerPage = 4;
|
||||
|
||||
var COIN = 100000000;
|
||||
$scope.blockchain_txs = [];
|
||||
|
||||
$scope.update = function () {
|
||||
$scope.loading = false;
|
||||
|
@ -30,22 +33,71 @@ angular.module('copayApp.controllers').controller('TransactionsController',
|
|||
}, 10);
|
||||
};
|
||||
|
||||
var _aggregateItems = function(items) {
|
||||
if (!items) return [];
|
||||
|
||||
var l = items.length;
|
||||
|
||||
var ret = [];
|
||||
var tmp = {};
|
||||
var u = 0;
|
||||
|
||||
for(var i=0; i < l; i++) {
|
||||
|
||||
var notAddr = false;
|
||||
// non standard input
|
||||
if (items[i].scriptSig && !items[i].addr) {
|
||||
items[i].addr = 'Unparsed address [' + u++ + ']';
|
||||
items[i].notAddr = true;
|
||||
notAddr = true;
|
||||
}
|
||||
|
||||
// non standard output
|
||||
if (items[i].scriptPubKey && !items[i].scriptPubKey.addresses) {
|
||||
items[i].scriptPubKey.addresses = ['Unparsed address [' + u++ + ']'];
|
||||
items[i].notAddr = true;
|
||||
notAddr = true;
|
||||
}
|
||||
|
||||
// multiple addr at output
|
||||
if (items[i].scriptPubKey && items[i].scriptPubKey.addresses.length > 1) {
|
||||
items[i].addr = items[i].scriptPubKey.addresses.join(',');
|
||||
ret.push(items[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
var addr = items[i].addr || (items[i].scriptPubKey && items[i].scriptPubKey.addresses[0]);
|
||||
|
||||
if (!tmp[addr]) {
|
||||
tmp[addr] = {};
|
||||
tmp[addr].valueSat = 0;
|
||||
tmp[addr].count = 0;
|
||||
tmp[addr].addr = addr;
|
||||
tmp[addr].items = [];
|
||||
}
|
||||
tmp[addr].isSpent = items[i].spentTxId;
|
||||
|
||||
tmp[addr].doubleSpentTxID = tmp[addr].doubleSpentTxID || items[i].doubleSpentTxID;
|
||||
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].items.push(items[i]);
|
||||
tmp[addr].notAddr = notAddr;
|
||||
tmp[addr].count++;
|
||||
}
|
||||
|
||||
angular.forEach(tmp, function(v) {
|
||||
v.value = v.value || parseInt(v.valueSat) / COIN;
|
||||
ret.push(v);
|
||||
});
|
||||
return ret;
|
||||
};
|
||||
|
||||
$scope.toogleLast = function () {
|
||||
$scope.loading = true;
|
||||
$scope.lastShowed = !$scope.lastShowed;
|
||||
if ($scope.lastShowed) {
|
||||
$scope.getTransactions(function(txs){
|
||||
$timeout(function() {
|
||||
$scope.loading = false;
|
||||
$scope.blockchain_txs = txs;
|
||||
$scope.$digest();
|
||||
}, 10);
|
||||
});
|
||||
} else {
|
||||
$timeout(function(){
|
||||
$scope.loading = false;
|
||||
$rootScope.$digest();
|
||||
}, 10);
|
||||
$scope.getTransactions();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -86,15 +138,31 @@ angular.module('copayApp.controllers').controller('TransactionsController',
|
|||
});
|
||||
};
|
||||
|
||||
$scope.getTransactions = function(cb) {
|
||||
var w =$rootScope.wallet;
|
||||
$scope.getTransactions = function() {
|
||||
var w = $rootScope.wallet;
|
||||
$scope.loading = true;
|
||||
if (w) {
|
||||
var addresses = w.getAddressesStr();
|
||||
if (addresses.length > 0) {
|
||||
return w.blockchain.getTransactions(addresses, cb);
|
||||
$scope.blockchain_txs = [];
|
||||
w.blockchain.getTransactions(addresses, function(txs) {
|
||||
$timeout(function() {
|
||||
for (var i=0; i<txs.length;i++) {
|
||||
txs[i].vinSimple = _aggregateItems(txs[i].vin);
|
||||
txs[i].voutSimple = _aggregateItems(txs[i].vout);
|
||||
$scope.blockchain_txs.push(txs[i]);
|
||||
}
|
||||
$scope.loading = false;
|
||||
}, 10);
|
||||
});
|
||||
}
|
||||
else {
|
||||
$timeout(function() {
|
||||
$scope.loading = false;
|
||||
$scope.lastShowed = false;
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
return cb();
|
||||
};
|
||||
|
||||
$scope.getShortNetworkName = function() {
|
||||
|
|
|
@ -6,23 +6,6 @@ angular.module('copayApp.filters', [])
|
|||
return amMoment.preprocessDate(input).fromNow();
|
||||
};
|
||||
}])
|
||||
.filter('groupByAddress', function() {
|
||||
return function(inputs) {
|
||||
function reduce(dic, input) {
|
||||
if(!dic[input.addr]) dic[input.addr] = 0;
|
||||
dic[input.addr] += input.value;
|
||||
return dic;
|
||||
}
|
||||
|
||||
var dic;
|
||||
if (inputs) {
|
||||
dic = inputs.reduce(reduce, {});
|
||||
return Object.keys(dic).map(function(key) {
|
||||
return { addr: key, value: dic[key] };
|
||||
});
|
||||
}
|
||||
};
|
||||
})
|
||||
.filter('paged', function() {
|
||||
return function(elements) {
|
||||
if (elements) {
|
||||
|
|
|
@ -3,59 +3,49 @@
|
|||
//
|
||||
describe("Unit: Testing Controllers", function() {
|
||||
|
||||
beforeEach(module('notifications'));
|
||||
beforeEach(module('copayApp.services'));
|
||||
beforeEach(module('copayApp.controllers'));
|
||||
var scope;
|
||||
|
||||
var scope, addressCtrl;
|
||||
//
|
||||
beforeEach(module('notifications'));
|
||||
beforeEach(module('copayApp.services'));
|
||||
beforeEach(module('copayApp.controllers'));
|
||||
|
||||
describe('Address Controller', function() {
|
||||
var addressCtrl;
|
||||
beforeEach(inject(function($controller, $rootScope) {
|
||||
scope = $rootScope.$new();
|
||||
addressCtrl = $controller('AddressesController', {
|
||||
$scope: scope,
|
||||
});
|
||||
}));
|
||||
|
||||
|
||||
it('should have a AddressesController controller', function() {
|
||||
expect(scope.loading).equal(false);
|
||||
});
|
||||
|
||||
it('should have a AddressesController controller', function() {
|
||||
expect(scope.loading).equal(false);
|
||||
});
|
||||
it('selectedAddr should modify scope', function() {
|
||||
expect(scope.selectedAddress).equal(undefined);
|
||||
scope.selectAddress('hola');
|
||||
expect(scope.selectedAddr).equal('hola');
|
||||
});
|
||||
|
||||
it('selectedAddr should modify scope', function() {
|
||||
expect(scope.selectedAddress).equal(undefined);
|
||||
scope.selectAddress('hola');
|
||||
expect(scope.selectedAddr).equal('hola');
|
||||
});
|
||||
});
|
||||
|
||||
//
|
||||
// it('should have a BackupController controller', function() {
|
||||
// expect(copayApp.Backupcontroller).not.to.equal(null);
|
||||
// });
|
||||
//
|
||||
// it('should have a HeaderController controller', function() {
|
||||
// expect(copayApp.HeaderController).not.to.equal(null);
|
||||
// });
|
||||
//
|
||||
// it('should have a SendController controller', function() {
|
||||
// expect(copayApp.SendController).not.to.equal(null);
|
||||
// });
|
||||
//
|
||||
// it('should have a SetupController controller', function() {
|
||||
// expect(copayApp.SetupController).not.to.equal(null);
|
||||
// });
|
||||
//
|
||||
// it('should have a SigninController controller', function() {
|
||||
// expect(copayApp.SigninController).not.to.equal(null);
|
||||
// console.log('[controllersSpec.js.30:copayApp:]',copayApp); //TODO
|
||||
// });
|
||||
//
|
||||
// it('should have a TransactionsController controller', function() {
|
||||
// expect(copayApp.TransactionsController).not.to.equal(null);
|
||||
// });
|
||||
//
|
||||
// beforeEach(angular.mock.module('copay.walletFactory'));
|
||||
// it('should display a link to create a new wallet if no wallets in localStorage', inject(function(walletFactory) {
|
||||
// expect(walletFactory.storage.getWalletIds()).to.be.empty;
|
||||
// }));
|
||||
describe('Transactions Controller', function() {
|
||||
var transactionCtrl;
|
||||
beforeEach(inject(function($controller, $rootScope) {
|
||||
scope = $rootScope.$new();
|
||||
transactionsCtrl = $controller('TransactionsController', {
|
||||
$scope: scope,
|
||||
});
|
||||
}));
|
||||
|
||||
it('should have a TransactionController controller', function() {
|
||||
expect(scope.loading).equal(false);
|
||||
});
|
||||
|
||||
it('should return an empty array of tx from insight', function() {
|
||||
scope.getTransactions();
|
||||
expect(scope.blockchain_txs).to.be.empty;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue