add tx modal - fix search tx

This commit is contained in:
Javier 2016-05-20 11:37:13 -03:00
commit 6f15afc638
6 changed files with 264 additions and 161 deletions

View file

@ -71,14 +71,14 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.hideBalance = function() {
storageService.getHideBalanceFlag(self.walletId, function(err, shouldHideBalance) {
if (err) self.shouldHideBalance = false;
else self.shouldHideBalance = (shouldHideBalance == 'true') ? true : false;
if (err) self.shouldHideBalance = false;
else self.shouldHideBalance = (shouldHideBalance == 'true') ? true : false;
});
}
self.onHold = function(){
self.shouldHideBalance = !self.shouldHideBalance;
storageService.setHideBalanceFlag(self.walletId, self.shouldHideBalance, function() {});
self.onHold = function() {
self.shouldHideBalance = !self.shouldHideBalance;
storageService.setHideBalanceFlag(self.walletId, self.shouldHideBalance, function() {});
}
self.setOngoingProcess = function(processName, isOn) {
@ -1353,16 +1353,19 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.coinbasePendingTransactions = lodash.isEmpty(txs) ? null : txs;
lodash.forEach(txs, function(dataFromStorage, txId) {
if ((dataFromStorage.type == 'sell' && dataFromStorage.status == 'completed') ||
(dataFromStorage.type == 'buy' && dataFromStorage.status == 'completed') ||
dataFromStorage.status == 'error' ||
(dataFromStorage.type == 'send' && dataFromStorage.status == 'completed')) return;
(dataFromStorage.type == 'buy' && dataFromStorage.status == 'completed') ||
dataFromStorage.status == 'error' ||
(dataFromStorage.type == 'send' && dataFromStorage.status == 'completed')) return;
coinbaseService.getTransaction(accessToken, accountId, txId, function(err, tx) {
if (err) {
if (err.errors[0] && err.errors[0].id == 'expired_token') {
self.refreshCoinbaseToken();
return;
}
coinbaseService.savePendingTransaction(dataFromStorage, {status: 'error', error: err}, function(err) {
coinbaseService.savePendingTransaction(dataFromStorage, {
status: 'error',
error: err
}, function(err) {
if (err) $log.debug(err);
});
return;
@ -1376,7 +1379,10 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.refreshCoinbaseToken();
return;
}
coinbaseService.savePendingTransaction(dataFromStorage, {status: 'error', error: err}, function(err) {
coinbaseService.savePendingTransaction(dataFromStorage, {
status: 'error',
error: err
}, function(err) {
if (err) $log.debug(err);
});
return;
@ -1386,8 +1392,15 @@ angular.module('copayApp.controllers').controller('indexController', function($r
if (variance < dataFromStorage.price_sensitivity.value) {
self.sellPending(tx.data);
} else {
var error = {errors: [{ message: 'Price falls over the selected percentage' }]};
coinbaseService.savePendingTransaction(dataFromStorage, {status: 'error', error: error}, function(err) {
var error = {
errors: [{
message: 'Price falls over the selected percentage'
}]
};
coinbaseService.savePendingTransaction(dataFromStorage, {
status: 'error',
error: error
}, function(err) {
if (err) $log.debug(err);
});
}
@ -1405,8 +1418,8 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}, 1000);
var _updateCoinbasePendingTransactions = function (obj/*, …*/) {
for (var i=1; i<arguments.length; i++) {
var _updateCoinbasePendingTransactions = function(obj /*, …*/ ) {
for (var i = 1; i < arguments.length; i++) {
for (var prop in arguments[i]) {
var val = arguments[i][prop];
if (typeof val == "object")
@ -1452,21 +1465,31 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.refreshCoinbaseToken();
return;
}
coinbaseService.savePendingTransaction(tx, {status: 'error', error: err}, function(err) {
coinbaseService.savePendingTransaction(tx, {
status: 'error',
error: err
}, function(err) {
if (err) $log.debug(err);
});
} else {
if (!res.data.id) {
coinbaseService.savePendingTransaction(tx, {status: 'error', error: err}, function(err) {
coinbaseService.savePendingTransaction(tx, {
status: 'error',
error: err
}, function(err) {
if (err) $log.debug(err);
});
return;
}
coinbaseService.getTransaction(self.coinbaseToken, self.coinbaseAccount.id, res.data.id, function(err, sendTx) {
coinbaseService.savePendingTransaction(tx, {remove: true}, function(err) {
coinbaseService.savePendingTransaction(tx, {
remove: true
}, function(err) {
coinbaseService.savePendingTransaction(sendTx.data, {}, function(err) {
$timeout(function() {
self.updateCoinbase({updateAccount: true});
self.updateCoinbase({
updateAccount: true
});
}, 1000);
});
});
@ -1485,22 +1508,32 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.refreshCoinbaseToken();
return;
}
coinbaseService.savePendingTransaction(tx, {status: 'error', error: err}, function(err) {
coinbaseService.savePendingTransaction(tx, {
status: 'error',
error: err
}, function(err) {
if (err) $log.debug(err);
});
} else {
if (!res.data.transaction) {
coinbaseService.savePendingTransaction(tx, {status: 'error', error: err}, function(err) {
coinbaseService.savePendingTransaction(tx, {
status: 'error',
error: err
}, function(err) {
if (err) $log.debug(err);
});
return;
}
coinbaseService.savePendingTransaction(tx, {remove: true}, function(err) {
coinbaseService.savePendingTransaction(tx, {
remove: true
}, function(err) {
coinbaseService.getTransaction(self.coinbaseToken, self.coinbaseAccount.id, res.data.transaction.id, function(err, updatedTx) {
coinbaseService.savePendingTransaction(updatedTx.data, {}, function(err) {
if (err) $log.debug(err);
$timeout(function() {
self.updateCoinbase({updateAccount: true});
self.updateCoinbase({
updateAccount: true
});
}, 1000);
});
});
@ -1691,13 +1724,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
});
});
$rootScope.$on('Local/TxModal', function(event, tx) {
self.showTx = tx;
$timeout(function() {
$rootScope.$apply();
});
});
$rootScope.$on('NewIncomingTx', function() {
self.newTx = true;
self.updateAll({

View file

@ -0,0 +1,55 @@
'use strict';
angular.module('copayApp.controllers').controller('txDetailsController', function($scope, $rootScope, $log, $filter, profileService, configService) {
var self = $scope.self;
var fc = profileService.focusedClient;
$scope.settings = configService.getSync();
$scope.copayerId = fc.credentials.copayerId;
$scope.isShared = fc.credentials.n > 1;
$scope.getAlternativeAmount = function() {
var satToBtc = 1 / 100000000;
fc.getFiatRate({
code: self.alternativeIsoCode,
ts: $scope.btx.time * 1000
}, function(err, res) {
if (err) {
$log.debug('Could not get historic rate');
return;
}
if (res && res.rate) {
var alternativeAmountBtc = ($scope.btx.amount * satToBtc).toFixed(8);
$scope.rateDate = res.fetchedOn;
$scope.rateStr = res.rate + ' ' + self.alternativeIsoCode;
$scope.alternativeAmountStr = $filter('noFractionNumber')(alternativeAmountBtc * res.rate, 2) + ' ' + self.alternativeIsoCode;
$scope.$apply();
}
});
};
$scope.getAmount = function(amount) {
return self.getAmount(amount);
};
$scope.getUnitName = function() {
return self.getUnitName();
};
$scope.getShortNetworkName = function() {
var n = fc.credentials.network;
return n.substring(0, 4);
};
$scope.copyToClipboard = function(addr) {
if (!addr) return;
self.copyToClipboard(addr);
};
$scope.cancel = function() {
$scope.txDetailsModal.hide();
$scope.txDetailsModal.remove();
};
});

View file

@ -1349,8 +1349,21 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
return this.alternativeIsoCode;
};
this.openTxModal = function(tx) {
$rootScope.$emit('Local/TxModal', tx);
this.openTxModal = function(btx) {
var self = this;
$scope.btx = btx;
$scope.self = self;
$ionicModal.fromTemplateUrl('views/modals/tx-details.html', {
scope: $scope,
backdropClickToClose: false,
hardwareBackButtonClose: false,
hideDelay: 500
}).then(function(modal) {
$scope.txDetailsModal = modal;
$scope.txDetailsModal.show();
});
};
this.hasAction = function(actions, action) {