Merge pull request #222 from JDonadio/ref/wallets-view
Ref/wallets view
This commit is contained in:
commit
0c81e49fac
10 changed files with 167 additions and 193 deletions
|
|
@ -28,12 +28,14 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
$scope.commentPopupClose = function() {
|
||||
commentPopup.close();
|
||||
};
|
||||
$scope.commentPopupSave = function() {
|
||||
$log.debug('Saving description: ' + $scope.data.comment);
|
||||
$scope.description = $scope.data.comment;
|
||||
$scope.commentPopupSave = function(description) {
|
||||
$log.debug('Saving description: ' + description);
|
||||
$scope.description = description;
|
||||
$scope.txp = null;
|
||||
|
||||
ongoingProcess.set('creatingTx', true);
|
||||
createTx($scope.wallet, function(err, txp) {
|
||||
ongoingProcess.set('creatingTx', false);
|
||||
if (err) return;
|
||||
cachedTxp[$scope.wallet.id] = txp;
|
||||
apply(txp);
|
||||
|
|
@ -42,7 +44,6 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
};
|
||||
};
|
||||
|
||||
|
||||
var setFromPayPro = function(uri, cb) {
|
||||
if (!cb) cb = function() {};
|
||||
|
||||
|
|
@ -92,23 +93,12 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
$scope.init = function() {
|
||||
|
||||
if ($stateParams.paypro) {
|
||||
return setFromPayPro($stateParams.paypro, function(err) {
|
||||
if (err && !isChromeApp) {
|
||||
showAlert(gettext('Could not fetch payment'));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// TODO (URL , etc)
|
||||
if (!$stateParams.toAddress || !$stateParams.toAmount) {
|
||||
$log.error('Bad params at amount')
|
||||
throw ('bad params');
|
||||
}
|
||||
|
||||
$scope.isCordova = platformInfo.isCordova;
|
||||
|
||||
var config = configService.getSync().wallet;
|
||||
|
|
@ -122,64 +112,87 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
$scope.description = $stateParams.description;
|
||||
$scope.paypro = $stateParams.paypro;
|
||||
|
||||
var network = (new bitcore.Address($scope.toAddress)).network.name;
|
||||
$scope.network = network;
|
||||
var networkName = (new bitcore.Address($scope.toAddress)).network.name;
|
||||
$scope.network = networkName;
|
||||
|
||||
function setWallets() {
|
||||
var w = profileService.getWallets({
|
||||
onlyComplete: true,
|
||||
network: network,
|
||||
$scope.notAvailable = false;
|
||||
var wallets = profileService.getWallets({
|
||||
onlyComplete: true,
|
||||
network: networkName,
|
||||
});
|
||||
|
||||
var filteredWallets = [];
|
||||
var index = 0;
|
||||
|
||||
ongoingProcess.set('scanning', true);
|
||||
|
||||
lodash.each(wallets, function(w) {
|
||||
walletService.getStatus(w, {}, function(err, status) {
|
||||
if (err) $log.error(err);
|
||||
if (!status.availableBalanceSat) $log.debug('No balance available in: ' + w.name);
|
||||
if (status.availableBalanceSat > amount) filteredWallets.push(w);
|
||||
|
||||
if (++index == wallets.length) {
|
||||
ongoingProcess.set('scanning', false);
|
||||
|
||||
if (!lodash.isEmpty(filteredWallets)) {
|
||||
$scope.wallets = lodash.clone(filteredWallets);
|
||||
$scope.notAvailable = false;
|
||||
} else {
|
||||
$scope.notAvailable = true;
|
||||
$log.warn('No wallet available to make the payment');
|
||||
}
|
||||
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
}, 10);
|
||||
return;
|
||||
}
|
||||
});
|
||||
$scope.wallets = lodash.filter(w, function(x) {
|
||||
if (!x.availableBalanceSat) return true;
|
||||
return x.availableBalanceSat > amount;
|
||||
});
|
||||
|
||||
$scope.someFiltered = $scope.wallets.length != w.length;
|
||||
|
||||
};
|
||||
|
||||
var stop;
|
||||
|
||||
function setWallet(wallet, delayed) {
|
||||
$scope.wallet = wallet;
|
||||
$scope.fee = $scope.txp = null;
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
}, 10);
|
||||
|
||||
if (stop) {
|
||||
$timeout.cancel(stop);
|
||||
stop = null;
|
||||
}
|
||||
|
||||
if (cachedTxp[wallet.id]) {
|
||||
apply(cachedTxp[wallet.id]);
|
||||
} else {
|
||||
stop = $timeout(function() {
|
||||
createTx(wallet, function(err, txp) {
|
||||
if (err) return;
|
||||
cachedTxp[wallet.id] = txp;
|
||||
apply(txp);
|
||||
});
|
||||
}, delayed ? 2000 : 1);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
txFormatService.formatAlternativeStr(amount, function(v) {
|
||||
$scope.alternativeAmountStr = v;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.$on("$ionicSlides.slideChangeEnd", function(event, data) {
|
||||
setWallet($scope.wallets[data.slider.activeIndex], true);
|
||||
});
|
||||
$scope.$on('Wallet/Changed', function(event, wallet) {
|
||||
if (lodash.isEmpty(wallet)) {
|
||||
$log.debug('No wallet provided');
|
||||
return;
|
||||
}
|
||||
$log.debug('Wallet changed: ' + wallet.name);
|
||||
setWallet(wallet, true);
|
||||
});
|
||||
|
||||
setWallets();
|
||||
setWallet($scope.wallets[0]);
|
||||
function setWallet(wallet, delayed) {
|
||||
var stop;
|
||||
$scope.wallet = wallet;
|
||||
$scope.fee = $scope.txp = null;
|
||||
|
||||
$timeout(function() {
|
||||
$ionicScrollDelegate.resize();
|
||||
}, 100);
|
||||
$scope.$apply();
|
||||
}, 10);
|
||||
|
||||
if (stop) {
|
||||
$timeout.cancel(stop);
|
||||
stop = null;
|
||||
}
|
||||
|
||||
if (cachedTxp[wallet.id]) {
|
||||
apply(cachedTxp[wallet.id]);
|
||||
} else {
|
||||
ongoingProcess.set('creatingTx', true);
|
||||
stop = $timeout(function() {
|
||||
createTx(wallet, function(err, txp) {
|
||||
ongoingProcess.set('creatingTx', false);
|
||||
if (err) return;
|
||||
cachedTxp[wallet.id] = txp;
|
||||
apply(txp);
|
||||
});
|
||||
}, delayed ? 2000 : 1);
|
||||
}
|
||||
};
|
||||
|
||||
var setSendError = function(msg) {
|
||||
|
|
@ -244,7 +257,6 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
});
|
||||
};
|
||||
|
||||
|
||||
$scope.openPPModal = function() {
|
||||
$ionicModal.fromTemplateUrl('views/modals/paypro.html', {
|
||||
scope: $scope
|
||||
|
|
@ -254,8 +266,6 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
$scope.approve = function() {
|
||||
var wallet = $scope.wallet;
|
||||
var txp = $scope.txp;
|
||||
|
|
@ -287,7 +297,4 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
$scope.cancel = function() {
|
||||
$state.transitionTo('tabs.send');
|
||||
};
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,65 +1,54 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('tabReceiveController', function($scope, $ionicPopover, $timeout, platformInfo, nodeWebkit, walletService, profileService, configService, lodash, gettextCatalog) {
|
||||
angular.module('copayApp.controllers').controller('tabReceiveController', function($scope, $timeout, $log, platformInfo, walletService, profileService, configService, lodash, gettextCatalog) {
|
||||
|
||||
$scope.isCordova = platformInfo.isCordova;
|
||||
|
||||
$scope.init = function() {
|
||||
$scope.index = 0;
|
||||
$scope.wallets = profileService.getWallets({
|
||||
onlyComplete: true
|
||||
});
|
||||
$scope.isCordova = platformInfo.isCordova;
|
||||
$scope.isNW = platformInfo.isNW;
|
||||
$scope.setWallets();
|
||||
$scope.setAddress(false);
|
||||
$scope.options = {
|
||||
loop: false,
|
||||
effect: 'flip',
|
||||
speed: 500,
|
||||
spaceBetween: 100
|
||||
}
|
||||
|
||||
$scope.$on("$ionicSlides.sliderInitialized", function(event, data) {
|
||||
// data.slider is the instance of Swiper
|
||||
$scope.slider = data.slider;
|
||||
});
|
||||
|
||||
$scope.$on("$ionicSlides.slideChangeStart", function(event, data) {
|
||||
console.log('Slide change is beginning');
|
||||
});
|
||||
|
||||
$scope.$on("$ionicSlides.slideChangeEnd", function(event, data) {
|
||||
$scope.index = data.slider.activeIndex;
|
||||
$scope.setAddress();
|
||||
});
|
||||
}
|
||||
|
||||
$scope.$on('Wallet/Changed', function(event, wallet) {
|
||||
if (lodash.isEmpty(wallet)) {
|
||||
$log.debug('No wallet provided');
|
||||
return;
|
||||
}
|
||||
$scope.defaultWallet = wallet;
|
||||
$log.debug('Wallet changed: ' + wallet.name);
|
||||
$scope.setAddress(wallet);
|
||||
});
|
||||
|
||||
$scope.shareAddress = function(addr) {
|
||||
if ($scope.isCordova) {
|
||||
window.plugins.socialsharing.share('bitcoin:' + addr, null, null, null);
|
||||
}
|
||||
};
|
||||
|
||||
$scope.setAddress = function(forceNew) {
|
||||
$scope.setAddress = function(wallet, forceNew) {
|
||||
var wallet = wallet || $scope.defaultWallet;
|
||||
if ($scope.generatingAddress) return;
|
||||
|
||||
$scope.addr = null;
|
||||
$scope.addrError = null;
|
||||
$scope.error = null;
|
||||
|
||||
var wallet = $scope.wallets[$scope.index];
|
||||
if (!wallet.isComplete()) {
|
||||
$scope.incomplete = true;
|
||||
if (wallet && !wallet.isComplete()) {
|
||||
$timeout(function() {
|
||||
$scope.$digest();
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
$scope.incomplete = false;
|
||||
$scope.generatingAddress = true;
|
||||
|
||||
$timeout(function() {
|
||||
walletService.getAddress($scope.wallets[$scope.index], forceNew, function(err, addr) {
|
||||
walletService.getAddress(wallet, forceNew, function(err, addr) {
|
||||
$scope.generatingAddress = false;
|
||||
if (err) {
|
||||
$scope.addrError = err;
|
||||
$scope.error = err;
|
||||
} else {
|
||||
if (addr)
|
||||
$scope.addr = addr;
|
||||
|
|
@ -68,10 +57,4 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi
|
|||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
$scope.setWallets = function() {
|
||||
$scope.wallets = profileService.getWallets();
|
||||
};
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -142,4 +142,23 @@ angular.module('copayApp.directives')
|
|||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
.directive('wallets', function($log, profileService, walletService, lodash) {
|
||||
return {
|
||||
restrict: 'E',
|
||||
templateUrl: 'views/includes/wallets.html',
|
||||
scope: {
|
||||
wallets: '=wallets'
|
||||
},
|
||||
link: function(scope, element, attrs) {
|
||||
scope.$on("$ionicSlides.sliderInitialized", function(event, data) {
|
||||
scope.slider = data.slider;
|
||||
scope.$emit('Wallet/Changed', scope.wallets ? scope.wallets[0] : null);
|
||||
});
|
||||
|
||||
scope.$on("$ionicSlides.slideChangeEnd", function(event, data) {
|
||||
scope.$emit('Wallet/Changed', scope.wallets ? scope.wallets[data.slider.activeIndex] : null);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -881,6 +881,9 @@ input[type=file] {
|
|||
width: inherit;
|
||||
}
|
||||
|
||||
.wallets {
|
||||
height: 105px;
|
||||
}
|
||||
/*
|
||||
* Calculator
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue