Simple refactor. Update address if receives tx
This commit is contained in:
parent
a0a6f0d645
commit
16f2c780ce
1 changed files with 22 additions and 34 deletions
|
|
@ -14,11 +14,11 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.setAddress = function() {
|
$scope.setAddress = function(newAddr) {
|
||||||
if (!$scope.wallet || $scope.generatingAddress || !$scope.wallet.isComplete()) return;
|
|
||||||
$scope.addr = null;
|
$scope.addr = null;
|
||||||
|
if (!$scope.wallet || $scope.generatingAddress || !$scope.wallet.isComplete()) return;
|
||||||
$scope.generatingAddress = true;
|
$scope.generatingAddress = true;
|
||||||
walletService.getAddress($scope.wallet, false, function(err, addr) {
|
walletService.getAddress($scope.wallet, newAddr, function(err, addr) {
|
||||||
$scope.generatingAddress = false;
|
$scope.generatingAddress = false;
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
@ -74,20 +74,6 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.updateCurrentWallet = function(wallet) {
|
|
||||||
walletService.getStatus(wallet, {}, function(err, status) {
|
|
||||||
if (err) {
|
|
||||||
return popupService.showAlert(bwcError.msg(err, gettextCatalog.getString('Could not update wallet')));
|
|
||||||
}
|
|
||||||
$timeout(function() {
|
|
||||||
$scope.wallet = profileService.getWallet(wallet.id);
|
|
||||||
$scope.wallet.status = status;
|
|
||||||
$scope.setAddress();
|
|
||||||
$scope.$apply();
|
|
||||||
}, 200);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.shouldShowReceiveAddressFromHardware = function() {
|
$scope.shouldShowReceiveAddressFromHardware = function() {
|
||||||
var wallet = $scope.wallet;
|
var wallet = $scope.wallet;
|
||||||
if (wallet.isPrivKeyExternal() && wallet.credentials.hwInfo) {
|
if (wallet.isPrivKeyExternal() && wallet.credentials.hwInfo) {
|
||||||
|
|
@ -108,36 +94,38 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi
|
||||||
$scope.wallets = profileService.getWallets();
|
$scope.wallets = profileService.getWallets();
|
||||||
$scope.singleWallet = $scope.wallets.length == 1;
|
$scope.singleWallet = $scope.wallets.length == 1;
|
||||||
|
|
||||||
|
if (!$scope.wallets[0]) return;
|
||||||
|
|
||||||
|
// select first wallet if no wallet selected previously
|
||||||
|
var selectedWallet = checkSelectedWallet($scope.wallet, $scope.wallets);
|
||||||
|
$scope.onWalletSelect(selectedWallet);
|
||||||
|
|
||||||
listeners = [
|
listeners = [
|
||||||
$rootScope.$on('bwsEvent', function(e, walletId, type, n) {
|
$rootScope.$on('bwsEvent', function(e, walletId, type, n) {
|
||||||
// Update current address
|
// Update current address
|
||||||
if ($scope.wallet && walletId == $scope.wallet.id) $scope.updateCurrentWallet($scope.wallet);
|
if ($scope.wallet && walletId == $scope.wallet.id && type == 'NewIncomingTx') $scope.setAddress(true);
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!$scope.wallets[0]) return;
|
|
||||||
if (!$scope.wallet) return $scope.init();
|
|
||||||
|
|
||||||
var w = lodash.find($scope.wallets, function(w) {
|
|
||||||
return w.id == $scope.wallet.id;
|
|
||||||
});
|
|
||||||
if (w) $scope.updateCurrentWallet($scope.wallet);
|
|
||||||
else $scope.init();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.init = function() {
|
|
||||||
$scope.wallet = $scope.wallets[0];
|
|
||||||
$scope.updateCurrentWallet($scope.wallet);
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.$on("$ionicView.leave", function(event, data) {
|
$scope.$on("$ionicView.leave", function(event, data) {
|
||||||
lodash.each(listeners, function(x) {
|
lodash.each(listeners, function(x) {
|
||||||
x();
|
x();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var checkSelectedWallet = function(wallet, wallets) {
|
||||||
|
if (!wallet) return wallets[0];
|
||||||
|
var w = lodash.find(wallets, function(w) {
|
||||||
|
return w.id == wallet.id;
|
||||||
|
});
|
||||||
|
if (!w) return wallets[0];
|
||||||
|
return wallet;
|
||||||
|
}
|
||||||
|
|
||||||
$scope.onWalletSelect = function(wallet) {
|
$scope.onWalletSelect = function(wallet) {
|
||||||
$scope.updateCurrentWallet(wallet);
|
$scope.wallet = wallet;
|
||||||
|
$scope.setAddress();
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.showWalletSelector = function() {
|
$scope.showWalletSelector = function() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue