commit
ef3c8e2865
9 changed files with 77 additions and 94 deletions
31
index.html
31
index.html
|
|
@ -209,14 +209,13 @@
|
||||||
<div class="home" data-ng-controller="HomeController">
|
<div class="home" data-ng-controller="HomeController">
|
||||||
<div ng-show='$root.wallet.publicKeyRing.isComplete()'>
|
<div ng-show='$root.wallet.publicKeyRing.isComplete()'>
|
||||||
<h3>Address</h3>
|
<h3>Address</h3>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="large-6 columns">
|
<div class="large-6 columns">
|
||||||
<a class="panel db" ng-repeat="addr in addrs" ng-click="selectAddr(addr)">{{addr}} <span class="right">({{addrBalance[addr]}} BTC) ></span></a>
|
<a class="panel db" ng-repeat="addr in addrs" ng-click="selectAddr(addr)">{{addr}} <span class="right">{{balanceByAddr[addr] || 0}} BTC ></span></a>
|
||||||
</div>
|
</div>
|
||||||
<div class="large-3 columns line-dashed-v text-center">
|
<div class="large-3 columns line-dashed-v text-center">
|
||||||
<qrcode size="160" data="{{selectedAddr}}"></qrcode>
|
<qrcode size="160" data="{{selectedAddr}}"></qrcode>
|
||||||
<p class="m10t" ng-repeat="addr in addrs" ng-if="selectedAddr==addr"> <strong> {{addrBalance[addr]}} BTC </strong> </p>
|
<p class="m10t" ng-repeat="addr in addrs" ng-if="selectedAddr==addr"> <strong> {{balanceByAddr[addr]}} BTC </strong> </p>
|
||||||
</div>
|
</div>
|
||||||
<div class="large-1 columns"> </div>
|
<div class="large-1 columns"> </div>
|
||||||
<div class="large-2 columns">
|
<div class="large-2 columns">
|
||||||
|
|
@ -236,20 +235,20 @@
|
||||||
<div class="large-12 columns">
|
<div class="large-12 columns">
|
||||||
<h3>Pending Transactions <small>({{txs.length}})</small></h3>
|
<h3>Pending Transactions <small>({{txs.length}})</small></h3>
|
||||||
<div class="panel pending" ng-repeat="txp in txs">
|
<div class="panel pending" ng-repeat="txp in txs">
|
||||||
{{txp}}
|
<div class="row" ng-repeat="o in txs.outs">
|
||||||
<div class="row">
|
<p class="large-5 columns"> {{o.address}}</p>
|
||||||
<p class="large-5 columns"> Address 1</p>
|
|
||||||
<i class="large-2 columns fi-arrow-right size-16 text-center"></i>
|
<i class="large-2 columns fi-arrow-right size-16 text-center"></i>
|
||||||
<p class="large-5 columns"> Address 2</p>
|
<p class="large-5 columns"> {{o.value}} BTC </p>
|
||||||
|
</div>
|
||||||
<div class="large-12 columns m0" ng-show="txp.signedByUs"> YOU SIGNED! </div>
|
<div class="large-12 columns m0 panel panel-sign" ng-show="txp.signedByUs">
|
||||||
|
<i class="fi-check size-40"></i> YOU SIGNED!
|
||||||
<div class="large-12 columns m0" ng-show="!txp.signedByUs">
|
</div>
|
||||||
<div class="line"></div>
|
<div class="large-12 columns m0" ng-show="!txp.signedByUs">
|
||||||
<button class="primary round large-4 columns"><i class="large-2 columns fi-x size-16 text-center"></i> Ignore</button>
|
<div class="line"></div>
|
||||||
<small class="large-4 columns text-center">Faltan 3 cosigners</small>
|
<button class="primary round large-4 columns"><i class="large-2 columns fi-x size-16 text-center"></i> Ignore</button>
|
||||||
<button class="secondary round large-4 columns" ng-click="sign(txp.ntxid)"><i class="large-2 columns fi-check size-16 text-center"></i> Sign</button>
|
<small class="large-4 columns text-center">Faltan 3 cosigners</small>
|
||||||
</div>
|
<button class="secondary round large-4 columns" ng-click="sign(txp.ntxid)"><i class="large-2 columns fi-check size-16 text-center"></i> Sign</button>
|
||||||
|
</div>
|
||||||
</div> <!-- end of row -->
|
</div> <!-- end of row -->
|
||||||
</div> <!-- end of pending -->
|
</div> <!-- end of pending -->
|
||||||
<div class="line-dashed-h"></div>
|
<div class="line-dashed-h"></div>
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,7 @@ angular.module('copay.backup').controller('BackupController',
|
||||||
$location.path('signin');
|
$location.path('signin');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var socket = Socket($scope);
|
controllerUtils.handleTransactionByAddress($scope);
|
||||||
socket.on('connect', controllerUtils.handleTransactionByAddress($scope));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.title = 'Backup';
|
$scope.title = 'Backup';
|
||||||
|
|
|
||||||
|
|
@ -3,40 +3,34 @@
|
||||||
angular.module('copay.home').controller('HomeController',
|
angular.module('copay.home').controller('HomeController',
|
||||||
function($scope, $rootScope, $location, Socket, controllerUtils) {
|
function($scope, $rootScope, $location, Socket, controllerUtils) {
|
||||||
$scope.title = 'Home';
|
$scope.title = 'Home';
|
||||||
|
|
||||||
$scope.oneAtATime = true;
|
$scope.oneAtATime = true;
|
||||||
$scope.addrBalance = {};
|
$scope.addrBalance = {};
|
||||||
|
|
||||||
var _getBalance = function() {
|
var w = $rootScope.wallet;
|
||||||
$scope.addrs.forEach(function(addr) {
|
|
||||||
$rootScope.wallet.getBalance([addr], function(balance) {
|
var _updateBalance = function () {
|
||||||
$scope.addrBalance[addr] = balance;
|
w.getBalance(function (balance, balanceByAddr) {
|
||||||
$scope.$digest();
|
$scope.balanceByAddr = balanceByAddr;
|
||||||
});
|
$scope.addrs = Object.keys(balanceByAddr);
|
||||||
|
$scope.selectedAddr = $scope.addrs[0];
|
||||||
|
$scope.$digest();
|
||||||
});
|
});
|
||||||
|
var socket = Socket($scope);
|
||||||
|
controllerUtils.handleTransactionByAddress($scope, _updateBalance);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!$rootScope.wallet || !$rootScope.wallet.id) {
|
|
||||||
$location.path('signin');
|
|
||||||
} else {
|
|
||||||
$scope.addrs = $rootScope.wallet.getAddressesStr(true);
|
|
||||||
$scope.selectedAddr = $scope.addrs[0];
|
|
||||||
|
|
||||||
_getBalance();
|
|
||||||
|
|
||||||
var socket = Socket($scope);
|
|
||||||
socket.on('connect', controllerUtils.handleTransactionByAddress($scope));
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.newAddr = function() {
|
$scope.newAddr = function() {
|
||||||
var a = $rootScope.wallet.generateAddress().toString();
|
var a = w.generateAddress().toString();
|
||||||
$scope.addrs.push(a);
|
_updateBalance();
|
||||||
_getBalance();
|
|
||||||
var socket = Socket($scope);
|
|
||||||
socket.on('connect', controllerUtils.handleTransactionByAddress($scope));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.selectAddr = function(addr) {
|
$scope.selectAddr = function(addr) {
|
||||||
$scope.selectedAddr = addr;
|
$scope.selectedAddr = addr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
if (!$rootScope.wallet || !$rootScope.wallet.id) {
|
||||||
|
$location.path('signin');
|
||||||
|
}
|
||||||
|
_updateBalance();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,7 @@ angular.module('copay.peer').controller('PeerController',
|
||||||
$location.path('signin');
|
$location.path('signin');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var socket = Socket($scope);
|
controllerUtils.handleTransactionByAddress($scope);
|
||||||
socket.on('connect', controllerUtils.handleTransactionByAddress($scope));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,7 @@ angular.module('copay.send').controller('SendController',
|
||||||
$location.path('signin');
|
$location.path('signin');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var socket = Socket($scope);
|
controllerUtils.handleTransactionByAddress($scope);
|
||||||
socket.on('connect', controllerUtils.handleTransactionByAddress($scope));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.sendTest = function() {
|
$scope.sendTest = function() {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ angular.module('copay.transactions').controller('TransactionsController',
|
||||||
var b = i.txp.builder;
|
var b = i.txp.builder;
|
||||||
var tx = b.build();
|
var tx = b.build();
|
||||||
var one = {
|
var one = {
|
||||||
valueOutSat: b.valueOutSat,
|
|
||||||
feeSat: b.feeSat,
|
feeSat: b.feeSat,
|
||||||
};
|
};
|
||||||
var outs = [];
|
var outs = [];
|
||||||
|
|
@ -24,7 +23,10 @@ angular.module('copay.transactions').controller('TransactionsController',
|
||||||
var s = o.getScript();
|
var s = o.getScript();
|
||||||
var aStr = bitcore.Address.fromScript(s, config.networkName).toString();
|
var aStr = bitcore.Address.fromScript(s, config.networkName).toString();
|
||||||
if (!w.addressIsOwn(aStr))
|
if (!w.addressIsOwn(aStr))
|
||||||
outs.push({address: aStr, value: bitcore.util.valueToBigInt(o.getValue())});
|
outs.push({
|
||||||
|
address: aStr,
|
||||||
|
value: bitcore.util.valueToBigInt(o.getValue())/bitcore.util.COIN,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
one.outs = outs;
|
one.outs = outs;
|
||||||
ts.push(one);
|
ts.push(one);
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ function _asyncForEach(array, fn, callback) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Insight.prototype.listUnspent = function(addresses, cb) {
|
Insight.prototype.getUnspent = function(addresses, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (!addresses || !addresses.length) return cb([]);
|
if (!addresses || !addresses.length) return cb([]);
|
||||||
|
|
|
||||||
|
|
@ -152,13 +152,17 @@ Wallet.prototype.netStart = function() {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Wallet.prototype.store = function() {
|
Wallet.prototype.store = function(isSync) {
|
||||||
this.log('[Wallet.js.135:store:]'); //TODO
|
this.log('[Wallet.js.135:store:]'); //TODO
|
||||||
var wallet = this.toObj();
|
var wallet = this.toObj();
|
||||||
this.storage.setFromObj(this.id, wallet);
|
this.storage.setFromObj(this.id, wallet);
|
||||||
|
|
||||||
this.log('[Wallet.js.146] EMIT REFRESH'); //TODO
|
if (isSync) {
|
||||||
this.emit('refresh');
|
this.log('Wallet stored.'); //TODO
|
||||||
|
} else {
|
||||||
|
this.log('Wallet stored. REFRESH Emitted'); //TODO
|
||||||
|
this.emit('refresh');
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -222,7 +226,7 @@ Wallet.prototype.sendPublicKeyRing = function(recipients) {
|
||||||
Wallet.prototype.generateAddress = function() {
|
Wallet.prototype.generateAddress = function() {
|
||||||
var addr = this.publicKeyRing.generateAddress();
|
var addr = this.publicKeyRing.generateAddress();
|
||||||
this.sendPublicKeyRing();
|
this.sendPublicKeyRing();
|
||||||
this.store();
|
this.store(true);
|
||||||
return addr;
|
return addr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -272,13 +276,13 @@ Wallet.prototype.sign = function(ntxid) {
|
||||||
this.blockchain.sendRawTransaction(txHex, function(txid) {
|
this.blockchain.sendRawTransaction(txHex, function(txid) {
|
||||||
this.log('[Wallet.js.235:txid:]',txid); //TODO
|
this.log('[Wallet.js.235:txid:]',txid); //TODO
|
||||||
if (txid) {
|
if (txid) {
|
||||||
this.store();
|
this.store(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.sendTxProposals();
|
this.sendTxProposals();
|
||||||
this.store();
|
this.store(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|
@ -311,7 +315,6 @@ Wallet.prototype.getAddressesStr = function(onlyMain) {
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Wallet.prototype.addressIsOwn = function(addrStr) {
|
Wallet.prototype.addressIsOwn = function(addrStr) {
|
||||||
var addrList = this.getAddressesStr();
|
var addrList = this.getAddressesStr();
|
||||||
var l = addrList.length;
|
var l = addrList.length;
|
||||||
|
|
@ -326,38 +329,35 @@ Wallet.prototype.addressIsOwn = function(addrStr) {
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Wallet.prototype.getBalance = function(cb) {
|
||||||
Wallet.prototype.getTotalBalance = function(cb) {
|
|
||||||
this.getBalance(this.getAddressesStr(), function(balance) {
|
|
||||||
return cb(balance);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Wallet.prototype.getBalance = function(addrs, cb) {
|
|
||||||
var balance = 0;
|
var balance = 0;
|
||||||
this.listUnspent(addrs, function(utxos) {
|
var balanceByAddr = {};
|
||||||
|
var COIN = bitcore.util.COIN;
|
||||||
|
|
||||||
|
// Prefill balanceByAddr with main address
|
||||||
|
this.getAddressesStr(true).forEach(function(a){
|
||||||
|
balanceByAddr[a]=0;
|
||||||
|
});
|
||||||
|
this.getUnspent(function(utxos) {
|
||||||
for(var i=0;i<utxos.length; i++) {
|
for(var i=0;i<utxos.length; i++) {
|
||||||
balance = balance + utxos[i].amount;
|
var u= utxos[i];
|
||||||
|
var amt = u.amount * COIN;
|
||||||
|
balance = balance + amt;
|
||||||
|
balanceByAddr[u.address] = (balanceByAddr[u.address]||0) + amt;
|
||||||
}
|
}
|
||||||
if (balance) {
|
Object.keys(balanceByAddr).forEach(function(a) {
|
||||||
if (balance === parseInt(balance)) {
|
balanceByAddr[a] = balanceByAddr[a]/COIN;
|
||||||
balance = balance;
|
});
|
||||||
}
|
return cb(balance / COIN, balanceByAddr);
|
||||||
else {
|
|
||||||
balance = balance.toFixed(8);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cb(balance);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Wallet.prototype.listUnspent = function(addrs, cb) {
|
Wallet.prototype.getUnspent = function(cb) {
|
||||||
this.blockchain.listUnspent(addrs, function(utxos) {
|
this.blockchain.getUnspent(this.getAddressesStr(), function(unspentList) {
|
||||||
return cb(utxos);
|
return cb(unspentList);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Wallet.prototype.createTx = function(toAddress, amountSatStr, opts, cb) {
|
Wallet.prototype.createTx = function(toAddress, amountSatStr, opts, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
if (typeof opts === 'function') {
|
if (typeof opts === 'function') {
|
||||||
|
|
@ -374,9 +374,9 @@ Wallet.prototype.createTx = function(toAddress, amountSatStr, opts, cb) {
|
||||||
opts.remainderOut={ address: this.publicKeyRing.generateAddress(true).toString()};
|
opts.remainderOut={ address: this.publicKeyRing.generateAddress(true).toString()};
|
||||||
}
|
}
|
||||||
|
|
||||||
self.listUnspent(self.getAddressesStr(), function(utxos) {
|
self.getUnspent(function(unspentList) {
|
||||||
// TODO check enough funds, etc.
|
// TODO check enough funds, etc.
|
||||||
self.createTxSync(toAddress, amountSatStr, utxos, opts);
|
self.createTxSync(toAddress, amountSatStr, unspentList, opts);
|
||||||
self.sendTxProposals();
|
self.sendTxProposals();
|
||||||
self.store();
|
self.store();
|
||||||
return cb();
|
return cb();
|
||||||
|
|
@ -426,11 +426,4 @@ Wallet.prototype.disconnect = function() {
|
||||||
this.network.disconnect();
|
this.network.disconnect();
|
||||||
};
|
};
|
||||||
|
|
||||||
// // HERE? not sure
|
|
||||||
// Wallet.prototype.cleanPeers = function() {
|
|
||||||
// this.storage.remove('peerData');
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
;
|
|
||||||
|
|
||||||
module.exports = require('soop')(Wallet);
|
module.exports = require('soop')(Wallet);
|
||||||
|
|
|
||||||
|
|
@ -32,35 +32,34 @@ angular.module('copay.controllerUtils').factory('controllerUtils', function ($ro
|
||||||
$location.path('peer');
|
$location.path('peer');
|
||||||
$rootScope.wallet = w;
|
$rootScope.wallet = w;
|
||||||
|
|
||||||
// Initial getBalance
|
$rootScope.wallet.getBalance(function(balance) {
|
||||||
$rootScope.wallet.getTotalBalance(function(balance) {
|
|
||||||
$rootScope.totalBalance = balance;
|
$rootScope.totalBalance = balance;
|
||||||
$rootScope.$digest();
|
$rootScope.$digest();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
w.on('refresh', function() {
|
w.on('refresh', function() {
|
||||||
console.log('[controllerUtils.js] Refreshing'); //TODO
|
console.log('[controllerUtils.js] Refreshing'); //TODO
|
||||||
// Do not use $digest() here.
|
$rootScope.$digest();
|
||||||
});
|
});
|
||||||
w.on('openError', root.onErrorDigest);
|
w.on('openError', root.onErrorDigest);
|
||||||
w.on('close', root.onErrorDigest);
|
w.on('close', root.onErrorDigest);
|
||||||
};
|
};
|
||||||
|
|
||||||
root.handleTransactionByAddress = function(scope) {
|
root.handleTransactionByAddress = function(scope, cb) {
|
||||||
var socket = Socket(scope);
|
var socket = Socket(scope);
|
||||||
var addrs = $rootScope.wallet.getAddressesStr();
|
var addrs = $rootScope.wallet.getAddressesStr();
|
||||||
socket.emit('subscribe', 'inv');
|
|
||||||
for(var i=0;i<addrs.length;i++) {
|
for(var i=0;i<addrs.length;i++) {
|
||||||
socket.emit('subscribe', addrs[i]);
|
socket.emit('subscribe', addrs[i]);
|
||||||
}
|
}
|
||||||
addrs.forEach(function(addr) {
|
addrs.forEach(function(addr) {
|
||||||
socket.on(addr, function(txid) {
|
socket.on(addr, function(txid) {
|
||||||
console.log('Received!', txid);
|
console.log('Received!', txid);
|
||||||
$rootScope.wallet.getTotalBalance(function(balance) {
|
$rootScope.wallet.getBalance(function(balance) {
|
||||||
scope.$apply(function() {
|
scope.$apply(function() {
|
||||||
$rootScope.totalBalance = balance;
|
$rootScope.totalBalance = balance;
|
||||||
});
|
});
|
||||||
console.log('New balance:', balance);
|
console.log('New balance:', balance);
|
||||||
|
if (typeof cb === 'function') return cb();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue