diff --git a/www/js/controllers/app-controllers.js b/www/js/controllers/app-controllers.js index 3b6576eba30a7d6c051720f5c72677105e3f8d60..2a58c669214f50b617d492cb8d4322974cf8ab58 100644 --- a/www/js/controllers/app-controllers.js +++ b/www/js/controllers/app-controllers.js @@ -409,12 +409,27 @@ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $ if (!res) throw {message: 'ERROR.UNKNOWN_URI_FORMAT'}; // Continue if (res.pubkey) { - $state.go('app.wot_identity', - angular.merge({ - pubkey: res.pubkey, - action: res.params && (res.params.amount || res.params.comment) ? 'transfer' : undefined - }, res.params), - {reload: true}); + var action = res.params && (angular.isDefined(res.params.amount) || res.params.comment) ? 'transfer' : undefined; + + console.info('[app] Redirecting from URI to identity {{0}} {1} {2}'.format( + res.pubkey.substring(0,8), + action ? ('with action ' + action) : '', + res.params ? JSON.stringify(res.params) : '' + ), uri); + + // Redirect to an owned wallet + if (!action && (csWallet.isUserPubkey(res.pubkey) || csWallet.children.isUserPubkey(res.pubkey))) { + var wallet = csWallet.getByPubkey(res.pubkey); + return $state.go('app.view_wallet_by_id', {id: wallet.id}); + } + else { + return $state.go('app.wot_identity', + angular.merge({ + pubkey: res.pubkey, + action: action + }, res.params), + {reload: true}); + } } else if (res.uid) { return $state.go('app.wot_identity_uid', diff --git a/www/js/controllers/transfer-controllers.js b/www/js/controllers/transfer-controllers.js index fb5f53b5bb3c11400462485fb30709eefa54c1f2..746e245ae844a0c654e7db8effe4d444f3ab607d 100644 --- a/www/js/controllers/transfer-controllers.js +++ b/www/js/controllers/transfer-controllers.js @@ -129,11 +129,13 @@ function TransferModalController($scope, $q, $translate, $timeout, $filter, $foc $scope.destPub = parameters.pubkey; } if (parameters.amount) { - $scope.formData.amount = parameters.amount; + var amount = parseInt(parameters.amount); // Parse as integer - see issue #1001) + $scope.formData.amount = !isNaN(amount) ? amount : null; $scope.formData.useRelative=false; } else if (parameters.udAmount) { - $scope.formData.amount = parameters.udAmount; + var udAmount = Number(parameters.udAmount); + $scope.formData.amount = !isNaN(udAmount) ? udAmount : null; $scope.formData.useRelative=true; } if (parameters.comment) { diff --git a/www/js/services/bma-services.js b/www/js/services/bma-services.js index 100ee9788161ce83146fd2d51778b16aa8ec78a2..566fee59b763eb38e7e3145d85ac1d11116eeb94 100644 --- a/www/js/services/bma-services.js +++ b/www/js/services/bma-services.js @@ -1058,14 +1058,12 @@ angular.module('cesium.bma.services', ['ngApi', 'cesium.http.services', 'cesium. // Pubkey (explicit path) var pubkey; if (parser.hostname === 'wallet' || parser.hostname === 'pubkey') { - if (exports.regexp.PUBKEY.test(parser.pathSegments[0]) || exports.regexp.PUBKEY_WITH_CHECKSUM.test(parser.pathSegments[0])) { - pubkey = parser.pathSegments[0]; - parser.pathSegments = parser.pathSegments.slice(1); - } - else { + pubkey = parser.pathSegments[0]; + if (!exports.regexp.PUBKEY.test(pubkey) && !exports.regexp.PUBKEY_WITH_CHECKSUM.test(pubkey)) { reject({message: 'ERROR.INVALID_PUBKEY'}); return; } + parser.pathSegments = parser.pathSegments.slice(1); } else if (parser.hostname && (exports.regexp.PUBKEY.test(parser.hostname) || exports.regexp.PUBKEY_WITH_CHECKSUM.test(parser.hostname))) { diff --git a/www/js/services/http-services.js b/www/js/services/http-services.js index 22463b5fbc3f9a0585135a69abc33e5a0f214032..a3ff1ea6f63ddedf8b870bf8761f22b4bbfc756d 100644 --- a/www/js/services/http-services.js +++ b/www/js/services/http-services.js @@ -358,6 +358,9 @@ angular.module('cesium.http.services', ['cesium.cache.services']) function parseUri(uri) { var protocol, hostname; + // Use a <a> element to parse + var parser = document.createElement('a'); + // G1 URI (see G1lien) if (uri.startsWith('june:') || uri.startsWith('web+june:')) { protocol = 'june:'; @@ -366,30 +369,25 @@ angular.module('cesium.http.services', ['cesium.cache.services']) // Store hostname here, because parse will apply a lowercase hostname = path; if (hostname.indexOf('/') !== -1) { - hostname = hostname.substr(0, path.indexOf('/')); + hostname = hostname.substring(0, path.indexOf('/')); } if (hostname.indexOf('?') !== -1) { - hostname = hostname.substr(0, path.indexOf('?')); + hostname = hostname.substring(0, path.indexOf('?')); } + // Avoid checksum to be parsed as an port (integer): remove it from the path (see issue #1001) if (hostname.indexOf(':') !== -1) { - var port = hostname.substring(path.indexOf(':')+1); - var cleanHostName = hostname.substr(0, path.indexOf(':')); - // Invalid port (e.g. a checksum) => remove it (otherwise net <a> parser will failed to parse the URI) - if (isNaN(parseInt(port))) { - path = cleanHostName + path.substring(hostname.length); - } - else { - hostname = cleanHostName; - } + // Removing checksum from the path, to be parseable + path = hostname.substring(0, path.indexOf(':')) + path.substring(hostname.length); } - // Clean path - uri = 'http://' + path; + + // Clean path (parsable by the <a> element) + parser.href = 'https://' + path; } - // Use a <a> element to parse - var parser = document.createElement('a'); - parser.href = uri; + else { + parser.href = uri; + } var pathname = parser.pathname; if (pathname && pathname.startsWith('/')) { @@ -397,6 +395,7 @@ angular.module('cesium.http.services', ['cesium.cache.services']) } var searchParams; + if (parser.search && parser.search.startsWith('?')) { searchParams = parser.search.substring(1).split('&') .reduce(function(res, searchParam) {