generate new address
This commit is contained in:
parent
3068f41a66
commit
576f02d691
4 changed files with 47 additions and 19 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('addressesController', function($scope, $stateParams, $state, $timeout, $ionicScrollDelegate, configService, popupService, gettextCatalog, ongoingProcess, lodash, profileService, walletService) {
|
angular.module('copayApp.controllers').controller('addressesController', function($scope, $stateParams, $state, $timeout, $ionicScrollDelegate, configService, popupService, gettextCatalog, ongoingProcess, lodash, profileService, walletService, bwcError) {
|
||||||
var UNUSED_ADDRESS_LIMIT = 5;
|
var UNUSED_ADDRESS_LIMIT = 5;
|
||||||
var BALANCE_ADDRESS_LIMIT = 5;
|
var BALANCE_ADDRESS_LIMIT = 5;
|
||||||
var config;
|
var config;
|
||||||
|
|
@ -9,36 +9,35 @@ angular.module('copayApp.controllers').controller('addressesController', functio
|
||||||
var satToUnit;
|
var satToUnit;
|
||||||
var unitDecimals;
|
var unitDecimals;
|
||||||
var withBalance;
|
var withBalance;
|
||||||
var noBalance;
|
|
||||||
$scope.showInfo = false;
|
$scope.showInfo = false;
|
||||||
$scope.wallet = profileService.getWallet($stateParams.walletId);
|
$scope.wallet = profileService.getWallet($stateParams.walletId);
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
ongoingProcess.set('extractingWalletInfo', true);
|
ongoingProcess.set('gettingAddresses', true);
|
||||||
walletService.getMainAddresses($scope.wallet, {}, function(err, addresses) {
|
walletService.getMainAddresses($scope.wallet, {}, function(err, addresses) {
|
||||||
if (err) {
|
if (err) {
|
||||||
ongoingProcess.set('extractingWalletInfo', false);
|
ongoingProcess.set('gettingAddresses', false);
|
||||||
return popupService.showAlert(gettextCatalog.getString('Error'), err);
|
return popupService.showAlert(gettextCatalog.getString('Error'), err);
|
||||||
}
|
}
|
||||||
|
|
||||||
var allAddresses = addresses;
|
var allAddresses = addresses;
|
||||||
|
|
||||||
walletService.getBalance($scope.wallet, {}, function(err, resp) {
|
walletService.getBalance($scope.wallet, {}, function(err, resp) {
|
||||||
ongoingProcess.set('extractingWalletInfo', false);
|
ongoingProcess.set('gettingAddresses', false);
|
||||||
if (err) {
|
if (err) {
|
||||||
return popupService.showAlert(gettextCatalog.getString('Error'), err);
|
return popupService.showAlert(gettextCatalog.getString('Error'), err);
|
||||||
}
|
}
|
||||||
|
|
||||||
withBalance = resp.byAddress;
|
withBalance = resp.byAddress;
|
||||||
var idx = lodash.indexBy(withBalance, 'address');
|
var idx = lodash.indexBy(withBalance, 'address');
|
||||||
noBalance = lodash.reject(allAddresses, function(x) {
|
$scope.noBalance = lodash.reject(allAddresses, function(x) {
|
||||||
return idx[x.address];
|
return idx[x.address];
|
||||||
});
|
});
|
||||||
|
|
||||||
processPaths(noBalance);
|
processPaths($scope.noBalance);
|
||||||
processPaths(withBalance);
|
processPaths(withBalance);
|
||||||
|
|
||||||
$scope.latestUnused = lodash.slice(noBalance, 0, UNUSED_ADDRESS_LIMIT);
|
$scope.latestUnused = lodash.slice($scope.noBalance, 0, UNUSED_ADDRESS_LIMIT);
|
||||||
$scope.latestWithBalance = lodash.slice(withBalance, 0, BALANCE_ADDRESS_LIMIT);
|
$scope.latestWithBalance = lodash.slice(withBalance, 0, BALANCE_ADDRESS_LIMIT);
|
||||||
|
|
||||||
lodash.each(withBalance, function(a) {
|
lodash.each(withBalance, function(a) {
|
||||||
|
|
@ -46,9 +45,9 @@ angular.module('copayApp.controllers').controller('addressesController', functio
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.viewAll = {
|
$scope.viewAll = {
|
||||||
value: noBalance.length > UNUSED_ADDRESS_LIMIT || withBalance.length > BALANCE_ADDRESS_LIMIT
|
value: $scope.noBalance.length > UNUSED_ADDRESS_LIMIT || withBalance.length > BALANCE_ADDRESS_LIMIT
|
||||||
};
|
};
|
||||||
$scope.allAddresses = noBalance.concat(withBalance);
|
$scope.allAddresses = $scope.noBalance.concat(withBalance);
|
||||||
$scope.$digest();
|
$scope.$digest();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -60,6 +59,31 @@ angular.module('copayApp.controllers').controller('addressesController', functio
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.newAddress = function() {
|
||||||
|
ongoingProcess.set('generatingNewAddress', true);
|
||||||
|
walletService.getAddress($scope.wallet, true, function(err, addr) {
|
||||||
|
if (err) {
|
||||||
|
ongoingProcess.set('generatingNewAddress', false);
|
||||||
|
return popupService.showAlert(gettextCatalog.getString('Error'), bwcError.msg(err));
|
||||||
|
}
|
||||||
|
|
||||||
|
walletService.getMainAddresses($scope.wallet, {
|
||||||
|
limit: 1
|
||||||
|
}, function(err, _addr) {
|
||||||
|
ongoingProcess.set('generatingNewAddress', false);
|
||||||
|
if (err) return popupService.showAlert(gettextCatalog.getString('Error'), err);
|
||||||
|
if (addr != _addr[0].address) return popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('New address could not be generated. Please try again.'));
|
||||||
|
|
||||||
|
$scope.viewAll = {
|
||||||
|
value: [_addr[0]].concat($scope.latestUnused).length > UNUSED_ADDRESS_LIMIT
|
||||||
|
};
|
||||||
|
$scope.noBalance.concat(_addr[0]);
|
||||||
|
$scope.latestUnused = lodash.slice($scope.noBalance, 0, UNUSED_ADDRESS_LIMIT);
|
||||||
|
$scope.$digest();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
$scope.viewAllAddresses = function() {
|
$scope.viewAllAddresses = function() {
|
||||||
$state.go('tabs.receive.allAddresses', {
|
$state.go('tabs.receive.allAddresses', {
|
||||||
walletId: $scope.wallet.id
|
walletId: $scope.wallet.id
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,8 @@ angular.module('copayApp.services').factory('ongoingProcess', function($log, $ti
|
||||||
'validatingWords': gettext('Validating recovery phrase...'),
|
'validatingWords': gettext('Validating recovery phrase...'),
|
||||||
'loadingTxInfo': gettext('Loading transaction info...'),
|
'loadingTxInfo': gettext('Loading transaction info...'),
|
||||||
'sendingFeedback': gettext('Sending feedback...'),
|
'sendingFeedback': gettext('Sending feedback...'),
|
||||||
|
'generatingNewAddress': gettext('Generating new address...'),
|
||||||
|
'gettingAddresses': gettext('Getting addresses...'),
|
||||||
};
|
};
|
||||||
|
|
||||||
root.clear = function() {
|
root.clear = function() {
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@
|
||||||
}
|
}
|
||||||
i {
|
i {
|
||||||
font-size: 35px;
|
font-size: 35px;
|
||||||
margin-right: 5px;
|
margin-right: 2px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.item-note {
|
.item-note {
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="list">
|
<div class="list">
|
||||||
<div class="item item-divider item-icon-right" ng-click="addNewAddress()" translate>
|
<div class="item item-divider item-icon-right" ng-click="newAddress()" translate>
|
||||||
Unused Addresses
|
Unused Addresses <span ng-if="noBalance.length > 5">({{noBalance.length}})</span>
|
||||||
<i class="icon ion-ios-plus-empty"></i>
|
<i class="icon ion-ios-plus-empty"></i>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -42,13 +42,15 @@
|
||||||
<span class="item" translate>Not unused addresses available</span>
|
<span class="item" translate>Not unused addresses available</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="item item-divider" translate>
|
<div ng-if="latestWithBalance[0]">
|
||||||
Addresses With Balance
|
<div class="item item-divider" translate>
|
||||||
</div>
|
Addresses With Balance
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="item" ng-repeat="w in latestWithBalance track by $index">
|
<div class="item" ng-repeat="w in latestWithBalance track by $index">
|
||||||
{{w.address}}
|
{{w.address}}
|
||||||
<div class="addr-balance">{{w.balanceStr}}</div>
|
<div class="addr-balance">{{w.balanceStr}}</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="item item-icon-right view-all" ng-show="viewAll.value" ng-click="viewAllAddresses()">
|
<div class="item item-icon-right view-all" ng-show="viewAll.value" ng-click="viewAllAddresses()">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue