Skip to content
This repository has been archived by the owner on Sep 2, 2023. It is now read-only.

Check and log transactions (RT-3499 - RT-3501) #2591

Merged
merged 5 commits into from
Sep 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/js/entry/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ require('../services/rippletxt.service.js');
require('../services/federation.service.js');
require('../services/domainalias.service.js');
require('../services/history.service.js');
require('../services/notifications.service.js');
require('../services/api.service.js');

require('../services/authflow.service.js');
require('../services/blob.service.js');
Expand All @@ -58,7 +58,7 @@ var appDependencies = [
'tracker',
'appManager',
'history',
'notifications',
'api',
// ID Service related services
'blob',
'authflow',
Expand Down
65 changes: 65 additions & 0 deletions src/js/services/api.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
'use strict';

/**
* Backend API
* Interaction with Ripple Trade Backend REST API
*/

var module = angular.module('api', []);

module.factory('rpAPI', ['$http', '$q', function($http, $q) {
var rpAPI = {};
var httpOptions = {};

rpAPI.setHttpOptions = function() {
httpOptions = {
headers: {'Authorization': 'Bearer ' + store.get('backend_token')},
timeout: 8000
};
};

rpAPI.setHttpOptions();

rpAPI.getSubscription = function() {
return $http.get(Options.backend_url + '/api/subscription', httpOptions);
};

rpAPI.updateSubscription = function(subscription) {
return $http.put(Options.backend_url + '/api/subscription', subscription, httpOptions);
};

rpAPI.addTransaction = function(transaction, result, hash, submit_response_time) {
var request_body = {
transaction: transaction,
result: result,
hash: hash,
submit_response_time: submit_response_time
};

return $http.post(Options.backend_url + '/api/transactions', request_body, httpOptions);
};

rpAPI.getUserProfile = function() {
return $http.get(Options.backend_url + '/api/user', httpOptions);
};

rpAPI.getUserAccess = function() {
return $http.get(Options.backend_url + '/api/user/access', httpOptions).then(function(res) {
if (res.data.access === 'allowed') {
return 'allowed';
}

return $q.reject('denied');
});
};

rpAPI.getBlob = function() {
return $http.get(Options.backend_url + '/api/blob', httpOptions);
};

rpAPI.updateBlob = function(blobData) {
return $http.post(Options.backend_url + '/api/blob', blobData, httpOptions);
};

return rpAPI;
}]);
16 changes: 4 additions & 12 deletions src/js/services/blob.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var module = angular.module('blob', []);

module.factory('rpBlob', ['$rootScope', '$http', '$q', function($scope, $http, $q) {
module.factory('rpBlob', ['$rootScope', '$q', 'rpAPI', function($scope, $q, api) {

// Blob object class
function BlobObj() {
Expand Down Expand Up @@ -43,11 +43,7 @@ module.factory('rpBlob', ['$rootScope', '$http', '$q', function($scope, $http, $
BlobObj.prototype.init = function() {
var self = this;

return $http.get(
Options.backend_url + '/api/blob', {
headers: {'Authorization': 'Bearer ' + store.get('backend_token')},
timeout: 8000
}).then(function(response) {
return api.getBlob().then(function(response) {
if (!response.data || !response.data.data || !response.data.data.account_id) {
return $q.reject('Could not retrieve blob');
}
Expand Down Expand Up @@ -275,12 +271,8 @@ module.factory('rpBlob', ['$rootScope', '$http', '$q', function($scope, $http, $
blobData.encrypted_secret = this.encrypted_secret;
blobData.data = this.data;

return $http.post(
Options.backend_url + '/api/blob',
blobData, {
headers: {'Authorization': 'Bearer ' + store.get('backend_token')},
timeout: 8000
}).then(function(response) {
return api.updateBlob(blobData)
.then(function(response) {
if (!response.data) {
return callback(new Error('Could not save blob'));
}
Expand Down
44 changes: 19 additions & 25 deletions src/js/services/id.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ var webutil = require('../util/web'),
var module = angular.module('id', ['authflow', 'blob']);

module.factory(
'rpId', ['$rootScope', '$location', '$route', '$routeParams', '$timeout', '$http', 'rpAuthFlow', 'rpBlob', '$q',
function($scope, $location, $route, $routeParams, $timeout, $http, $authflow, $blob, $q) {
'rpId', ['$rootScope', '$location', '$route', '$routeParams', '$timeout', '$q', 'rpAuthFlow', 'rpBlob', 'rpAPI',
function($scope, $location, $route, $routeParams, $timeout, $q, authflow, blob, api) {
/**
* Identity manager
*
Expand Down Expand Up @@ -250,7 +250,7 @@ module.factory(
Id.prototype.exists = function(username, callback) {
username = Id.normalizeUsernameForDisplay(username);

$authflow.exists(Id.normalizeUsernameForInternals(username), function(err, data) {
authflow.exists(Id.normalizeUsernameForInternals(username), function(err, data) {
if (!err && data) {
// Blob found, new auth method
callback(null, true);
Expand All @@ -275,17 +275,19 @@ module.factory(
}

store.set('backend_token', backend_token);
// Update HTTP Options using new backend token value
api.setHttpOptions();

var blobObj = new $blob();
var blobObj = new blob();

// init returns a promise
blobObj.init().then(function(blob) {
blobObj.init().then(function(blobData) {
// Ensure certain properties exist
$.extend(true, blob, Id.minimumBlob);
$.extend(true, blobData, Id.minimumBlob);

$scope.userBlob = blob;
self.setUsername(blob.ripple_name);
self.setAccount(blob.data.account_id);
$scope.userBlob = blobData;
self.setUsername(blobData.ripple_name);
self.setAccount(blobData.data.account_id);
self.loginStatus = true;
$scope.loginStatus = true;
$scope.$broadcast('$blobUpdate');
Expand Down Expand Up @@ -323,22 +325,22 @@ module.factory(
// self.loginStatus = true;
// $scope.loginStatus = true;

var blobObj = new $blob();
var blobObj = new blob();

// init returns a promise
blobObj.init().then(function(blob) {
blobObj.init().then(function(blobData) {
// Ensure certain properties exist
$.extend(true, blob, Id.minimumBlob);
$.extend(true, blobData, Id.minimumBlob);

$scope.userBlob = blob;
self.setUsername(blob.ripple_name);
self.setAccount(blob.data.account_id);
$scope.userBlob = blobData;
self.setUsername(blobData.ripple_name);
self.setAccount(blobData.data.account_id);
self.loginStatus = true;
$scope.loginStatus = true;
$scope.$broadcast('$blobUpdate');
store.set('ripple_known', true);

callback(null, blob);
callback(null, blobData);

}, function(err) {
callback(new Error(err));
Expand All @@ -365,14 +367,6 @@ module.factory(
// location.href = location.protocol + '//' + location.hostname + port + location.pathname;
};

Id.prototype.getUserProfile = function() {
return $http.get(
Options.backend_url + '/api/user',
{
headers: {'Authorization': 'Bearer ' + store.get('backend_token')}
});
};

Id.prototype.unlock = function(username, password, callback) {
// Callback is optional
if ('function' !== typeof callback) {
Expand All @@ -382,7 +376,7 @@ module.factory(
// username = Id.normalizeUsernameForDisplay(username);
// password = Id.normalizePassword(password);

$authflow.unlock(username, password, function(err, resp) {
authflow.unlock(username, password, function(err, resp) {
if (err) {
callback(err);
return;
Expand Down
32 changes: 0 additions & 32 deletions src/js/services/notifications.service.js

This file was deleted.

22 changes: 16 additions & 6 deletions src/js/services/txqueue.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ angular
.module('txQueue', [])
.service('rpTxQueue', rpTxQueue);

rpTxQueue.$inject = ['$rootScope', 'rpNetwork', 'rpKeychain', 'rpId'];
rpTxQueue.$inject = ['$rootScope', 'rpNetwork', 'rpKeychain', 'rpId', 'rpAPI'];

function rpTxQueue($scope, network, keychain, id) {
function rpTxQueue($scope, network, keychain, id, api) {
return {
addTransaction: addTransaction,
checkQueue: checkQueue,
Expand Down Expand Up @@ -47,7 +47,7 @@ function rpTxQueue($scope, network, keychain, id) {
return;
}
$scope.userBlob.unshift('/clients/rippletradecom/txQueue', item);
}
};

if ($scope.userBlob.data && !$scope.userBlob.data.clients) {
// there is bug in RippleLib with unshift operation - if
Expand Down Expand Up @@ -76,8 +76,13 @@ function rpTxQueue($scope, network, keychain, id) {
transaction.remote = network.remote;
transaction.secret(secret);

// If account is funded submit the transaction right away
transaction.submit();
api.getUserAccess().then(function(res) {
// If account is funded submit the transaction right away
transaction.submit();
}, function(err2) {
// err
});

});
}
}
Expand Down Expand Up @@ -112,7 +117,12 @@ function rpTxQueue($scope, network, keychain, id) {
var tx = ripple.Transaction.from_json(item.tx_json);
tx.remote = network.remote;
tx.secret(secret);
tx.submit();

api.getUserAccess().then(function(res) {
tx.submit();
}, function(err2) {
// err
});
});

self.emptyQueue();
Expand Down
24 changes: 20 additions & 4 deletions src/js/tabs/brl.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ BrlTab.prototype.mainMenu = 'fund';

BrlTab.prototype.angular = function (module)
{
module.controller('BrlCtrl', ['$scope', 'rpId', 'rpAppManager', 'rpTracker', '$routeParams', 'rpKeychain', 'rpNetwork', '$timeout',
function ($scope, id, appManager, rpTracker, $routeParams, keychain, network, $timeout) {
module.controller('BrlCtrl', ['$scope', 'rpId', 'rpAppManager', 'rpTracker', '$routeParams', 'rpKeychain', 'rpNetwork', 'rpAPI', '$timeout',
function ($scope, id, appManager, rpTracker, $routeParams, keychain, network, api, $timeout) {


$scope.toggle_instructions = function() {
$scope.showInstructions = !$scope.showInstructions;
}
};

$scope.save_account = function () {

Expand Down Expand Up @@ -59,6 +59,8 @@ BrlTab.prototype.angular = function (module)
$scope.loading = false;
$scope.editing = false;
});

api.addTransaction(res.tx_json, {Status: 'success'}, res.tx_json.hash, new Date().toString());
})
.on('error', function (res) {
setEngineStatus(res, false);
Expand All @@ -71,6 +73,8 @@ BrlTab.prototype.angular = function (module)
$scope.editing = false;
});
});

api.addTransaction(res.tx_json, {Status: 'error'}, res.tx_json.hash, new Date().toString());
});

function setEngineStatus(res, accepted) {
Expand Down Expand Up @@ -116,9 +120,21 @@ BrlTab.prototype.angular = function (module)
$scope.mode = 'granting';

tx.secret(secret);
tx.submit();

api.getUserAccess().then(function(res) {
tx.submit();
}, function(err2) {
console.log('error', err2);
setImmediate(function () {
$scope.$apply(function () {
$scope.mode = 'error';

$scope.loading = false;
$scope.editing = false;
});
});

});
});

};
Expand Down
Loading