mirror of https://github.com/BTCPrivate/copay.git
Review copay features for 1-of-1
This commit is contained in:
parent
53e0371b7f
commit
7d8d89ab38
11
index.html
11
index.html
|
@ -451,7 +451,7 @@
|
|||
<script type="text/ng-template" id="transactions.html">
|
||||
<div class="transactions" data-ng-controller="TransactionsController">
|
||||
<div class="row" ng-show='$root.wallet.publicKeyRing.isComplete()'>
|
||||
<div class="large-12 columns">
|
||||
<div class="large-12 columns" ng-show="wallet.totalCopayers > 1">
|
||||
<h4> Transaction proposals <small>({{txs.length}})</small></h4>
|
||||
|
||||
<ul class="inline-list">
|
||||
|
@ -558,15 +558,18 @@
|
|||
</div>
|
||||
<div class="large-12 columns">
|
||||
<h4>Last transactions</h4>
|
||||
<div class="m10b size-12">
|
||||
<div class="m10b size-12" ng-hide="wallet.totalCopayers == 1">
|
||||
<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="m10b size-12" ng-hide="wallet.totalCopayers > 1 || !loading">
|
||||
<i class="size-21 fi-bitcoin-circle icon-rotate spinner"></i> Loading...
|
||||
</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="panel radius" ng-repeat="btx in blockchain_txs | orderBy: 'time':true">
|
||||
<div class="m10 size-12">
|
||||
<div class="row">
|
||||
<div class="large-8 columns">
|
||||
|
@ -710,7 +713,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="row" ng-show="wallet.totalCopayers > 1">
|
||||
<div class="large-12 columns">
|
||||
<div class="row collapse">
|
||||
<label for="comment">Note
|
||||
|
|
|
@ -47,13 +47,27 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
|
||||
var w = $rootScope.wallet;
|
||||
|
||||
w.createTx(address, amount, commentText, function() {
|
||||
$scope.loading = false;
|
||||
$rootScope.$flashMessage = {
|
||||
message: 'The transaction proposal has been created',
|
||||
type: 'success'
|
||||
};
|
||||
$rootScope.$digest();
|
||||
w.createTx(address, amount, commentText, function(ntxid) {
|
||||
if (w.totalCopayers > 1) {
|
||||
$scope.loading = false;
|
||||
$rootScope.$flashMessage = {
|
||||
message: 'The transaction proposal has been created',
|
||||
type: 'success'
|
||||
};
|
||||
$rootScope.$digest();
|
||||
} else {
|
||||
w.sendTx(ntxid, function(txid) {
|
||||
$rootScope.$flashMessage = txid ? {
|
||||
type: 'success',
|
||||
message: 'Transaction broadcasted. txid: ' + txid
|
||||
} : {
|
||||
type: 'error',
|
||||
message: 'There was an error sending the Transaction'
|
||||
};
|
||||
$scope.loading = false;
|
||||
$scope.update();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// reset fields
|
||||
|
|
|
@ -147,9 +147,10 @@ angular.module('copayApp.controllers').controller('TransactionsController',
|
|||
if (w) {
|
||||
var addresses = w.getAddressesStr();
|
||||
if (addresses.length > 0) {
|
||||
$scope.blockchain_txs = [];
|
||||
$scope.blockchain_txs = $scope.wallet.txCache || [];
|
||||
w.blockchain.getTransactions(addresses, function(txs) {
|
||||
$timeout(function() {
|
||||
$scope.blockchain_txs = [];
|
||||
for (var i = 0; i < txs.length; i++) {
|
||||
txs[i].vinSimple = _aggregateItems(txs[i].vin);
|
||||
txs[i].voutSimple = _aggregateItems(txs[i].vout);
|
||||
|
@ -157,6 +158,7 @@ angular.module('copayApp.controllers').controller('TransactionsController',
|
|||
txs[i].fees = ((txs[i].fees * bitcore.util.COIN).toFixed(0)) * satToUnit;
|
||||
$scope.blockchain_txs.push(txs[i]);
|
||||
}
|
||||
$scope.wallet.txCache = $scope.blockchain_txs;
|
||||
$scope.loading = false;
|
||||
}, 10);
|
||||
});
|
||||
|
@ -185,4 +187,10 @@ angular.module('copayApp.controllers').controller('TransactionsController',
|
|||
$scope.loading = false;
|
||||
};
|
||||
|
||||
// Autoload transactions on 1-of-1
|
||||
if ($rootScope.wallet && $rootScope.wallet.totalCopayers == 1) {
|
||||
$scope.lastShowed = true;
|
||||
$scope.getTransactions();
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -2,6 +2,8 @@ var FakeWallet = function() {
|
|||
this.id = 'testID';
|
||||
this.balance = 10000;
|
||||
this.safeBalance = 1000;
|
||||
this.totalCopayers = 2;
|
||||
this.requiredCopayers = 2;
|
||||
this.balanceByAddr = {
|
||||
'1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC': 1000
|
||||
};
|
||||
|
@ -15,6 +17,15 @@ var FakeWallet = function() {
|
|||
};
|
||||
};
|
||||
|
||||
FakeWallet.prototype.createTx = function(toAddress, amountSatStr, comment, opts, cb) {
|
||||
var callback = cb || opts;
|
||||
callback({});
|
||||
}
|
||||
|
||||
FakeWallet.prototype.sendTx = function(ntxid, cb) {
|
||||
cb(8);
|
||||
}
|
||||
|
||||
FakeWallet.prototype.set = function(balance, safeBalance, balanceByAddr) {
|
||||
this.balance = balance;
|
||||
this.safeBalance = safeBalance;
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
// test/unit/controllers/controllersSpec.js
|
||||
//
|
||||
|
||||
var sinon = require('sinon');
|
||||
|
||||
// Replace saveAs plugin
|
||||
saveAsLastCall = null;
|
||||
saveAs = function(o) {
|
||||
|
@ -115,7 +117,7 @@ describe("Unit: Controllers", function() {
|
|||
});
|
||||
|
||||
describe('Send Controller', function() {
|
||||
var scope, form;
|
||||
var scope, form, sendForm;
|
||||
beforeEach(angular.mock.module('copayApp'));
|
||||
beforeEach(angular.mock.inject(function($compile, $rootScope, $controller) {
|
||||
scope = $rootScope.$new();
|
||||
|
@ -129,14 +131,27 @@ describe("Unit: Controllers", function() {
|
|||
scope.model = {
|
||||
newaddress: null,
|
||||
newlabel: null,
|
||||
address: null,
|
||||
amount: null
|
||||
};
|
||||
$compile(element)(scope);
|
||||
|
||||
var element2 = angular.element(
|
||||
'<form name="form2">' +
|
||||
'<input type="text" id="address" name="address" ng-model="address" valid-address required>' +
|
||||
'<input type="number" id="amount" name="amount" ng-model="amount" min="1" max="10000000000" required>' +
|
||||
'<textarea id="comment" name="comment" ng-model="commentText" ng-maxlength="100"></textarea>' +
|
||||
'</form>'
|
||||
);
|
||||
$compile(element2)(scope);
|
||||
$controller('SendController', {
|
||||
$scope: scope,
|
||||
$modal: {},
|
||||
});
|
||||
|
||||
scope.$digest();
|
||||
form = scope.form;
|
||||
sendForm = scope.form2;
|
||||
}));
|
||||
|
||||
it('should have a SendController controller', function() {
|
||||
|
@ -170,6 +185,31 @@ describe("Unit: Controllers", function() {
|
|||
expect(form.newlabel.$invalid).to.equal(true);
|
||||
});
|
||||
|
||||
it('should create a transaction proposal', function() {
|
||||
sendForm.address.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy');
|
||||
sendForm.amount.$setViewValue(1000);
|
||||
|
||||
var spy = sinon.spy(scope.wallet, 'createTx');
|
||||
var spy2 = sinon.spy(scope.wallet, 'sendTx');
|
||||
scope.submitForm(sendForm);
|
||||
sinon.assert.callCount(spy, 1);
|
||||
sinon.assert.callCount(spy2, 0);
|
||||
});
|
||||
|
||||
it('should create and send a transaction proposal', function() {
|
||||
sendForm.address.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy');
|
||||
sendForm.amount.$setViewValue(1000);
|
||||
|
||||
scope.wallet.totalCopayers = scope.wallet.requiredCopayers = 1;
|
||||
var spy = sinon.spy(scope.wallet, 'createTx');
|
||||
var spy2 = sinon.spy(scope.wallet, 'sendTx');
|
||||
scope.update = function() {};
|
||||
|
||||
scope.submitForm(sendForm);
|
||||
sinon.assert.callCount(spy, 1);
|
||||
sinon.assert.callCount(spy2, 1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("Unit: Header Controller", function() {
|
||||
|
|
Loading…
Reference in New Issue