Merge pull request #1971 from cmgustavo/bug/transactions-02
Bug/transactions 02
This commit is contained in:
commit
b4050ccf41
8 changed files with 140 additions and 99 deletions
|
|
@ -1,7 +1,95 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('HomeWalletController', function($scope, $rootScope) {
|
||||
angular.module('copayApp.controllers').controller('HomeWalletController', function($scope, $rootScope, $timeout, $filter, rateService) {
|
||||
$scope.init = function() {
|
||||
$rootScope.title = 'Home';
|
||||
$rootScope.title = 'Home';
|
||||
|
||||
$scope.rateService = rateService;
|
||||
$scope.isRateAvailable = false;
|
||||
|
||||
var w = $rootScope.wallet;
|
||||
w.on('txProposalEvent', function() { _updateTxs()});
|
||||
$timeout(function() {
|
||||
_updateTxs();
|
||||
}, 1);
|
||||
|
||||
rateService.whenAvailable(function() {
|
||||
$scope.isRateAvailable = true;
|
||||
$scope.$digest();
|
||||
});
|
||||
};
|
||||
|
||||
// This is necesarry, since wallet can change in homeWallet, without running init() again.
|
||||
var removeWatch = $rootScope.$watch('wallet.id', function(newWallet, oldWallet) {
|
||||
if ($rootScope.wallet && $rootScope.wallet.isComplete() && newWallet !== oldWallet) {
|
||||
var w = $rootScope.wallet;
|
||||
$rootScope.pendingTxCount = 0;
|
||||
w.on('txProposalEvent', function() { _updateTxs()});
|
||||
_updateTxs();
|
||||
}
|
||||
});
|
||||
|
||||
$scope.$on("$destroy", function(){
|
||||
var w = $rootScope.wallet;
|
||||
removeWatch();
|
||||
w.removeListener('txProposalEvent', function() {_updateTxs()} );
|
||||
});
|
||||
|
||||
$scope.setAlternativeAmount = function(w, tx, cb) {
|
||||
rateService.whenAvailable(function() {
|
||||
_.each(tx.outs, function(out) {
|
||||
var valueSat = out.valueSat * w.settings.unitToSatoshi;
|
||||
out.alternativeAmount = $filter('noFractionNumber')(rateService.toFiat(valueSat, $scope.alternativeIsoCode), 2);
|
||||
out.alternativeIsoCode = $scope.alternativeIsoCode;
|
||||
});
|
||||
if (cb) return cb(tx);
|
||||
});
|
||||
};
|
||||
|
||||
var _updateTxs = _.throttle(function() {
|
||||
var w = $rootScope.wallet;
|
||||
if (!w) return;
|
||||
|
||||
$scope.alternativeIsoCode = w.settings.alternativeIsoCode;
|
||||
$scope.myId = w.getMyCopayerId();
|
||||
|
||||
var res = w.getPendingTxProposals();
|
||||
_.each(res.txs, function(tx) {
|
||||
$scope.setAlternativeAmount(w, tx);
|
||||
if (tx.merchant) {
|
||||
var url = tx.merchant.request_url;
|
||||
var domain = /^(?:https?)?:\/\/([^\/:]+).*$/.exec(url)[1];
|
||||
tx.merchant.domain = domain;
|
||||
}
|
||||
if (tx.outs) {
|
||||
_.each(tx.outs, function(out) {
|
||||
out.valueSat = out.value;
|
||||
out.value = $filter('noFractionNumber')(out.value);
|
||||
});
|
||||
}
|
||||
});
|
||||
$scope.txps = res.txs;
|
||||
console.log('[homeWallet.js:45]',$scope.txps); //TODO
|
||||
}, 100);
|
||||
|
||||
|
||||
|
||||
$scope.sign = function(ntxid) {
|
||||
var w = $rootScope.wallet;
|
||||
$scope.loading = true;
|
||||
$scope.error = $scope.success = null;
|
||||
w.signAndSend(ntxid, function(err, id, status) {
|
||||
$scope.loading = false;
|
||||
$scope.notifyStatus(status);
|
||||
_updateTxs();
|
||||
});
|
||||
};
|
||||
|
||||
$scope.reject = function(ntxid) {
|
||||
var w = $rootScope.wallet;
|
||||
w.reject(ntxid);
|
||||
notification.warning('Transaction rejected', 'You rejected the transaction successfully');
|
||||
_updateTxs();
|
||||
};
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
preconditions.checkState(w);
|
||||
preconditions.checkState(w.settings.unitToSatoshi);
|
||||
|
||||
$rootScope.title = 'Send';
|
||||
$rootScope.title = w.isShared() ? 'Create Transaction Proposal' : 'Send';
|
||||
$scope.loading = false;
|
||||
$scope.error = $scope.success = null;
|
||||
var satToUnit = 1 / w.settings.unitToSatoshi;
|
||||
|
|
@ -39,30 +39,7 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
});
|
||||
if (cb) return cb(tx);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
$scope.updateTxs = _.throttle(function() {
|
||||
var w = $rootScope.wallet;
|
||||
if (!w) return;
|
||||
|
||||
var res = w.getPendingTxProposals();
|
||||
_.each(res.txs, function(tx) {
|
||||
$scope.setAlternativeAmount(w, tx);
|
||||
if (tx.merchant) {
|
||||
var url = tx.merchant.request_url;
|
||||
var domain = /^(?:https?)?:\/\/([^\/:]+).*$/.exec(url)[1];
|
||||
tx.merchant.domain = domain;
|
||||
}
|
||||
if (tx.outs) {
|
||||
_.each(tx.outs, function(out) {
|
||||
out.valueSat = out.value;
|
||||
out.value = $filter('noFractionNumber')(out.value);
|
||||
});
|
||||
}
|
||||
});
|
||||
$scope.txps = res.txs;
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
/**
|
||||
* Setting the two related amounts as properties prevents an infinite
|
||||
|
|
@ -119,16 +96,8 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
|
||||
|
||||
$scope.init = function() {
|
||||
$rootScope.pendingTxCount = 0;
|
||||
$scope.updateTxs();
|
||||
var w = $rootScope.wallet;
|
||||
w.on('txProposalEvent', $scope.updateTxs);
|
||||
};
|
||||
|
||||
$scope.$on("$destroy", function(){
|
||||
var w = $rootScope.wallet;
|
||||
w.removeListener('txProposalEvent', $scope.updateTxs );
|
||||
});
|
||||
// Empty
|
||||
};
|
||||
|
||||
$scope.showAddressBook = function() {
|
||||
return w && _.keys(w.addressBook).length > 0;
|
||||
|
|
@ -155,7 +124,6 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
|
||||
$scope.error = message;
|
||||
$scope.loading = false;
|
||||
$scope.updateTxs();
|
||||
};
|
||||
|
||||
$scope.submitForm = function(form) {
|
||||
|
|
@ -201,7 +169,6 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
if (err) return $scope._showError(err);
|
||||
|
||||
$scope.notifyStatus(status);
|
||||
$scope.updateTxs();
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -422,25 +389,8 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
w.issueTx(ntxid, function(err, txid, status) {
|
||||
$scope.notifyStatus(status);
|
||||
if (cb) return cb();
|
||||
else $scope.updateTxs();
|
||||
});
|
||||
};
|
||||
|
||||
$scope.sign = function(ntxid) {
|
||||
$scope.loading = true;
|
||||
$scope.error = $scope.success = null;
|
||||
w.signAndSend(ntxid, function(err, id, status) {
|
||||
$scope.loading = false;
|
||||
$scope.notifyStatus(status);
|
||||
$scope.updateTxs();
|
||||
});
|
||||
};
|
||||
|
||||
$scope.reject = function(ntxid) {
|
||||
w.reject(ntxid);
|
||||
notification.warning('Transaction rejected', 'You rejected the transaction successfully');
|
||||
$scope.updateTxs();
|
||||
};
|
||||
};
|
||||
|
||||
$scope.clearMerchant = function(callback) {
|
||||
// TODO: Find a better way of detecting
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ describe("Unit: Controllers", function() {
|
|||
var w = {};
|
||||
w.id = 1234;
|
||||
w.isComplete = sinon.stub().returns(true);
|
||||
w.isShared = sinon.stub().returns(true);
|
||||
w.privateKey = {};
|
||||
w.settings = {
|
||||
unitToSatoshi: 100,
|
||||
|
|
@ -218,7 +219,7 @@ describe("Unit: Controllers", function() {
|
|||
});
|
||||
|
||||
it('should have a title', function() {
|
||||
expect(scope.title).equal('Send');
|
||||
expect(scope.title).equal('Create Transaction Proposal');
|
||||
});
|
||||
|
||||
it('should return true if wallet has addressBook', function() {
|
||||
|
|
@ -254,13 +255,10 @@ describe("Unit: Controllers", function() {
|
|||
sendForm.amount.$setViewValue(anAmount);
|
||||
sendForm.comment.$setViewValue(aComment);
|
||||
|
||||
scope.updateTxs = sinon.spy();
|
||||
|
||||
var w = scope.wallet;
|
||||
scope.submitForm(sendForm);
|
||||
sinon.assert.callCount(w.spend, 1);
|
||||
sinon.assert.callCount(w.broadcastTx, 0);
|
||||
sinon.assert.callCount(scope.updateTxs, 1);
|
||||
var spendArgs = w.spend.getCall(0).args[0];
|
||||
spendArgs.toAddress.should.equal(anAddr);
|
||||
spendArgs.amountSat.should.equal(anAmount * scope.wallet.settings.unitToSatoshi);
|
||||
|
|
|
|||
|
|
@ -16,16 +16,16 @@
|
|||
<div class="large-4 medium-6 small-9 columns">
|
||||
<div class="text-right">
|
||||
<span class="size-21">
|
||||
<strong>
|
||||
<span ng-if="!$root.updatingBalance">{{$root.wallet.balanceInfo.totalBalance || 0}}</span>
|
||||
<span ng-if="$root.updatingBalance"><i class="fi-bitcoin-circle icon-rotate spinner"></i></span>
|
||||
{{$root.wallet.settings.unitName}}
|
||||
</strong>
|
||||
<strong>
|
||||
<span ng-if="!$root.updatingBalance">{{$root.wallet.balanceInfo.totalBalance || 0}}</span>
|
||||
<span ng-if="$root.updatingBalance"><i class="fi-bitcoin-circle icon-rotate spinner"></i></span>
|
||||
{{$root.wallet.settings.unitName}}
|
||||
</strong>
|
||||
</span>
|
||||
<span class="size-14 db m5t text-gray">
|
||||
<span ng-if="!$root.wallet.balanceInfo.updatingBalance && $root.wallet.balanceInfo.alternativeBalanceAvailable">{{$root.wallet.balanceInfo.totalBalanceAlternative}} {{$root.wallet.balanceInfo.alternativeIsoCode}}</span>
|
||||
<span ng-if="!$root.wallet.balanceInfo.updatingBalance && !$root.wallet.balanceInfo.alternativeBalanceAvailable">N/A</span>
|
||||
<span ng-if="$root.wallet.balanceInfo.updatingBalance"><i class="fi-bitcoin-circle icon-rotate spinner"></i></span>
|
||||
<span ng-if="!$root.wallet.balanceInfo.updatingBalance && $root.wallet.balanceInfo.alternativeBalanceAvailable">{{$root.wallet.balanceInfo.totalBalanceAlternative}} {{$root.wallet.balanceInfo.alternativeIsoCode}}</span>
|
||||
<span ng-if="!$root.wallet.balanceInfo.updatingBalance && !$root.wallet.balanceInfo.alternativeBalanceAvailable">N/A</span>
|
||||
<span ng-if="$root.wallet.balanceInfo.updatingBalance"><i class="fi-bitcoin-circle icon-rotate spinner"></i></span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -35,23 +35,34 @@
|
|||
<div class="right size-10">
|
||||
<span ng-if="!$root.wallet.isShared()">Personal Wallet</span>
|
||||
<span ng-if="$root.wallet.isShared()">
|
||||
Multisignature wallet [{{$root.wallet.requiredCopayers}} of {{$root.wallet.totalCopayers}} ]
|
||||
</span>
|
||||
Multisignature wallet [{{$root.wallet.requiredCopayers}} of {{$root.wallet.totalCopayers}} ]
|
||||
</span>
|
||||
<span ng-if="$root.wallet.isTestnet()"> in TESTNET</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row" ng-if="$root.wallet.isShared()">
|
||||
<!-- List of copayers -->
|
||||
<div ng-show="$root.wallet.isShared() && txps.length != 0">
|
||||
<div class="row">
|
||||
<div class="large-12 columns">
|
||||
<div class="panel oh">
|
||||
<h2 class="line-b" translate>Copayers</h2>
|
||||
<div ng-include="'views/includes/copayer.html'"></div>
|
||||
</div>
|
||||
<h2 translate>Pending Transactions Proposals</h2>
|
||||
<div class="panel last-transactions pr"
|
||||
ng-repeat="tx in txps | paged"
|
||||
ng-include="'views/includes/transaction.html'"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row" ng-if="$root.wallet.isShared()">
|
||||
<!-- List of copayers -->
|
||||
<div class="large-12 columns">
|
||||
<div class="panel oh">
|
||||
<h2 class="line-b" translate>Copayers</h2>
|
||||
<div ng-include="'views/includes/copayer.html'"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<i class="size-36 {{item.icon}} db"></i>
|
||||
<div class="size-10 tu">
|
||||
{{item.title}}
|
||||
<span class="label alert round" ng-if="item.link=='send' && $root.pendingTxCount > 0">{{$root.pendingTxCount}}</span>
|
||||
<span class="label alert round" ng-if="item.link=='homeWallet' && $root.pendingTxCount > 0">{{$root.pendingTxCount}}</span>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@
|
|||
<div class="avatar-wallet">{{(item.name || item.id) | limitTo: 1}}</div>
|
||||
</div>
|
||||
<div class="col2">
|
||||
<a class="size-12 wallet-item" >
|
||||
<a href class="size-12 wallet-item">
|
||||
<div class="oh">
|
||||
<div class="right size-10 type-wallet">[ {{item.requiredCopayers}} of {{item.totalCopayers}} ]</div>
|
||||
<div class="ellipsis name-wallet">{{item.name || item.id}}</div>
|
||||
|
|
@ -80,7 +80,9 @@
|
|||
<a href="#!/{{item.link}}" ng-click="toggleCollapse()" class="db p20h">
|
||||
<i class="size-21 m20r {{item.icon}}"></i> {{item.title|translate}}
|
||||
<span class="right">
|
||||
<span class="label alert" ng-if="item.link=='send' && $root.pendingTxCount > 0">{{$root.pendingTxCount}}</span>
|
||||
<span class="label alert" ng-if="item.link=='homeWallet' && $root.pendingTxCount > 0">
|
||||
{{$root.pendingTxCount}}
|
||||
</span>
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
|
|
|
|||
|
|
@ -13,14 +13,16 @@
|
|||
|
||||
<div class="last-transactions-content">
|
||||
<div class="row" ng-repeat="out in tx.outs">
|
||||
<div class="large-3 medium-3 small-4 columns size-14">
|
||||
<div class="large-5 medium-5 small-6 columns size-14">
|
||||
<b>{{out.value}} {{$root.wallet.settings.unitName}}</b>
|
||||
<span class="alt-currency gray">
|
||||
<span ng-show="out.alternativeAmount" class="alt-currency gray">
|
||||
{{out.alternativeAmount}} {{out.alternativeIsoCode}}
|
||||
</span>
|
||||
</div>
|
||||
<div class="large-1 medium-1 small-1 columns fi-arrow-right"></div>
|
||||
<div class="large-8 medium-8 small-7 columns ellipsis size-12">
|
||||
<div class="large-2 medium-2 small-1 columns text-center">
|
||||
<i class="fi-arrow-right"></i>
|
||||
</div>
|
||||
<div class="large-5 medium-5 small-5 columns ellipsis size-12">
|
||||
<contact address="{{out.address}}" tooltip-popup-delay="500" tooltip tooltip-placement="right" />
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,23 +1,13 @@
|
|||
<div class="send" ng-controller="SendController" ng-init="init()">
|
||||
<div class="send" ng-controller="SendController" ng-init="init()">
|
||||
|
||||
<div class="row">
|
||||
<div class="large-12 medium-12 small-12 columns">
|
||||
<div ng-show="txps.length != 0" class="line-dashed-h m20b"></div>
|
||||
<h1 class="hide-for-large-up">{{$root.title}}</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row" ng-show="txps.length != 0">
|
||||
<div class="large-12 columns">
|
||||
<h2 translate>Pending Transactions Proposals</h2>
|
||||
<div class="panel last-transactions pr"
|
||||
ng-repeat="tx in txps | paged"
|
||||
ng-include="'views/includes/transaction.html'"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="large-12 columns">
|
||||
<h2 ng-show="txps.length != 0" translate>Create Transaction Proposal</h2>
|
||||
<form name="sendForm" ng-submit="submitForm(sendForm)" novalidate>
|
||||
<div class="panel">
|
||||
<p class="text-warning size-16"
|
||||
|
|
@ -140,7 +130,7 @@
|
|||
</p>
|
||||
|
||||
<p>
|
||||
<i>{{amount + defaultFee}} {{$root.wallet.settings.unitName}}</i>
|
||||
<i>{{amount}} {{$root.wallet.settings.unitName}}</i>
|
||||
<span class="text-gray" ng-if="isRateAvailable">
|
||||
{{ alternative }} {{ alternativeIsoCode }}
|
||||
</span>
|
||||
|
|
@ -167,7 +157,7 @@
|
|||
</label>
|
||||
<div class="input">
|
||||
<textarea id="comment" ng-disabled="loading"
|
||||
name="comment" placeholder="{{(wallet.isShared() ? 'Leave a private message to your copayers' : 'Add a private comment to identify the transaction') |translate}}" ng-model="commentText" ng-maxlength="100"></textarea>
|
||||
name="comment" placeholder="{{($root.wallet.isShared() ? 'Leave a private message to your copayers' : 'Add a private comment to identify the transaction')}}" ng-model="commentText" ng-maxlength="100"></textarea>
|
||||
<i class="icon-compose"></i>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -195,7 +185,7 @@
|
|||
<i class="fi-bitcoin-circle"></i>
|
||||
1 BTC = {{$root.wallet.balanceInfo.alternativeConversionRate}} {{alternativeIsoCode}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="line-dashed-h m20b"></div>
|
||||
<div class="row">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue