diff --git a/www/i18n/locale-en.json b/www/i18n/locale-en.json index c30a21fdd973c1e3b4828002ef068d44d5eac133..32e9783b36beebb68c590c535893afeca6135393 100644 --- a/www/i18n/locale-en.json +++ b/www/i18n/locale-en.json @@ -84,7 +84,8 @@ "PSEUDO": "Pseudonym", "PSEUDO_HELP": "joe123", "PASSWORD_CONFIRM": "Confirm Password", - "PASSWORD_CONFIRM_HELP": "Confirm Password" + "PASSWORD_CONFIRM_HELP": "Confirm Password", + "MSG_UID_ALREADY_USED": "This pseudonym is alreadey used by an existing member.<br/>Please choose another one." }, "POPUP_REGISTER": { "TITLE": "Enter a pseudonym", diff --git a/www/js/controllers/wallet-controllers.js b/www/js/controllers/wallet-controllers.js index 5914a1c7428218665cbe645a49aadf8b661b446a..26594199cb4726ecb76e356b2dfb6a5fe478c7a9 100644 --- a/www/js/controllers/wallet-controllers.js +++ b/www/js/controllers/wallet-controllers.js @@ -41,7 +41,7 @@ angular.module('cesium.wallet.controllers', ['cesium.services', 'cesium.currency .controller('TransferCtrl', TransferController) ; -function WalletController($scope, $state, $q, $ionicPopup, UIUtils, Wallet, $translate) { +function WalletController($scope, $state, $q, $ionicPopup, UIUtils, Wallet, BMA, $translate) { $scope.walletData = {}; $scope.convertedBalance = 0; @@ -115,7 +115,6 @@ function WalletController($scope, $state, $q, $ionicPopup, UIUtils, Wallet, $tra //don't allow the user to close unless he enters a uid e.preventDefault(); } else { - // TODO : check if not already used return $scope.walletData.uid; } } @@ -123,17 +122,43 @@ function WalletController($scope, $state, $q, $ionicPopup, UIUtils, Wallet, $tra ] }) .then(function(uid) { - if (!uid) { + if (!uid) { // user cancel $scope.walletData.uid = null; + UIUtils.loading.hide(); + return; } - else { - UIUtils.loading.show(); + var doSendSelf = function() { Wallet.self(uid) - .then(function() { + .then(function() { + UIUtils.loading.hide(); + }) + .catch(UIUtils.onError('ERROR.SEND_SELF_REGISTRATION')); + }; + // Check uid is not used by another member + UIUtils.loading.show(); + BMA.wot.lookup({ search: uid }) + .then(function(res) { + var found = typeof res.results != "undefined" && res.results != null && res.results.length > 0 + && res.results.some(function(pub){ + return typeof pub.uids != "undefined" && pub.uids != null && pub.uids.length > 0 + && pub.uids.some(function(idty){ + return (idty.uid == uid); + }); + }); + if (found) { // uid is already used : display a message and reopen the popup UIUtils.loading.hide(); - }) - .catch(UIUtils.onError('ERROR.SEND_SELF_REGISTRATION')); - } + UIUtils.alert.info('ACCOUNT.NEW.MSG_UID_ALREADY_USED') + .then(function(){ + $scope.self(); + }); + } + else { + doSendSelf(); + } + }) + .catch(function() { + doSendSelf(); + }); }); }); }; diff --git a/www/js/services/utils-services.js b/www/js/services/utils-services.js index 249e45b057f5eff9844032082b72c988ca268ad3..2c209d31cbbee0241816cbda788182364a402905 100644 --- a/www/js/services/utils-services.js +++ b/www/js/services/utils-services.js @@ -2,7 +2,7 @@ angular.module('cesium.utils.services', ['ngResource']) -.factory('UIUtils', function($ionicLoading, $ionicPopup, $translate) { +.factory('UIUtils', function($ionicLoading, $ionicPopup, $translate, $q) { function alertError(err, subtitle) { $translate([err, 'ERROR.POPUP_TITLE', 'ERROR.UNKNOWN_ERROR', 'COMMON.BTN_OK']) .then(function (translations) { @@ -22,19 +22,23 @@ angular.module('cesium.utils.services', ['ngResource']) } function alertInfo(message, subtitle) { - $translate([message, 'INFO.POPUP_TITLE', 'COMMON.BTN_OK']) - .then(function (translations) { - var message = translations[message]; - return $ionicPopup.show({ - template: '<p>' + message + '</p>', - title: translations['INFO.POPUP_TITLE'], - subTitle: subtitle, - buttons: [ - { - text: '<b>'+translations['COMMON.BTN_OK']+'</b>', - type: 'button-positive' - } - ] + return $q(function(resolve, reject) { + $translate([message, 'INFO.POPUP_TITLE', 'COMMON.BTN_OK']) + .then(function (translations) { + return $ionicPopup.show({ + template: '<p>' + translations[message] + '</p>', + title: translations['INFO.POPUP_TITLE'], + subTitle: subtitle, + buttons: [ + { + text: '<b>'+translations['COMMON.BTN_OK']+'</b>', + type: 'button-positive', + onTap: function(e) { + resolve(e); + } + } + ] + }); }); }); } @@ -59,7 +63,8 @@ angular.module('cesium.utils.services', ['ngResource']) return { alert: { - error: alertError + error: alertError, + info: alertInfo }, loading: { show: showLoading,