refactor call tx modal

This commit is contained in:
Javier 2016-09-20 16:21:05 -03:00
commit 1cfd4c733f
8 changed files with 90 additions and 77 deletions

View file

@ -19,7 +19,7 @@
<div ng-if="!fetchingNotifications"> <div ng-if="!fetchingNotifications">
<div class="list card"> <div class="list card">
<div class="item" ng-repeat="x in notifications" ng-click="x.action()"> <div class="item" ng-repeat="notification in notifications" ng-click="openTxModal(notification)">
<span ng-include="'views/includes/walletActivity.html'"></span> <span ng-include="'views/includes/walletActivity.html'"></span>
</div> </div>

View file

@ -9,7 +9,7 @@
</ion-header-bar> </ion-header-bar>
<ion-content> <ion-content>
<div class="header-modal text-center" ng-if="!loadingTxInfo" ng-init="showRate = false"> <div class="header-modal text-center" ng-init="showRate = false">
<div ng-show="btx.action != 'invalid'"> <div ng-show="btx.action != 'invalid'">
<i class="icon big-icon-svg"> <i class="icon big-icon-svg">
@ -53,7 +53,7 @@
</div> </div>
</div> </div>
<div class="list" ng-if="!loadingTxInfo"> <div class="list">
<div class="item item-icon-left" ng-show="btx.action == 'sent'"> <div class="item item-icon-left" ng-show="btx.action == 'sent'">
<i class="icon ion-social-bitcoin-outline"></i> <i class="icon ion-social-bitcoin-outline"></i>
<div ng-if="!btx.hasMultiplesOutputs && btx.addressTo && btx.addressTo != 'N/A'" copy-to-clipboard="btx.addressTo"> <div ng-if="!btx.hasMultiplesOutputs && btx.addressTo && btx.addressTo != 'N/A'" copy-to-clipboard="btx.addressTo">

View file

@ -30,7 +30,7 @@
<span class="badge badge-assertive" ng-show="txpsN>3" translate> {{txpsN}}</span> <span class="badge badge-assertive" ng-show="txpsN>3" translate> {{txpsN}}</span>
</a> </a>
<a ng-repeat="tx in txps" class="item" ng-click="openTxpModal(tx)"> <a ng-repeat="tx in txps" class="item" ng-click="openTxpModal(tx)">
<span ng-include="'views/includes/txp.html'"></span> <span ng-include="'views/includes/txp.html'"></span>
</a> </a>
</div> </div>

View file

@ -1,10 +1,7 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('activityController', angular.module('copayApp.controllers').controller('activityController',
function($rootScope, $timeout, $scope, $state, lodash, profileService, walletService, configService, txFormatService, $ionicModal, $log, platformInfo) { function($timeout, $scope, $log, $ionicModal, lodash, profileService, walletService, ongoingProcess, popupService, gettextCatalog) {
var self = this;
$scope.init = function() { $scope.init = function() {
$scope.fetchingNotifications = true; $scope.fetchingNotifications = true;
profileService.getNotifications(50, function(err, n) { profileService.getNotifications(50, function(err, n) {
@ -19,4 +16,32 @@ angular.module('copayApp.controllers').controller('activityController',
}, 1); }, 1);
}); });
} }
$scope.openTxModal = function(n) {
var wallet = profileService.getWallet(n.walletId);
ongoingProcess.set('loadingTxInfo', true);
walletService.getTx(wallet, n.txid, function(err, tx) {
ongoingProcess.set('loadingTxInfo', false);
if (err) {
$log.error(err);
return popupService.showAlert(gettextCatalog.getString('Error'), err);
}
if (!tx) {
$log.warn('No tx found');
return popupService.showAlert(gettextCatalog.getString('Transaction not found'), null);
}
$scope.wallet = wallet;
$scope.btx = lodash.cloneDeep(tx);
$ionicModal.fromTemplateUrl('views/modals/tx-details.html', {
scope: $scope
}).then(function(modal) {
$scope.txDetailsModal = modal;
$scope.txDetailsModal.show();
});
});
};
}); });

View file

@ -1,64 +1,32 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('txDetailsController', function($log, $timeout, $scope, $filter, $stateParams, ongoingProcess, walletService, lodash, gettextCatalog, profileService, configService, txFormatService, externalLinkService, popupService) { angular.module('copayApp.controllers').controller('txDetailsController', function($log, $timeout, $scope, $filter, $stateParams, ongoingProcess, walletService, lodash, gettextCatalog, profileService, configService, txFormatService, externalLinkService, popupService) {
var self = $scope.self;
var wallet = profileService.getWallet($stateParams.walletId || $scope.walletId);
var config = configService.getSync(); var config = configService.getSync();
var configWallet = config.wallet; var configWallet = config.wallet;
var walletSettings = configWallet.settings; var walletSettings = configWallet.settings;
var wallet;
$scope.title = gettextCatalog.getString('Transaction'); $scope.title = gettextCatalog.getString('Transaction');
$scope.loadingTxInfo = false;
$scope.init = function() { $scope.init = function() {
$scope.loadingTxInfo = true; wallet = $scope.wallet;
ongoingProcess.set('loadingTxInfo', true); $scope.alternativeIsoCode = walletSettings.alternativeIsoCode;
findTx($scope.txid, function(err, tx) { $scope.color = wallet.color;
ongoingProcess.set('loadingTxInfo', false); $scope.copayerId = wallet.credentials.copayerId;
$scope.loadingTxInfo = false; $scope.isShared = wallet.credentials.n > 1;
if (err) { $scope.btx.feeLevel = walletSettings.feeLevel;
$log.error(err);
popupService.showAlert(gettextCatalog.getString('Error'), err);
return $scope.cancel();
}
if (!tx) { if ($scope.btx.action != 'invalid') {
$log.warn('No tx found'); if ($scope.btx.action == 'sent') $scope.title = gettextCatalog.getString('Sent Funds');
popupService.showAlert(gettextCatalog.getString('Transaction not found'), null); if ($scope.btx.action == 'received') $scope.title = gettextCatalog.getString('Received Funds');
return $scope.cancel(); if ($scope.btx.action == 'moved') $scope.title = gettextCatalog.getString('Moved Funds');
} }
$scope.btx = lodash.cloneDeep(tx); initActionList();
$scope.alternativeIsoCode = walletSettings.alternativeIsoCode; getAlternativeAmount();
$scope.color = wallet.color;
$scope.copayerId = wallet.credentials.copayerId;
$scope.isShared = wallet.credentials.n > 1;
$scope.btx.feeLevel = walletSettings.feeLevel;
if ($scope.btx.action != 'invalid') { $timeout(function() {
if ($scope.btx.action == 'sent') $scope.title = gettextCatalog.getString('Sent Funds'); $scope.$apply();
if ($scope.btx.action == 'received') $scope.title = gettextCatalog.getString('Received Funds'); }, 100);
if ($scope.btx.action == 'moved') $scope.title = gettextCatalog.getString('Moved Funds');
}
initActionList();
getAlternativeAmount();
$timeout(function() {
$scope.$apply();
}, 10);
});
};
function findTx(txid, cb) {
walletService.getTxHistory(wallet, {}, function(err, txHistory) {
if (err) return cb(err);
var tx = lodash.find(txHistory, {
txid: txid
});
return cb(null, tx);
});
}; };
function initActionList() { function initActionList() {
@ -158,8 +126,5 @@ angular.module('copayApp.controllers').controller('txDetailsController', functio
$scope.cancel = function() { $scope.cancel = function() {
$scope.txDetailsModal.hide(); $scope.txDetailsModal.hide();
$timeout(function() {
$scope.txDetailsModal.remove();
}, 10);
}; };
}); });

View file

@ -1,7 +1,7 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('tabHomeController', angular.module('copayApp.controllers').controller('tabHomeController',
function($rootScope, $timeout, $scope, $state, $stateParams, $ionicModal, $ionicScrollDelegate, lodash, profileService, walletService, configService, $log, platformInfo, storageService, txpModalService, $window) { function($rootScope, $timeout, $scope, $state, $stateParams, $ionicModal, $ionicScrollDelegate, gettextCatalog, lodash, popupService, ongoingProcess, profileService, walletService, configService, $log, platformInfo, storageService, txpModalService, $window) {
$scope.externalServices = {}; $scope.externalServices = {};
$scope.bitpayCardEnabled = true; // TODO $scope.bitpayCardEnabled = true; // TODO
$scope.openTxpModal = txpModalService.open; $scope.openTxpModal = txpModalService.open;
@ -17,13 +17,30 @@ angular.module('copayApp.controllers').controller('tabHomeController',
}); });
$scope.openTxModal = function(n) { $scope.openTxModal = function(n) {
$scope.txid = n.txid; var wallet = profileService.getWallet(n.walletId);
$scope.walletId = n.walletId;
$ionicModal.fromTemplateUrl('views/modals/tx-details.html', { ongoingProcess.set('loadingTxInfo', true);
scope: $scope walletService.getTx(wallet, n.txid, function(err, tx) {
}).then(function(modal) { ongoingProcess.set('loadingTxInfo', false);
$scope.txDetailsModal = modal;
$scope.txDetailsModal.show(); if (err) {
$log.error(err);
return popupService.showAlert(gettextCatalog.getString('Error'), err);
}
if (!tx) {
$log.warn('No tx found');
return popupService.showAlert(gettextCatalog.getString('Transaction not found'), null);
}
$scope.wallet = wallet;
$scope.btx = lodash.cloneDeep(tx);
$ionicModal.fromTemplateUrl('views/modals/tx-details.html', {
scope: $scope
}).then(function(modal) {
$scope.txDetailsModal = modal;
$scope.txDetailsModal.show();
});
}); });
}; };

View file

@ -131,18 +131,13 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
$scope.close = function() { $scope.close = function() {
$scope.searchModal.hide(); $scope.searchModal.hide();
} }
}; };
$scope.openTxModal = function(btx) { $scope.openTxModal = function(btx) {
var self = this;
$scope.btx = lodash.cloneDeep(btx); $scope.btx = lodash.cloneDeep(btx);
$scope.self = self; $scope.walletId = wallet.id;
$ionicModal.fromTemplateUrl('views/modals/tx-details.html', { $ionicModal.fromTemplateUrl('views/modals/tx-details.html', {
scope: $scope, scope: $scope
hideDelay: 500
}).then(function(modal) { }).then(function(modal) {
$scope.txDetailsModal = modal; $scope.txDetailsModal = modal;
$scope.txDetailsModal.show(); $scope.txDetailsModal.show();

View file

@ -502,6 +502,17 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
}); });
}; };
root.getTx = function(wallet, txid, cb) {
root.getTxHistory(wallet, {}, function(err, txHistory) {
if (err) return cb(err);
var tx = lodash.find(txHistory, {
txid: txid
});
return cb(null, tx);
});
};
root.getTxHistory = function(wallet, opts, cb) { root.getTxHistory = function(wallet, opts, cb) {
opts = opts || {}; opts = opts || {};