2014-04-17 11:46:49 -03:00
|
|
|
'use strict';
|
2014-06-12 17:42:26 -03:00
|
|
|
var bitcore = require('bitcore');
|
2014-04-17 11:46:49 -03:00
|
|
|
|
2014-06-03 17:42:36 -03:00
|
|
|
angular.module('copayApp.services')
|
2014-09-16 17:30:30 -03:00
|
|
|
.factory('controllerUtils', function($rootScope, $sce, $location, $filter, notification, $timeout, uriHandler, rateService) {
|
2014-08-22 13:13:04 -04:00
|
|
|
var root = {};
|
2014-05-07 19:04:36 -03:00
|
|
|
|
2014-10-10 17:58:19 -03:00
|
|
|
|
|
|
|
|
root.redirIfNotComplete = function() {
|
|
|
|
|
var w = $rootScope.wallet;
|
|
|
|
|
if (w) {
|
|
|
|
|
if (!w.isReady()) {
|
|
|
|
|
$location.path('/copayers');
|
2014-10-15 12:09:10 -03:00
|
|
|
}
|
2014-10-10 17:58:19 -03:00
|
|
|
} else {
|
|
|
|
|
$location.path('/');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2014-08-22 13:13:04 -04:00
|
|
|
root.redirIfLogged = function() {
|
2014-10-08 10:54:26 -03:00
|
|
|
var w = $rootScope.wallet;
|
|
|
|
|
if (w) {
|
|
|
|
|
if (!w.isReady()) {
|
|
|
|
|
$location.path('/copayers');
|
|
|
|
|
} else {
|
2014-10-31 11:49:52 -03:00
|
|
|
$location.path('homeWallet');
|
2014-10-08 10:54:26 -03:00
|
|
|
}
|
2014-08-22 13:13:04 -04:00
|
|
|
}
|
|
|
|
|
};
|
2014-08-06 18:41:37 -03:00
|
|
|
|
2014-08-22 13:13:04 -04:00
|
|
|
root.logout = function() {
|
2014-10-29 23:23:16 -03:00
|
|
|
|
|
|
|
|
if ($rootScope.iden) {
|
2014-10-30 16:20:25 -03:00
|
|
|
$rootScope.iden.store(null, function() {
|
2014-10-29 23:23:16 -03:00
|
|
|
$rootScope.iden.close();
|
2014-06-24 12:57:15 -03:00
|
|
|
|
2014-10-30 16:20:25 -03:00
|
|
|
delete $rootScope['wallet'];
|
|
|
|
|
delete $rootScope['iden'];
|
2014-04-23 18:07:20 -03:00
|
|
|
|
2014-10-31 16:14:52 -03:00
|
|
|
// Go home reloading the application
|
|
|
|
|
var hashIndex = window.location.href.indexOf('#!/');
|
|
|
|
|
window.location = window.location.href.substr(0, hashIndex);
|
2014-10-30 16:20:25 -03:00
|
|
|
});
|
|
|
|
|
}
|
2014-08-22 13:13:04 -04:00
|
|
|
};
|
2014-06-12 11:03:24 -03:00
|
|
|
|
2014-08-22 13:13:04 -04:00
|
|
|
root.onError = function(scope) {
|
2014-11-12 12:35:50 -03:00
|
|
|
if (scope) {
|
|
|
|
|
scope.loading = false;
|
|
|
|
|
}
|
2014-08-12 15:26:15 -04:00
|
|
|
}
|
2014-08-22 13:13:04 -04:00
|
|
|
|
|
|
|
|
root.onErrorDigest = function(scope, msg) {
|
|
|
|
|
root.onError(scope);
|
|
|
|
|
if (msg) {
|
|
|
|
|
notification.error('Error', msg);
|
2014-08-12 15:26:15 -04:00
|
|
|
}
|
2014-08-22 13:13:04 -04:00
|
|
|
};
|
2014-07-08 08:58:24 -03:00
|
|
|
|
2014-10-06 16:13:21 -03:00
|
|
|
|
|
|
|
|
root.isFocusedWallet = function(wid) {
|
2014-10-31 12:03:37 -03:00
|
|
|
return $rootScope.wallet && wid === $rootScope.wallet.getId();
|
2014-10-06 16:13:21 -03:00
|
|
|
};
|
|
|
|
|
|
2014-10-15 12:09:10 -03:00
|
|
|
|
2014-11-07 15:30:00 -03:00
|
|
|
root.updateTxsAndBalance = function(w) {
|
2014-11-07 12:22:05 -03:00
|
|
|
root.updateTxs();
|
2014-10-15 12:09:10 -03:00
|
|
|
root.updateBalance(w, function() {
|
|
|
|
|
$rootScope.$digest();
|
2014-11-07 12:22:05 -03:00
|
|
|
});
|
2014-11-07 15:30:00 -03:00
|
|
|
};
|
2014-10-15 12:09:10 -03:00
|
|
|
|
2014-10-08 10:54:26 -03:00
|
|
|
root.installWalletHandlers = function($scope, w) {
|
2014-10-06 16:13:21 -03:00
|
|
|
|
|
|
|
|
var wid = w.getId();
|
2014-09-09 15:30:21 -03:00
|
|
|
w.on('connectionError', function() {
|
2014-10-06 16:13:21 -03:00
|
|
|
if (root.isFocusedWallet(wid)) {
|
|
|
|
|
var message = "Could not connect to the Insight server. Check your settings and network configuration";
|
|
|
|
|
notification.error('Networking Error', message);
|
|
|
|
|
root.onErrorDigest($scope);
|
|
|
|
|
}
|
2014-08-22 13:13:04 -04:00
|
|
|
});
|
2014-04-24 23:13:55 -03:00
|
|
|
|
2014-08-22 13:13:04 -04:00
|
|
|
w.on('corrupt', function(peerId) {
|
2014-10-06 16:13:21 -03:00
|
|
|
if (root.isFocusedWallet(wid)) {
|
|
|
|
|
notification.error('Error', $filter('translate')('Received corrupt message from ') + peerId);
|
|
|
|
|
}
|
2014-08-22 13:13:04 -04:00
|
|
|
});
|
|
|
|
|
w.on('ready', function(myPeerID) {
|
2014-10-06 16:13:21 -03:00
|
|
|
$scope.loading = false;
|
2014-09-19 11:27:48 -03:00
|
|
|
if ($rootScope.initialConnection) {
|
|
|
|
|
$rootScope.initialConnection = false;
|
|
|
|
|
if ($rootScope.pendingPayment) {
|
2014-11-03 18:02:21 -03:00
|
|
|
$location.path('paymentIntent');
|
2014-09-19 11:27:48 -03:00
|
|
|
} else {
|
2014-10-08 10:54:26 -03:00
|
|
|
root.redirIfLogged();
|
2014-09-19 11:27:48 -03:00
|
|
|
}
|
2014-08-22 13:13:04 -04:00
|
|
|
}
|
|
|
|
|
});
|
2014-05-16 18:48:17 -03:00
|
|
|
|
2014-09-17 17:34:00 -03:00
|
|
|
w.on('tx', function(address, isChange) {
|
2014-10-15 12:09:10 -03:00
|
|
|
if (!isChange) {
|
|
|
|
|
notification.funds('Funds received on ' + w.getName(), address);
|
2014-09-17 17:34:00 -03:00
|
|
|
}
|
2014-10-15 12:09:10 -03:00
|
|
|
root.updateBalance(w, function() {
|
|
|
|
|
$rootScope.$digest();
|
|
|
|
|
});
|
2014-09-09 15:30:21 -03:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
w.on('balanceUpdated', function() {
|
2014-10-15 12:09:10 -03:00
|
|
|
root.updateBalance(w, function() {
|
|
|
|
|
$rootScope.$digest();
|
|
|
|
|
});
|
2014-09-09 15:30:21 -03:00
|
|
|
});
|
|
|
|
|
|
2014-09-09 20:55:51 -03:00
|
|
|
w.on('insightReconnected', function() {
|
2014-10-15 12:09:10 -03:00
|
|
|
$rootScope.reconnecting = false;
|
|
|
|
|
root.updateAddressList(w.getId());
|
|
|
|
|
root.updateBalance(w, function() {
|
|
|
|
|
$rootScope.$digest();
|
|
|
|
|
});
|
2014-09-09 15:30:21 -03:00
|
|
|
});
|
|
|
|
|
|
2014-09-09 20:55:51 -03:00
|
|
|
w.on('insightError', function() {
|
2014-10-06 16:13:21 -03:00
|
|
|
if (root.isFocusedWallet(wid)) {
|
|
|
|
|
$rootScope.reconnecting = true;
|
|
|
|
|
$rootScope.$digest();
|
|
|
|
|
}
|
2014-09-09 15:30:21 -03:00
|
|
|
});
|
2014-10-27 14:53:40 -03:00
|
|
|
w.on('newAddresses', function() {
|
|
|
|
|
root.updateTxsAndBalance(w);
|
|
|
|
|
});
|
2014-09-09 15:30:21 -03:00
|
|
|
|
2014-10-27 14:53:40 -03:00
|
|
|
w.on('txProposalsUpdated', function() {
|
2014-10-15 12:09:10 -03:00
|
|
|
root.updateTxsAndBalance(w);
|
2014-08-22 13:13:04 -04:00
|
|
|
});
|
2014-10-06 18:58:45 -03:00
|
|
|
|
2014-08-22 13:13:04 -04:00
|
|
|
w.on('txProposalEvent', function(e) {
|
2014-09-10 18:03:31 -03:00
|
|
|
|
2014-11-07 12:22:05 -03:00
|
|
|
root.updateTxsAndBalance(w);
|
2014-10-06 16:13:21 -03:00
|
|
|
// TODO: add wallet name notification
|
2014-08-22 13:13:04 -04:00
|
|
|
var user = w.publicKeyRing.nicknameForCopayer(e.cId);
|
2014-11-07 12:22:05 -03:00
|
|
|
var name = w.getName();
|
2014-08-22 13:13:04 -04:00
|
|
|
switch (e.type) {
|
2014-11-07 12:22:05 -03:00
|
|
|
case 'new':
|
|
|
|
|
notification.info('['+ name +'] New Transaction',
|
|
|
|
|
$filter('translate')('You received a transaction proposal from') + ' ' + user);
|
|
|
|
|
break;
|
2014-08-22 13:13:04 -04:00
|
|
|
case 'signed':
|
2014-11-07 12:22:05 -03:00
|
|
|
notification.info('['+ name +'] Transaction Signed',
|
|
|
|
|
$filter('translate')('A transaction was signed by') + ' ' + user);
|
2014-08-22 13:13:04 -04:00
|
|
|
break;
|
|
|
|
|
case 'rejected':
|
2014-11-07 12:22:05 -03:00
|
|
|
notification.info('['+ name +'] Transaction Rejected',
|
|
|
|
|
$filter('translate')('A transaction was rejected by') + ' ' + user);
|
2014-08-22 13:13:04 -04:00
|
|
|
break;
|
|
|
|
|
case 'corrupt':
|
2014-11-07 12:22:05 -03:00
|
|
|
notification.error('['+ name +'] Transaction Error',
|
|
|
|
|
$filter('translate')('Received corrupt transaction from') + ' ' + user);
|
2014-08-22 13:13:04 -04:00
|
|
|
break;
|
|
|
|
|
}
|
2014-11-07 12:22:05 -03:00
|
|
|
$rootScope.$digest();
|
2014-08-22 13:13:04 -04:00
|
|
|
});
|
|
|
|
|
w.on('addressBookUpdated', function(dontDigest) {
|
2014-10-06 16:13:21 -03:00
|
|
|
if (root.isFocusedWallet(wid)) {
|
|
|
|
|
if (!dontDigest) {
|
|
|
|
|
$rootScope.$digest();
|
|
|
|
|
}
|
2014-08-22 13:13:04 -04:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
w.on('connect', function(peerID) {
|
2014-05-09 11:59:38 -03:00
|
|
|
$rootScope.$digest();
|
2014-08-22 13:13:04 -04:00
|
|
|
});
|
|
|
|
|
w.on('close', root.onErrorDigest);
|
|
|
|
|
w.on('locked', root.onErrorDigest.bind(this));
|
2014-09-19 17:12:54 -03:00
|
|
|
|
2014-09-09 15:30:21 -03:00
|
|
|
};
|
|
|
|
|
|
2014-10-08 10:54:26 -03:00
|
|
|
root.setupGlobalVariables = function(iden) {
|
|
|
|
|
notification.enableHtml5Mode(); // for chrome: if support, enable it
|
2014-09-09 15:30:21 -03:00
|
|
|
uriHandler.register();
|
|
|
|
|
$rootScope.unitName = config.unitName;
|
|
|
|
|
$rootScope.txAlertCount = 0;
|
2014-09-19 11:27:48 -03:00
|
|
|
$rootScope.initialConnection = true;
|
2014-09-09 15:30:21 -03:00
|
|
|
$rootScope.reconnecting = false;
|
|
|
|
|
$rootScope.isCollapsed = true;
|
|
|
|
|
|
2014-10-08 10:54:26 -03:00
|
|
|
$rootScope.iden = iden;
|
|
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
// $rootScope.$watch('txAlertCount', function(txAlertCount) {
|
|
|
|
|
// if (txAlertCount && txAlertCount > 0) {
|
|
|
|
|
//
|
|
|
|
|
// notification.info('New Transaction', ($rootScope.txAlertCount == 1) ? 'You have a pending transaction proposal' : $filter('translate')('You have') + ' ' + $rootScope.txAlertCount + ' ' + $filter('translate')('pending transaction proposals'), txAlertCount);
|
|
|
|
|
// }
|
|
|
|
|
// });
|
2014-09-09 15:30:21 -03:00
|
|
|
};
|
|
|
|
|
|
2014-10-05 15:59:41 -03:00
|
|
|
|
2014-10-08 10:54:26 -03:00
|
|
|
root.rebindWallets = function($scope, iden) {
|
2014-10-24 12:24:44 -03:00
|
|
|
_.each(iden.listWallets(), function(wallet) {
|
|
|
|
|
preconditions.checkState(wallet);
|
|
|
|
|
root.installWalletHandlers($scope, wallet);
|
2014-10-08 10:54:26 -03:00
|
|
|
});
|
2014-10-05 15:59:41 -03:00
|
|
|
};
|
|
|
|
|
|
2014-11-03 18:02:21 -03:00
|
|
|
root.setPaymentWallet = function(w) {
|
|
|
|
|
root.setFocusedWallet(w);
|
|
|
|
|
$location.path('/send');
|
|
|
|
|
};
|
|
|
|
|
|
2014-10-08 10:54:26 -03:00
|
|
|
root.setFocusedWallet = function(w) {
|
2014-10-15 12:09:10 -03:00
|
|
|
if (!_.isObject(w))
|
2014-10-24 12:24:44 -03:00
|
|
|
w = $rootScope.iden.getWalletById(w);
|
2014-10-31 12:27:22 -03:00
|
|
|
|
2014-10-08 10:54:26 -03:00
|
|
|
preconditions.checkState(w && _.isObject(w));
|
|
|
|
|
|
|
|
|
|
$rootScope.wallet = w;
|
2014-10-31 12:27:22 -03:00
|
|
|
w.updateFocusedTimestamp(Date.now());
|
|
|
|
|
root.redirIfLogged();
|
2014-11-07 12:22:05 -03:00
|
|
|
root.updateTxs();
|
2014-10-31 12:27:22 -03:00
|
|
|
root.updateBalance(w, function() {
|
|
|
|
|
$rootScope.$digest();
|
|
|
|
|
})
|
2014-08-22 13:13:04 -04:00
|
|
|
};
|
2014-06-16 12:44:18 -03:00
|
|
|
|
2014-10-08 10:54:26 -03:00
|
|
|
root.bindProfile = function($scope, iden, w) {
|
|
|
|
|
root.setupGlobalVariables(iden);
|
|
|
|
|
root.rebindWallets($scope, iden);
|
2014-10-15 17:18:30 -03:00
|
|
|
if (w) {
|
|
|
|
|
root.setFocusedWallet(w);
|
|
|
|
|
} else {
|
2014-11-11 16:01:33 -03:00
|
|
|
$location.path('/createWallet');
|
2014-10-15 17:18:30 -03:00
|
|
|
}
|
2014-11-01 21:49:49 -03:00
|
|
|
$timeout(function() {
|
|
|
|
|
$rootScope.$digest()
|
2014-11-01 21:56:58 -03:00
|
|
|
}, 1);
|
2014-10-08 10:54:26 -03:00
|
|
|
};
|
|
|
|
|
|
2014-10-24 12:24:44 -03:00
|
|
|
// On the focused wallet
|
2014-10-08 10:54:26 -03:00
|
|
|
root.updateAddressList = function(wid) {
|
|
|
|
|
|
|
|
|
|
if (!wid || root.isFocusedWallet(wid)) {
|
|
|
|
|
var w = $rootScope.wallet;
|
|
|
|
|
|
|
|
|
|
if (w && w.isReady()) {
|
|
|
|
|
$rootScope.addrInfos = w.getAddressesInfo();
|
|
|
|
|
}
|
2014-09-10 18:03:31 -03:00
|
|
|
}
|
2014-08-22 13:13:04 -04:00
|
|
|
};
|
2014-05-13 04:03:09 -03:00
|
|
|
|
2014-10-16 15:06:39 -03:00
|
|
|
var _balanceCache = {};
|
2014-10-16 16:02:32 -03:00
|
|
|
root.clearBalanceCache = function(w) {
|
|
|
|
|
delete _balanceCache[w.getId()];
|
|
|
|
|
};
|
|
|
|
|
|
2014-08-06 13:59:33 -03:00
|
|
|
|
2014-11-03 15:47:35 -03:00
|
|
|
root._fetchBalance = function(w, cb) {
|
2014-10-20 10:29:43 -03:00
|
|
|
cb = cb || function() {};
|
|
|
|
|
var satToUnit = 1 / w.settings.unitToSatoshi;
|
|
|
|
|
var COIN = bitcore.util.COIN;
|
2014-10-16 15:06:39 -03:00
|
|
|
|
2014-11-03 15:47:35 -03:00
|
|
|
w.getBalance(function(err, balanceSat, balanceByAddrSat, safeBalanceSat, safeUnspentCount) {
|
2014-10-20 10:29:43 -03:00
|
|
|
if (err) return cb(err);
|
2014-10-16 15:06:39 -03:00
|
|
|
|
2014-10-20 10:29:43 -03:00
|
|
|
var r = {};
|
|
|
|
|
r.totalBalance = balanceSat * satToUnit;
|
|
|
|
|
r.totalBalanceBTC = (balanceSat / COIN);
|
|
|
|
|
r.availableBalance = safeBalanceSat * satToUnit;
|
2014-11-03 15:47:35 -03:00
|
|
|
r.safeUnspentCount = safeUnspentCount;
|
2014-10-20 10:29:43 -03:00
|
|
|
r.availableBalanceBTC = (safeBalanceSat / COIN);
|
2014-06-16 12:44:18 -03:00
|
|
|
|
2014-10-20 10:29:43 -03:00
|
|
|
r.lockedBalance = (balanceSat - safeBalanceSat) * satToUnit;
|
|
|
|
|
r.lockedBalanceBTC = (balanceSat - safeBalanceSat) / COIN;
|
2014-05-13 04:03:09 -03:00
|
|
|
|
2014-10-21 18:41:54 -03:00
|
|
|
var balanceByAddr = {};
|
|
|
|
|
for (var ii in balanceByAddrSat) {
|
|
|
|
|
balanceByAddr[ii] = balanceByAddrSat[ii] * satToUnit;
|
|
|
|
|
}
|
|
|
|
|
r.balanceByAddr = balanceByAddr;
|
|
|
|
|
root.updateAddressList();
|
2014-10-20 10:29:43 -03:00
|
|
|
|
2014-11-07 13:00:40 -03:00
|
|
|
if (rateService.isAvailable()) {
|
2014-10-20 10:29:43 -03:00
|
|
|
r.totalBalanceAlternative = rateService.toFiat(balanceSat, w.settings.alternativeIsoCode);
|
|
|
|
|
r.alternativeIsoCode = w.settings.alternativeIsoCode;
|
|
|
|
|
r.lockedBalanceAlternative = rateService.toFiat(balanceSat - safeBalanceSat, w.settings.alternativeIsoCode);
|
|
|
|
|
r.alternativeConversionRate = rateService.toFiat(100000000, w.settings.alternativeIsoCode);
|
2014-11-07 13:00:40 -03:00
|
|
|
r.alternativeBalanceAvailable = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
r.updatingBalance = false;
|
|
|
|
|
|
|
|
|
|
return cb(null, r)
|
2014-10-20 10:29:43 -03:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2014-11-03 15:47:35 -03:00
|
|
|
root._updateScope = function(w, data, scope, cb) {
|
|
|
|
|
_.each(data, function(v, k) {
|
|
|
|
|
scope[k] = data[k];
|
|
|
|
|
})
|
2014-10-20 10:29:43 -03:00
|
|
|
if (cb) return cb();
|
|
|
|
|
};
|
|
|
|
|
|
2014-11-06 12:47:54 -03:00
|
|
|
root.updateBalance = function(w, cb, refreshAll) {
|
2014-10-16 15:06:39 -03:00
|
|
|
w = w || $rootScope.wallet;
|
|
|
|
|
if (!w) return root.onErrorDigest();
|
|
|
|
|
if (!w.isReady()) return;
|
|
|
|
|
|
2014-10-20 10:29:43 -03:00
|
|
|
w.balanceInfo = {};
|
2014-11-06 12:47:54 -03:00
|
|
|
var scope = root.isFocusedWallet(w.id) && !refreshAll ? $rootScope : w.balanceInfo;
|
2014-10-20 10:29:43 -03:00
|
|
|
|
2014-10-17 13:14:41 -03:00
|
|
|
root.updateAddressList();
|
2014-10-16 15:06:39 -03:00
|
|
|
|
|
|
|
|
var wid = w.getId();
|
|
|
|
|
|
|
|
|
|
if (_balanceCache[wid]) {
|
2014-10-20 10:29:43 -03:00
|
|
|
root._updateScope(w, _balanceCache[wid], scope, function() {
|
2014-11-06 12:47:54 -03:00
|
|
|
if (root.isFocusedWallet(w.id) && !refreshAll) {
|
2014-10-20 10:29:43 -03:00
|
|
|
setTimeout(function() {
|
|
|
|
|
$rootScope.$digest();
|
|
|
|
|
}, 1);
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-10-16 15:06:39 -03:00
|
|
|
} else {
|
2014-10-20 10:29:43 -03:00
|
|
|
scope.updatingBalance = true;
|
2014-10-16 15:06:39 -03:00
|
|
|
}
|
|
|
|
|
|
2014-11-03 15:47:35 -03:00
|
|
|
root._fetchBalance(w, function(err, res) {
|
2014-10-16 15:06:39 -03:00
|
|
|
if (err) throw err;
|
2014-10-20 10:29:43 -03:00
|
|
|
_balanceCache[wid] = res;
|
|
|
|
|
root._updateScope(w, _balanceCache[wid], scope, function() {
|
|
|
|
|
scope.updatingBalance = false;
|
2014-10-17 13:14:41 -03:00
|
|
|
if (cb) cb();
|
2014-10-16 15:06:39 -03:00
|
|
|
});
|
2014-08-22 13:13:04 -04:00
|
|
|
});
|
|
|
|
|
};
|
2014-08-04 13:54:08 -03:00
|
|
|
|
2014-11-07 12:22:05 -03:00
|
|
|
root.computeAlternativeAmount = function(w, tx, cb) {
|
|
|
|
|
rateService.whenAvailable(function() {
|
|
|
|
|
_.each(tx.outs, function(out) {
|
|
|
|
|
var valueSat = out.value * w.settings.unitToSatoshi;
|
|
|
|
|
out.alternativeAmount = rateService.toFiat(valueSat, w.settings.alternativeIsoCode);
|
|
|
|
|
out.alternativeIsoCode = w.settings.alternativeIsoCode;
|
2014-11-04 10:56:13 -03:00
|
|
|
});
|
2014-11-07 12:22:05 -03:00
|
|
|
if (cb) return cb(tx);
|
2014-08-22 13:13:04 -04:00
|
|
|
});
|
2014-11-07 12:22:05 -03:00
|
|
|
};
|
2014-09-29 17:36:34 -03:00
|
|
|
|
2014-11-07 12:22:05 -03:00
|
|
|
root.updateTxs = function() {
|
|
|
|
|
var w = $rootScope.wallet;
|
|
|
|
|
if (!w) return root.onErrorDigest();
|
|
|
|
|
var res = w.getPendingTxProposals();
|
2014-11-07 17:02:54 -03:00
|
|
|
_.each(res.txs, function(tx) {
|
|
|
|
|
root.computeAlternativeAmount(w, tx);
|
|
|
|
|
});
|
2014-11-07 12:22:05 -03:00
|
|
|
$rootScope.txps = res.txs;
|
|
|
|
|
if ($rootScope.pendingTxCount < res.pendingForUs) {
|
|
|
|
|
$rootScope.txAlertCount = res.pendingForUs;
|
2014-08-12 15:26:15 -04:00
|
|
|
}
|
2014-11-07 12:22:05 -03:00
|
|
|
$rootScope.pendingTxCount = res.pendingForUs;
|
2014-08-22 13:13:04 -04:00
|
|
|
};
|
2014-08-12 15:26:15 -04:00
|
|
|
|
2014-11-11 12:54:52 -03:00
|
|
|
root.deleteWallet = function($scope, w, cb) {
|
|
|
|
|
if (!w) return root.onErrorDigest();
|
2014-11-10 16:41:07 -03:00
|
|
|
var name = w.getName();
|
2014-10-21 14:26:58 -03:00
|
|
|
$rootScope.iden.deleteWallet(w.id, function() {
|
2014-11-11 12:54:52 -03:00
|
|
|
notification.info(name + ' deleted', $filter('translate')('This wallet was deleted'));
|
|
|
|
|
return cb();
|
2014-10-21 14:26:58 -03:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2014-08-22 13:13:04 -04:00
|
|
|
return root;
|
|
|
|
|
});
|