mirror of https://github.com/BTCPrivate/copay.git
Merge pull request #742 from yemel/feature/better-off-alone
Review copay features for 1-of-1
This commit is contained in:
commit
8a8614fe5b
11
index.html
11
index.html
|
@ -451,7 +451,7 @@
|
||||||
<script type="text/ng-template" id="transactions.html">
|
<script type="text/ng-template" id="transactions.html">
|
||||||
<div class="transactions" data-ng-controller="TransactionsController">
|
<div class="transactions" data-ng-controller="TransactionsController">
|
||||||
<div class="row" ng-show='$root.wallet.publicKeyRing.isComplete()'>
|
<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>
|
<h4> Transaction proposals <small>({{txs.length}})</small></h4>
|
||||||
|
|
||||||
<ul class="inline-list">
|
<ul class="inline-list">
|
||||||
|
@ -558,15 +558,18 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="large-12 columns">
|
<div class="large-12 columns">
|
||||||
<h4>Last transactions</h4>
|
<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 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>
|
<a class="text-gray" ng-click="toogleLast()" ng-disabled="loading" loading="Loading" ng-show="lastShowed && !loading">[ Hide ]</a>
|
||||||
</div>
|
</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 class="btransactions" ng-if="lastShowed">
|
||||||
<div ng-if="!blockchain_txs[0].txid && !loading">
|
<div ng-if="!blockchain_txs[0].txid && !loading">
|
||||||
No transactions yet.
|
No transactions yet.
|
||||||
</div>
|
</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="m10 size-12">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="large-8 columns">
|
<div class="large-8 columns">
|
||||||
|
@ -710,7 +713,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row" ng-show="wallet.totalCopayers > 1">
|
||||||
<div class="large-12 columns">
|
<div class="large-12 columns">
|
||||||
<div class="row collapse">
|
<div class="row collapse">
|
||||||
<label for="comment">Note
|
<label for="comment">Note
|
||||||
|
|
|
@ -47,13 +47,26 @@ angular.module('copayApp.controllers').controller('SendController',
|
||||||
|
|
||||||
var w = $rootScope.wallet;
|
var w = $rootScope.wallet;
|
||||||
|
|
||||||
w.createTx(address, amount, commentText, function() {
|
w.createTx(address, amount, commentText, function(ntxid) {
|
||||||
|
if (w.totalCopayers > 1) {
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
$rootScope.$flashMessage = {
|
$rootScope.$flashMessage = {
|
||||||
message: 'The transaction proposal has been created',
|
message: 'The transaction proposal has been created',
|
||||||
type: 'success'
|
type: 'success'
|
||||||
};
|
};
|
||||||
$rootScope.$digest();
|
$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;
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// reset fields
|
// reset fields
|
||||||
|
|
|
@ -147,9 +147,10 @@ angular.module('copayApp.controllers').controller('TransactionsController',
|
||||||
if (w) {
|
if (w) {
|
||||||
var addresses = w.getAddressesStr();
|
var addresses = w.getAddressesStr();
|
||||||
if (addresses.length > 0) {
|
if (addresses.length > 0) {
|
||||||
$scope.blockchain_txs = [];
|
$scope.blockchain_txs = $scope.wallet.txCache || [];
|
||||||
w.blockchain.getTransactions(addresses, function(txs) {
|
w.blockchain.getTransactions(addresses, function(txs) {
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
|
$scope.blockchain_txs = [];
|
||||||
for (var i = 0; i < txs.length; i++) {
|
for (var i = 0; i < txs.length; i++) {
|
||||||
txs[i].vinSimple = _aggregateItems(txs[i].vin);
|
txs[i].vinSimple = _aggregateItems(txs[i].vin);
|
||||||
txs[i].voutSimple = _aggregateItems(txs[i].vout);
|
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;
|
txs[i].fees = ((txs[i].fees * bitcore.util.COIN).toFixed(0)) * satToUnit;
|
||||||
$scope.blockchain_txs.push(txs[i]);
|
$scope.blockchain_txs.push(txs[i]);
|
||||||
}
|
}
|
||||||
|
$scope.wallet.txCache = $scope.blockchain_txs;
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
}, 10);
|
}, 10);
|
||||||
});
|
});
|
||||||
|
@ -185,4 +187,10 @@ angular.module('copayApp.controllers').controller('TransactionsController',
|
||||||
$scope.loading = false;
|
$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.id = 'testID';
|
||||||
this.balance = 10000;
|
this.balance = 10000;
|
||||||
this.safeBalance = 1000;
|
this.safeBalance = 1000;
|
||||||
|
this.totalCopayers = 2;
|
||||||
|
this.requiredCopayers = 2;
|
||||||
this.balanceByAddr = {
|
this.balanceByAddr = {
|
||||||
'1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC': 1000
|
'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) {
|
FakeWallet.prototype.set = function(balance, safeBalance, balanceByAddr) {
|
||||||
this.balance = balance;
|
this.balance = balance;
|
||||||
this.safeBalance = safeBalance;
|
this.safeBalance = safeBalance;
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
// test/unit/controllers/controllersSpec.js
|
// test/unit/controllers/controllersSpec.js
|
||||||
//
|
//
|
||||||
|
|
||||||
|
var sinon = require('sinon');
|
||||||
|
|
||||||
// Replace saveAs plugin
|
// Replace saveAs plugin
|
||||||
saveAsLastCall = null;
|
saveAsLastCall = null;
|
||||||
saveAs = function(o) {
|
saveAs = function(o) {
|
||||||
|
@ -115,7 +117,7 @@ describe("Unit: Controllers", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Send Controller', function() {
|
describe('Send Controller', function() {
|
||||||
var scope, form;
|
var scope, form, sendForm;
|
||||||
beforeEach(angular.mock.module('copayApp'));
|
beforeEach(angular.mock.module('copayApp'));
|
||||||
beforeEach(angular.mock.inject(function($compile, $rootScope, $controller) {
|
beforeEach(angular.mock.inject(function($compile, $rootScope, $controller) {
|
||||||
scope = $rootScope.$new();
|
scope = $rootScope.$new();
|
||||||
|
@ -129,14 +131,27 @@ describe("Unit: Controllers", function() {
|
||||||
scope.model = {
|
scope.model = {
|
||||||
newaddress: null,
|
newaddress: null,
|
||||||
newlabel: null,
|
newlabel: null,
|
||||||
|
address: null,
|
||||||
|
amount: null
|
||||||
};
|
};
|
||||||
$compile(element)(scope);
|
$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', {
|
$controller('SendController', {
|
||||||
$scope: scope,
|
$scope: scope,
|
||||||
$modal: {},
|
$modal: {},
|
||||||
});
|
});
|
||||||
|
|
||||||
scope.$digest();
|
scope.$digest();
|
||||||
form = scope.form;
|
form = scope.form;
|
||||||
|
sendForm = scope.form2;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should have a SendController controller', function() {
|
it('should have a SendController controller', function() {
|
||||||
|
@ -170,6 +185,30 @@ describe("Unit: Controllers", function() {
|
||||||
expect(form.newlabel.$invalid).to.equal(true);
|
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.submitForm(sendForm);
|
||||||
|
sinon.assert.callCount(spy, 1);
|
||||||
|
sinon.assert.callCount(spy2, 1);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Unit: Header Controller", function() {
|
describe("Unit: Header Controller", function() {
|
||||||
|
|
Loading…
Reference in New Issue