Skip to content
Snippets Groups Projects
Commit 2533b217 authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

[fix] /app/transfer/:pubkey : make this URL works - fix #440

[enh] /app/transfer/:pubkey : add parameters 'amount', ''udAmount', 'comment'
parent ae621bd1
No related branches found
No related tags found
No related merge requests found
...@@ -6,10 +6,10 @@ angular.module('cesium.transfer.controllers', ['cesium.services', 'cesium.curren ...@@ -6,10 +6,10 @@ angular.module('cesium.transfer.controllers', ['cesium.services', 'cesium.curren
.state('app.new_transfer', { .state('app.new_transfer', {
cache: false, cache: false,
url: "/transfer?uid&pubkey", url: "/transfer?amount&udAmount&comment",
views: { views: {
'menuContent': { 'menuContent': {
templateUrl: "templates/wallet/new_transfer.html", templateUrl: "templates/wot/view_identity.html",
controller: 'TransferCtrl' controller: 'TransferCtrl'
} }
} }
...@@ -17,7 +17,7 @@ angular.module('cesium.transfer.controllers', ['cesium.services', 'cesium.curren ...@@ -17,7 +17,7 @@ angular.module('cesium.transfer.controllers', ['cesium.services', 'cesium.curren
.state('app.new_transfer_pubkey_uid', { .state('app.new_transfer_pubkey_uid', {
cache: false, cache: false,
url: "/transfer/:pubkey/:uid", url: "/transfer/:pubkey/:uid?amount&udAmount&comment",
views: { views: {
'menuContent': { 'menuContent': {
templateUrl: "templates/wallet/new_transfer.html", templateUrl: "templates/wallet/new_transfer.html",
...@@ -28,7 +28,7 @@ angular.module('cesium.transfer.controllers', ['cesium.services', 'cesium.curren ...@@ -28,7 +28,7 @@ angular.module('cesium.transfer.controllers', ['cesium.services', 'cesium.curren
.state('app.new_transfer_pubkey', { .state('app.new_transfer_pubkey', {
cache: false, cache: false,
url: "/transfer/:pubkey", url: "/transfer/:pubkey?amount&udAmount&comment",
views: { views: {
'menuContent': { 'menuContent': {
templateUrl: "templates/wallet/new_transfer.html", templateUrl: "templates/wallet/new_transfer.html",
...@@ -44,32 +44,58 @@ angular.module('cesium.transfer.controllers', ['cesium.services', 'cesium.curren ...@@ -44,32 +44,58 @@ angular.module('cesium.transfer.controllers', ['cesium.services', 'cesium.curren
.controller('TransferModalCtrl', TransferModalController) .controller('TransferModalCtrl', TransferModalController)
; ;
function TransferController($scope, $controller, UIUtils, csSettings) { function TransferController($scope, $controller, UIUtils, $q, csWot) {
'ngInject'; 'ngInject';
// Initialize the super class and extend it. // Initialize the super class and extend it.
angular.extend(this, $controller('TransferModalLookupCtrl', {$scope: $scope})); angular.extend(this, $controller('TransferModalCtrl', {$scope: $scope, parameters: null}));
$scope.$on('$ionicView.enter', function(e, state) { $scope.enter = function(e, state) {
if (!!state.stateParams && !!state.stateParams.pubkey) { var initJobs = [];
$scope.formData.destPub = state.stateParams.pubkey;
if (!!state.stateParams.uid) { // Compute parameters
$scope.destUid = state.stateParams.uid; var parameters = {};
$scope.destPub = ''; if (state && state.stateParams) {
if (state.stateParams.pubkey) {
parameters.pubkey = state.stateParams.pubkey;
}
if (state.stateParams.amount) {
parameters.useRelative = false;
parameters.amount = state.stateParams.amount;
} }
else { else if (state.stateParams.udAmount) {
$scope.destUid = ''; parameters.useRelative = true;
$scope.destPub = $scope.formData.destPub; parameters.udAmount = state.stateParams.udAmount;
}
if (state.stateParams.comment) {
//$scope.formData.comment = state.stateParams.comment;
parameters.comment = state.stateParams.comment;
} }
} }
// Make sure wallet is loaded
$scope.loadWallet() $scope.loadWallet()
.then(function() {
$scope.formData.useRelative = csSettings.data.useRelative; // If pubkey, get the uid (+ name, avatar)
$scope.onUseRelativeChanged(); .then(function() {
UIUtils.loading.hide(); if (parameters.pubkey) {
}); return csWot.extend({pubkey: parameters.pubkey})
}); .then(function(dest) {
if (dest && dest.uid) {
parameters.uid = dest.name || dest.uid;
}
});
}
})
// Apply parameters, then recompute relative amount
.then(function() {
$scope.setParameters(parameters);
$scope.onUseRelativeChanged();
UIUtils.loading.hide();
});
};
$scope.$on('$ionicView.enter', $scope.enter);
$scope.setForm = function(form) { $scope.setForm = function(form) {
$scope.form = form; $scope.form = form;
...@@ -96,13 +122,14 @@ function TransferModalController($scope, $rootScope, $translate, $filter, BMA, c ...@@ -96,13 +122,14 @@ function TransferModalController($scope, $rootScope, $translate, $filter, BMA, c
$scope.udAmount = null; $scope.udAmount = null;
$scope.commentPattern = BMA.regexp.COMMENT; $scope.commentPattern = BMA.regexp.COMMENT;
if (parameters) { $scope.setParameters = function(parameters) {
if (!parameters) return;
if (parameters.pubkey) { if (parameters.pubkey) {
$scope.formData.destPub = parameters.pubkey; $scope.formData.destPub = parameters.pubkey;
} }
if (parameters.uid) { if (parameters.uid) {
$scope.destUid = parameters.uid; $scope.destUid = parameters.uid;
$scope.destPub = ''; $scope.destPub = '';
} }
else { else {
$scope.destUid = ''; $scope.destUid = '';
...@@ -110,12 +137,19 @@ function TransferModalController($scope, $rootScope, $translate, $filter, BMA, c ...@@ -110,12 +137,19 @@ function TransferModalController($scope, $rootScope, $translate, $filter, BMA, c
} }
if (parameters.amount) { if (parameters.amount) {
$scope.formData.amount = parameters.amount; $scope.formData.amount = parameters.amount;
$scope.formData.useRelative=false;
}
else if (parameters.udAmount) {
$scope.formData.amount = parameters.udAmount;
$scope.formData.useRelative=true;
} }
if (parameters.comment) { if (parameters.comment) {
$scope.formData.useComment=true; $scope.formData.useComment=true;
$scope.formData.comment = parameters.comment; $scope.formData.comment = parameters.comment;
} }
} };
// Read default parameters
$scope.setParameters(parameters);
$scope.cancel = function() { $scope.cancel = function() {
$scope.closeModal(); $scope.closeModal();
......
...@@ -931,6 +931,13 @@ angular.module('cesium.wot.services', ['ngResource', 'ngApi', 'cesium.bma.servic ...@@ -931,6 +931,13 @@ angular.module('cesium.wot.services', ['ngResource', 'ngApi', 'cesium.bma.servic
}); });
}, },
extend = function(idty, pubkeyAttributeName, skipAddUid) {
return extendAll([idty], pubkeyAttributeName, skipAddUid)
.then(function(res) {
return res[0];
});
},
extendAll = function(idties, pubkeyAttributeName, skipAddUid) { extendAll = function(idties, pubkeyAttributeName, skipAddUid) {
pubkeyAttributeName = pubkeyAttributeName || 'pubkey'; pubkeyAttributeName = pubkeyAttributeName || 'pubkey';
...@@ -985,6 +992,7 @@ angular.module('cesium.wot.services', ['ngResource', 'ngApi', 'cesium.bma.servic ...@@ -985,6 +992,7 @@ angular.module('cesium.wot.services', ['ngResource', 'ngApi', 'cesium.bma.servic
newcomers: getNewcomers, newcomers: getNewcomers,
pending: getPending, pending: getPending,
all: getAll, all: getAll,
extend: extend,
extendAll: extendAll, extendAll: extendAll,
// api extension // api extension
api: api api: api
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment