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 3 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, local_time) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't logTransaction be a better name for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add is used to keep CRUD logic, log sounds better for sure.

var request_body = {
transaction: transaction,
result: result,
hash: hash,
local_time: local_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
14 changes: 4 additions & 10 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', 'rpAuthFlow', 'rpBlob', 'rpAPI', '$q',
function($scope, $location, $route, $routeParams, $timeout, $authflow, $blob, $api, $q) {
/**
* Identity manager
*
Expand Down Expand Up @@ -275,6 +275,8 @@ module.factory(
}

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

var blobObj = new $blob();

Expand Down Expand Up @@ -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 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
22 changes: 19 additions & 3 deletions src/js/tabs/btc.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ BtcTab.prototype.tabName = 'btc';
BtcTab.prototype.mainMenu = 'fund';

BtcTab.prototype.angular = function(module) { module.controller('BtcCtrl', [
'$scope', 'rpId', 'rpAppManager', 'rpTracker', '$routeParams', 'rpNetwork', 'rpKeychain',
function($scope, id, appManager, rpTracker, $routeParams, network, keychain) {
'$scope', 'rpId', 'rpAppManager', 'rpTracker', '$routeParams', 'rpNetwork', 'rpKeychain', 'rpAPI',
function($scope, id, appManager, rpTracker, $routeParams, network, keychain, api) {
$scope.accountLines = {};
$scope.showComponent = [];
$scope.showInstructions = false;
Expand Down Expand Up @@ -155,6 +155,8 @@ BtcTab.prototype.angular = function(module) { module.controller('BtcCtrl', [
$scope.btcLoading = false;
$scope.btcediting = false;
});

api.addTransaction(res.tx_json, {Status: 'success'}, res.tx_json.hash, new Date().toString());
})
.on('error', function (res) {
setEngineStatus(res, false);
Expand All @@ -167,6 +169,8 @@ BtcTab.prototype.angular = function(module) { module.controller('BtcCtrl', [
$scope.btcediting = false;
});
});

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

function setEngineStatus(res, accepted) {
Expand Down Expand Up @@ -212,8 +216,20 @@ BtcTab.prototype.angular = function(module) { module.controller('BtcCtrl', [
$scope.btcMode = '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.btcMode = 'error';

$scope.btcLoading = false;
$scope.btcediting = false;
});
});
});

});

Expand Down
19 changes: 18 additions & 1 deletion src/js/tabs/cad.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ CadTab.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 @@ -67,6 +69,8 @@ CadTab.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 @@ -109,7 +113,20 @@ CadTab.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;
});
});
});
});
};
$scope.$watch('lines', function() {
Expand Down
Loading