diff --git a/www/i18n/locale-en-GB.json b/www/i18n/locale-en-GB.json index 5ee1cda1a8e32d1026034aa8318677e7c961b74f..67fefa663a19988c768ec97584f264ed3332a0ba 100644 --- a/www/i18n/locale-en-GB.json +++ b/www/i18n/locale-en-GB.json @@ -747,7 +747,8 @@ "UPDATE_WALLET_LIST_FAILED": "Unable to refresh the list of wallets.", "LOAD_WALLET_LIST_FAILED": "Unable to load the list of wallets.", "SAVE_WALLET_LIST_FAILED": "Unable to save the list of wallets.", - "COULD_NOT_ADD_MAIN_WALLET": "The wallet to add <b>must be different from the main account</b> with which you are connected.", + "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.", + "COULD_NOT_ADD_EXISTING_WALLET": "Wallet already existing in the list.", "UNKNOWN_WALLET_ID": "Unknown secondary wallet.", "RESTORE_WALLET_LIST_FAILED": "Unable to restore the list of wallets.", "INVALID_FILE_FORMAT": "Invalid file format." diff --git a/www/i18n/locale-en.json b/www/i18n/locale-en.json index 1df269ec1dfefd374dcc6c3365595f9684788fed..b5c2347a72c90e4ab07e6dd2c2d92b6a67c1b214 100644 --- a/www/i18n/locale-en.json +++ b/www/i18n/locale-en.json @@ -747,7 +747,8 @@ "UPDATE_WALLET_LIST_FAILED": "Unable to refresh the list of wallets.", "LOAD_WALLET_LIST_FAILED": "Unable to load the list of wallets.", "SAVE_WALLET_LIST_FAILED": "Unable to save the list of wallets.", - "COULD_NOT_ADD_MAIN_WALLET": "The wallet to add <b>must be different from the main account</b> with which you are connected.", + "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.", + "COULD_NOT_ADD_EXISTING_WALLET": "Wallet already existing in the list.", "UNKNOWN_WALLET_ID": "Unknown secondary wallet.", "RESTORE_WALLET_LIST_FAILED": "Unable to restore the list of wallets.", "INVALID_FILE_FORMAT": "Invalid file format." diff --git a/www/i18n/locale-es-ES.json b/www/i18n/locale-es-ES.json index e3a4c5e78e96c1732eec6aff36f6ad87c1f1b1e6..694cace4670f8bb846a98c6f620f30dfbbc94157 100644 --- a/www/i18n/locale-es-ES.json +++ b/www/i18n/locale-es-ES.json @@ -536,6 +536,7 @@ "NO_WALLET": "Sin monedero secundaria", "BTN_DELETE": "Eliminar una monedero secundaria...", "BTN_RENAME": "Renombrar el monedero", + "EXPORT_FILENAME": "monederos-{{pubkey|formatPubkey}}-{{currency}}.csv", "EDIT_POPOVER": { "TITLE": "Renombrar el monedero", "HELP": "Completa el nuevo nombre", diff --git a/www/i18n/locale-fr-FR.json b/www/i18n/locale-fr-FR.json index d9c0ce9e18a196bb502a2a3dea8e02ad86df4715..0534293ba8ad5b60cf5a8741afca176a9d32c4c4 100644 --- a/www/i18n/locale-fr-FR.json +++ b/www/i18n/locale-fr-FR.json @@ -747,7 +747,8 @@ "UPDATE_WALLET_LIST_FAILED": "Échec du rafraichissement des portefeuilles secondaires.", "LOAD_WALLET_LIST_FAILED": "Échec du chargement des portefeuilles secondaires.", "SAVE_WALLET_LIST_FAILED": "Échec de la sauvegarde des portefeuilles secondaires.", - "COULD_NOT_ADD_MAIN_WALLET": "Le portefeuille à ajouter <b>doit être différent du compte principal</b> avec lequel vous êtes connecté.", + "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", + "COULD_NOT_ADD_EXISTING_WALLET": "Portefeuille déjà existant dans la liste.", "UNKNOWN_WALLET_ID": "Portefeuille secondaire inconnu.", "RESTORE_WALLET_LIST_FAILED": "Échec de la restauration des portefeuilles secondaires.", "INVALID_FILE_FORMAT": "Format de fichier invalide." diff --git a/www/js/controllers/wallets-controllers.js b/www/js/controllers/wallets-controllers.js index 69313a0792fc9bf0dcd8d7e588d62aad9c3643e2..2c85f8f4f1ac8da3d9b2c8d9884b0de90a8a1615 100644 --- a/www/js/controllers/wallets-controllers.js +++ b/www/js/controllers/wallets-controllers.js @@ -175,8 +175,7 @@ function WalletListController($scope, $controller, $state, $timeout, $q, $transl $scope.showNewWalletModal = function() { - var walletId = csWallet.children.count() + 1; - var wallet = csWallet.instance(walletId); + var wallet = csWallet.children.instance(); return wallet.login({ showNewAccountLink: false, title: 'ACCOUNT.WALLET_LIST.BTN_NEW', @@ -191,13 +190,20 @@ function WalletListController($scope, $controller, $state, $timeout, $q, $transl if (!walletData) return; // Avoid to add main wallet again - if (walletData.pubkey === csWallet.data.pubkey) { + if (csWallet.isUserPubkey(walletData.pubkey)) { UIUtils.loading.hide(); UIUtils.alert.error('ERROR.COULD_NOT_ADD_MAIN_WALLET'); return; } - console.debug("[wallet] Adding secondary wallet {"+walletData.pubkey.substring(0,8)+"} with id=" + walletId); + // Avoid to add exists wallet again + if (csWallet.children.hasPubkey(walletData.pubkey)) { + UIUtils.loading.hide(); + UIUtils.alert.error('ERROR.COULD_NOT_ADD_EXISTING_WALLET'); + return; + } + + console.debug("[wallet] Adding secondary wallet {"+walletData.pubkey.substring(0,8)+"}"); // Add the child wallet return $scope.addNewWallet(wallet) @@ -237,11 +243,8 @@ function WalletListController($scope, $controller, $state, $timeout, $q, $transl $scope.hideActionsPopover(); var loginAndAddWallet = function(authData) { - var walletId = csWallet.children.count() + 1; - - console.debug("[wallet] Adding secondary wallet {"+authData.pubkey.substring(0,8)+"} with id=" + walletId); - - var wallet = csWallet.instance(walletId); + console.debug("[wallet] Adding secondary wallet {"+authData.pubkey.substring(0,8)+"}"); + var wallet = csWallet.children.instance(); return wallet.login({ authData: authData, // Load data options : diff --git a/www/js/services/wallet-services.js b/www/js/services/wallet-services.js index c811bdfac8b13626a5f2cce13231bdea30303ed9..b04e17b5397d6af49ffcca3e406ce01ab3a1e891 100644 --- a/www/js/services/wallet-services.js +++ b/www/js/services/wallet-services.js @@ -631,13 +631,16 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se }); try { - _.forEach(content.children, function(child, index) { - var walletId = index+1; - var wallet = service.instance(walletId, BMA); - wallet.data.pubkey = child.pubkey; - wallet.data.localName = child.localName; - wallet.data.uid = child.uid; - addChildWallet(wallet, {store: false/*skip store*/}); + var pubkeys = {}; + _.forEach(content.children, function(child) { + if (!pubkeys[child.pubkey]) { // make sure wallet is unique by pubkey + pubkeys[child.pubkey] = true; + var wallet = getNewChildrenInstance(); + wallet.data.pubkey = child.pubkey; + wallet.data.localName = child.localName; + wallet.data.uid = child.uid; + addChildWallet(wallet, {store: false/*skip store*/}); + } }); delete content.children; // childrenCount not need anymore @@ -1997,6 +2000,14 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se return angular.isDefined(data.childrenCount) ? data.childrenCount : (data.children && data.children.length || 0); }, + getNewChildrenInstance = function() { + // Return max(id) + 1 + var walletId = (data.children && data.children.reduce(function(res, wallet) { + return Math.max(res, wallet.id); + }, 0) || data.childrenCount || 0 )+ 1; + return service.instance(walletId, BMA); + }, + getAllChildrenWallet = function() { return openEncryptedData() .then(function() { @@ -2348,6 +2359,7 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se setParent: setParentWallet, count: getChildrenWalletCount, hasPubkey: hasChildrenWithPubkey, + instance: getNewChildrenInstance, downloadFile: downloadChildrenWalletFile }, api: api