Skip to content

Commit be7292f

Browse files
committed
[fix] Avoid to re-add an existing wallet. Fix children wallet id generation (make sure id are unique)
1 parent b80374f commit be7292f

File tree

6 files changed

+38
-19
lines changed

6 files changed

+38
-19
lines changed

www/i18n/locale-en-GB.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,8 @@
747747
"UPDATE_WALLET_LIST_FAILED": "Unable to refresh the list of wallets.",
748748
"LOAD_WALLET_LIST_FAILED": "Unable to load the list of wallets.",
749749
"SAVE_WALLET_LIST_FAILED": "Unable to save the list of wallets.",
750-
"COULD_NOT_ADD_MAIN_WALLET": "The wallet to add <b>must be different from the main account</b> with which you are connected.",
750+
"COULD_NOT_ADD_MAIN_WALLET": "This wallet <b>is the main account</b> with which you are connected. Unable to add it as a secondary wallet.",
751+
"COULD_NOT_ADD_EXISTING_WALLET": "Wallet already existing in the list.",
751752
"UNKNOWN_WALLET_ID": "Unknown secondary wallet.",
752753
"RESTORE_WALLET_LIST_FAILED": "Unable to restore the list of wallets.",
753754
"INVALID_FILE_FORMAT": "Invalid file format."

www/i18n/locale-en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,8 @@
747747
"UPDATE_WALLET_LIST_FAILED": "Unable to refresh the list of wallets.",
748748
"LOAD_WALLET_LIST_FAILED": "Unable to load the list of wallets.",
749749
"SAVE_WALLET_LIST_FAILED": "Unable to save the list of wallets.",
750-
"COULD_NOT_ADD_MAIN_WALLET": "The wallet to add <b>must be different from the main account</b> with which you are connected.",
750+
"COULD_NOT_ADD_MAIN_WALLET": "This wallet <b>is the main account</b> with which you are connected. Unable to add it as a secondary wallet.",
751+
"COULD_NOT_ADD_EXISTING_WALLET": "Wallet already existing in the list.",
751752
"UNKNOWN_WALLET_ID": "Unknown secondary wallet.",
752753
"RESTORE_WALLET_LIST_FAILED": "Unable to restore the list of wallets.",
753754
"INVALID_FILE_FORMAT": "Invalid file format."

www/i18n/locale-es-ES.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@
536536
"NO_WALLET": "Sin monedero secundaria",
537537
"BTN_DELETE": "Eliminar una monedero secundaria...",
538538
"BTN_RENAME": "Renombrar el monedero",
539+
"EXPORT_FILENAME": "monederos-{{pubkey|formatPubkey}}-{{currency}}.csv",
539540
"EDIT_POPOVER": {
540541
"TITLE": "Renombrar el monedero",
541542
"HELP": "Completa el nuevo nombre",

www/i18n/locale-fr-FR.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,8 @@
747747
"UPDATE_WALLET_LIST_FAILED": "Échec du rafraichissement des portefeuilles secondaires.",
748748
"LOAD_WALLET_LIST_FAILED": "Échec du chargement des portefeuilles secondaires.",
749749
"SAVE_WALLET_LIST_FAILED": "Échec de la sauvegarde des portefeuilles secondaires.",
750-
"COULD_NOT_ADD_MAIN_WALLET": "Le portefeuille à ajouter <b>doit être différent du compte principal</b> avec lequel vous êtes connecté.",
750+
"COULD_NOT_ADD_MAIN_WALLET": "Ce portefeuille <b>correspond au compte principal</b> avec lequel vous êtes connecté.<br/>Impossible de l'ajouter comme portefeuille secondaire",
751+
"COULD_NOT_ADD_EXISTING_WALLET": "Portefeuille déjà existant dans la liste.",
751752
"UNKNOWN_WALLET_ID": "Portefeuille secondaire inconnu.",
752753
"RESTORE_WALLET_LIST_FAILED": "Échec de la restauration des portefeuilles secondaires.",
753754
"INVALID_FILE_FORMAT": "Format de fichier invalide."

www/js/controllers/wallets-controllers.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ function WalletListController($scope, $controller, $state, $timeout, $q, $transl
175175

176176
$scope.showNewWalletModal = function() {
177177

178-
var walletId = csWallet.children.count() + 1;
179-
var wallet = csWallet.instance(walletId);
178+
var wallet = csWallet.children.instance();
180179
return wallet.login({
181180
showNewAccountLink: false,
182181
title: 'ACCOUNT.WALLET_LIST.BTN_NEW',
@@ -191,13 +190,20 @@ function WalletListController($scope, $controller, $state, $timeout, $q, $transl
191190
if (!walletData) return;
192191

193192
// Avoid to add main wallet again
194-
if (walletData.pubkey === csWallet.data.pubkey) {
193+
if (csWallet.isUserPubkey(walletData.pubkey)) {
195194
UIUtils.loading.hide();
196195
UIUtils.alert.error('ERROR.COULD_NOT_ADD_MAIN_WALLET');
197196
return;
198197
}
199198

200-
console.debug("[wallet] Adding secondary wallet {"+walletData.pubkey.substring(0,8)+"} with id=" + walletId);
199+
// Avoid to add exists wallet again
200+
if (csWallet.children.hasPubkey(walletData.pubkey)) {
201+
UIUtils.loading.hide();
202+
UIUtils.alert.error('ERROR.COULD_NOT_ADD_EXISTING_WALLET');
203+
return;
204+
}
205+
206+
console.debug("[wallet] Adding secondary wallet {"+walletData.pubkey.substring(0,8)+"}");
201207

202208
// Add the child wallet
203209
return $scope.addNewWallet(wallet)
@@ -237,11 +243,8 @@ function WalletListController($scope, $controller, $state, $timeout, $q, $transl
237243
$scope.hideActionsPopover();
238244

239245
var loginAndAddWallet = function(authData) {
240-
var walletId = csWallet.children.count() + 1;
241-
242-
console.debug("[wallet] Adding secondary wallet {"+authData.pubkey.substring(0,8)+"} with id=" + walletId);
243-
244-
var wallet = csWallet.instance(walletId);
246+
console.debug("[wallet] Adding secondary wallet {"+authData.pubkey.substring(0,8)+"}");
247+
var wallet = csWallet.children.instance();
245248
return wallet.login({
246249
authData: authData,
247250
// Load data options :

www/js/services/wallet-services.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -631,13 +631,16 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se
631631
});
632632

633633
try {
634-
_.forEach(content.children, function(child, index) {
635-
var walletId = index+1;
636-
var wallet = service.instance(walletId, BMA);
637-
wallet.data.pubkey = child.pubkey;
638-
wallet.data.localName = child.localName;
639-
wallet.data.uid = child.uid;
640-
addChildWallet(wallet, {store: false/*skip store*/});
634+
var pubkeys = {};
635+
_.forEach(content.children, function(child) {
636+
if (!pubkeys[child.pubkey]) { // make sure wallet is unique by pubkey
637+
pubkeys[child.pubkey] = true;
638+
var wallet = getNewChildrenInstance();
639+
wallet.data.pubkey = child.pubkey;
640+
wallet.data.localName = child.localName;
641+
wallet.data.uid = child.uid;
642+
addChildWallet(wallet, {store: false/*skip store*/});
643+
}
641644
});
642645
delete content.children;
643646
// childrenCount not need anymore
@@ -1997,6 +2000,14 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se
19972000
return angular.isDefined(data.childrenCount) ? data.childrenCount : (data.children && data.children.length || 0);
19982001
},
19992002

2003+
getNewChildrenInstance = function() {
2004+
// Return max(id) + 1
2005+
var walletId = (data.children && data.children.reduce(function(res, wallet) {
2006+
return Math.max(res, wallet.id);
2007+
}, 0) || data.childrenCount || 0 )+ 1;
2008+
return service.instance(walletId, BMA);
2009+
},
2010+
20002011
getAllChildrenWallet = function() {
20012012
return openEncryptedData()
20022013
.then(function() {
@@ -2348,6 +2359,7 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se
23482359
setParent: setParentWallet,
23492360
count: getChildrenWalletCount,
23502361
hasPubkey: hasChildrenWithPubkey,
2362+
instance: getNewChildrenInstance,
23512363
downloadFile: downloadChildrenWalletFile
23522364
},
23532365
api: api

0 commit comments

Comments
 (0)