ref process txps
This commit is contained in:
parent
4809050ae4
commit
bb0eec5097
4 changed files with 128 additions and 67 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('preferencesDeleteWalletController',
|
angular.module('copayApp.controllers').controller('preferencesDeleteWalletController',
|
||||||
function($scope, $ionicPopup, $stateParams, lodash, notification, profileService, $state, gettextCatalog, ongoingProcess) {
|
function($scope, $ionicPopup, $stateParams, lodash, profileService, $state, gettextCatalog, ongoingProcess) {
|
||||||
var wallet = profileService.getWallet($stateParams.walletId);
|
var wallet = profileService.getWallet($stateParams.walletId);
|
||||||
$scope.alias = lodash.isEqual(wallet.name, wallet.credentials.walletName) ? null : wallet.name + ' ';
|
$scope.alias = lodash.isEqual(wallet.name, wallet.credentials.walletName) ? null : wallet.name + ' ';
|
||||||
$scope.walletName = '[' + wallet.credentials.walletName + ']';
|
$scope.walletName = '[' + wallet.credentials.walletName + ']';
|
||||||
|
|
@ -39,9 +39,6 @@ angular.module('copayApp.controllers').controller('preferencesDeleteWalletContro
|
||||||
$scope.error = err.message || err;
|
$scope.error = err.message || err;
|
||||||
} else {
|
} else {
|
||||||
$state.go('tabs.home');
|
$state.go('tabs.home');
|
||||||
notification.success(gettextCatalog.getString('Success'), gettextCatalog.getString('The wallet "{{walletName}}" was deleted', {
|
|
||||||
walletName: walletName
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
angular.module('copayApp.controllers').controller('tabHomeController',
|
angular.module('copayApp.controllers').controller('tabHomeController',
|
||||||
function($rootScope, $timeout, $scope, $state, lodash, profileService, walletService, configService, txFormatService, $ionicModal, $log, platformInfo) {
|
function($rootScope, $timeout, $scope, $state, lodash, profileService, walletService, configService, txFormatService, $ionicModal, $log, platformInfo) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
$scope.txps = [];
|
||||||
|
|
||||||
self.setWallets = function() {
|
self.setWallets = function() {
|
||||||
$scope.wallets = profileService.getWallets();
|
$scope.wallets = profileService.getWallets();
|
||||||
|
|
@ -15,69 +16,11 @@ angular.module('copayApp.controllers').controller('tabHomeController',
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$scope.txps = lodash.sortBy(txps, 'createdOn').reverse();
|
$scope.txps = lodash.sortBy(txps, 'createdOn').reverse();
|
||||||
};
|
|
||||||
|
|
||||||
var formatPendingTxps = function(txps) {
|
console.log('[tab-home.js.18]', $scope.txps); //TODO
|
||||||
$scope.pendingTxProposalsCountForUs = 0;
|
|
||||||
var now = Math.floor(Date.now() / 1000);
|
|
||||||
|
|
||||||
/* To test multiple outputs...
|
|
||||||
var txp = {
|
|
||||||
message: 'test multi-output',
|
|
||||||
fee: 1000,
|
|
||||||
createdOn: new Date() / 1000,
|
|
||||||
outputs: []
|
|
||||||
};
|
|
||||||
function addOutput(n) {
|
|
||||||
txp.outputs.push({
|
|
||||||
amount: 600,
|
|
||||||
toAddress: '2N8bhEwbKtMvR2jqMRcTCQqzHP6zXGToXcK',
|
|
||||||
message: 'output #' + (Number(n) + 1)
|
|
||||||
});
|
|
||||||
};
|
|
||||||
lodash.times(150, addOutput);
|
|
||||||
txps.push(txp);
|
|
||||||
*/
|
|
||||||
|
|
||||||
lodash.each(txps, function(tx) {
|
|
||||||
|
|
||||||
tx = txFormatService.processTx(tx);
|
|
||||||
|
|
||||||
// no future transactions...
|
|
||||||
if (tx.createdOn > now)
|
|
||||||
tx.createdOn = now;
|
|
||||||
|
|
||||||
tx.wallet = profileService.getWallet(tx.walletId);
|
|
||||||
if (!tx.wallet) {
|
|
||||||
$log.error("no wallet at txp?");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var action = lodash.find(tx.actions, {
|
|
||||||
copayerId: tx.wallet.copayerId
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!action && tx.status == 'pending') {
|
|
||||||
tx.pendingForUs = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (action && action.type == 'accept') {
|
|
||||||
tx.statusForUs = 'accepted';
|
|
||||||
} else if (action && action.type == 'reject') {
|
|
||||||
tx.statusForUs = 'rejected';
|
|
||||||
} else {
|
|
||||||
tx.statusForUs = 'pending';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!tx.deleteLockTime)
|
|
||||||
tx.canBeRemoved = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
return txps;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
self.updateAllWallets = function() {
|
self.updateAllWallets = function() {
|
||||||
|
|
||||||
$scope.wallets = profileService.getWallets();
|
$scope.wallets = profileService.getWallets();
|
||||||
|
|
||||||
var txps = [];
|
var txps = [];
|
||||||
|
|
@ -87,12 +30,12 @@ angular.module('copayApp.controllers').controller('tabHomeController',
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log('[tab-home.js.35:err:]', $log.error(err)); //TODO
|
console.log('[tab-home.js.35:err:]', $log.error(err)); //TODO
|
||||||
return;
|
return;
|
||||||
} // TODO
|
}
|
||||||
|
|
||||||
if (status.pendingTxps && status.pendingTxps[0]) {
|
if (status.pendingTxps && status.pendingTxps[0]) {
|
||||||
txps = txps.concat(status.pendingTxps);
|
txps = txps.concat(status.pendingTxps);
|
||||||
}
|
}
|
||||||
if (--i == 0) {
|
if (--i == 0) {
|
||||||
txps = formatPendingTxps(txps);
|
|
||||||
setPendingTxps(txps);
|
setPendingTxps(txps);
|
||||||
}
|
}
|
||||||
wallet.status = status;
|
wallet.status = status;
|
||||||
|
|
@ -116,7 +59,6 @@ angular.module('copayApp.controllers').controller('tabHomeController',
|
||||||
|
|
||||||
if ( (status.pendingTxps && status.pendingTxps[0]) || wasAny ) {
|
if ( (status.pendingTxps && status.pendingTxps[0]) || wasAny ) {
|
||||||
txps = txps.concat(status.pendingTxps);
|
txps = txps.concat(status.pendingTxps);
|
||||||
txps = formatPendingTxps(txps);
|
|
||||||
setPendingTxps(txps);
|
setPendingTxps(txps);
|
||||||
}
|
}
|
||||||
wallet.status = status;
|
wallet.status = status;
|
||||||
|
|
|
||||||
|
|
@ -75,5 +75,64 @@ angular.module('copayApp.services').factory('txFormatService', function(bwcServi
|
||||||
return tx;
|
return tx;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
root.formatPendingTxps = function(txps) {
|
||||||
|
$scope.pendingTxProposalsCountForUs = 0;
|
||||||
|
var now = Math.floor(Date.now() / 1000);
|
||||||
|
|
||||||
|
/* To test multiple outputs...
|
||||||
|
var txp = {
|
||||||
|
message: 'test multi-output',
|
||||||
|
fee: 1000,
|
||||||
|
createdOn: new Date() / 1000,
|
||||||
|
outputs: []
|
||||||
|
};
|
||||||
|
function addOutput(n) {
|
||||||
|
txp.outputs.push({
|
||||||
|
amount: 600,
|
||||||
|
toAddress: '2N8bhEwbKtMvR2jqMRcTCQqzHP6zXGToXcK',
|
||||||
|
message: 'output #' + (Number(n) + 1)
|
||||||
|
});
|
||||||
|
};
|
||||||
|
lodash.times(150, addOutput);
|
||||||
|
txps.push(txp);
|
||||||
|
*/
|
||||||
|
|
||||||
|
lodash.each(txps, function(tx) {
|
||||||
|
|
||||||
|
tx = txFormatService.processTx(tx);
|
||||||
|
|
||||||
|
// no future transactions...
|
||||||
|
if (tx.createdOn > now)
|
||||||
|
tx.createdOn = now;
|
||||||
|
|
||||||
|
tx.wallet = profileService.getWallet(tx.walletId);
|
||||||
|
if (!tx.wallet) {
|
||||||
|
$log.error("no wallet at txp?");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var action = lodash.find(tx.actions, {
|
||||||
|
copayerId: tx.wallet.copayerId
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!action && tx.status == 'pending') {
|
||||||
|
tx.pendingForUs = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action && action.type == 'accept') {
|
||||||
|
tx.statusForUs = 'accepted';
|
||||||
|
} else if (action && action.type == 'reject') {
|
||||||
|
tx.statusForUs = 'rejected';
|
||||||
|
} else {
|
||||||
|
tx.statusForUs = 'pending';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!tx.deleteLockTime)
|
||||||
|
tx.canBeRemoved = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
return txps;
|
||||||
|
};
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,68 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
|
||||||
root.getStatus = function(wallet, opts, cb) {
|
root.getStatus = function(wallet, opts, cb) {
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
|
|
||||||
|
|
||||||
|
function processPendingTxps(status) {
|
||||||
|
var txps = status.pendingTxps;
|
||||||
|
var now = Math.floor(Date.now() / 1000);
|
||||||
|
|
||||||
|
/* To test multiple outputs...
|
||||||
|
var txp = {
|
||||||
|
message: 'test multi-output',
|
||||||
|
fee: 1000,
|
||||||
|
createdOn: new Date() / 1000,
|
||||||
|
outputs: []
|
||||||
|
};
|
||||||
|
function addOutput(n) {
|
||||||
|
txp.outputs.push({
|
||||||
|
amount: 600,
|
||||||
|
toAddress: '2N8bhEwbKtMvR2jqMRcTCQqzHP6zXGToXcK',
|
||||||
|
message: 'output #' + (Number(n) + 1)
|
||||||
|
});
|
||||||
|
};
|
||||||
|
lodash.times(150, addOutput);
|
||||||
|
txps.push(txp);
|
||||||
|
*/
|
||||||
|
|
||||||
|
lodash.each(txps, function(tx) {
|
||||||
|
|
||||||
|
tx = txFormatService.processTx(tx);
|
||||||
|
|
||||||
|
// no future transactions...
|
||||||
|
if (tx.createdOn > now)
|
||||||
|
tx.createdOn = now;
|
||||||
|
|
||||||
|
tx.wallet = wallet;
|
||||||
|
|
||||||
|
if (!tx.wallet) {
|
||||||
|
$log.error("no wallet at txp?");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var action = lodash.find(tx.actions, {
|
||||||
|
copayerId: tx.wallet.copayerId
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!action && tx.status == 'pending') {
|
||||||
|
tx.pendingForUs = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action && action.type == 'accept') {
|
||||||
|
tx.statusForUs = 'accepted';
|
||||||
|
} else if (action && action.type == 'reject') {
|
||||||
|
tx.statusForUs = 'rejected';
|
||||||
|
} else {
|
||||||
|
tx.statusForUs = 'pending';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!tx.deleteLockTime)
|
||||||
|
tx.canBeRemoved = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
wallet.pendingTxps = txps;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
function get(cb) {
|
function get(cb) {
|
||||||
wallet.getStatus({
|
wallet.getStatus({
|
||||||
twoStep: true
|
twoStep: true
|
||||||
|
|
@ -238,11 +300,12 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
|
||||||
}, root.WALLET_STATUS_DELAY_BETWEEN_TRIES * tries);
|
}, root.WALLET_STATUS_DELAY_BETWEEN_TRIES * tries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
processPendingTxps(status);
|
||||||
|
|
||||||
$log.debug('Got Wallet Status for:' + wallet.credentials.walletName);
|
$log.debug('Got Wallet Status for:' + wallet.credentials.walletName);
|
||||||
|
|
||||||
cacheStatus(status);
|
cacheStatus(status);
|
||||||
|
|
||||||
// wallet.setPendingTxps(status.pendingTxps);
|
|
||||||
return cb(null, status);
|
return cb(null, status);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue