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

[FIX] do not ask pass on unfunded (RT-3433) #2522

Merged
merged 1 commit into from
May 28, 2015
Merged
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
80 changes: 48 additions & 32 deletions src/js/services/txqueue.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ angular

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

function rpTxQueue($scope, network, keychain, id)
{
function rpTxQueue($scope, network, keychain, id) {
return {
addTransaction: addTransaction,
checkQueue: checkQueue,
Expand All @@ -28,41 +27,59 @@ function rpTxQueue($scope, network, keychain, id)
* @param callback function
*/
function addTransaction(tx) {
if (!$scope.account.Balance) {
// if account is unfunded, then there is no need to ask user for a key
// Add transaction to the queue.
// (Will be submitted as soon as account gets funding)
var item = {
tx_json: tx.tx_json,
type: tx.tx_json.TransactionType
};

// Additional details depending on a transaction type
if ('TrustSet' === item.type) {
item.details = tx.tx_json.LimitAmount;
}

// Get user's secret key
keychain.requestSecret(id.account, id.username, function (err, secret) {
if (err) {
console.log("client: txQueue: error while unlocking wallet: ", err);
var saveTx = function(e1, r1) {
if (e1) {
console.warn(e1);
return;
}
$scope.userBlob.unshift('/clients/rippletradecom/txQueue', item);
}

return;
if ($scope.userBlob.data && !$scope.userBlob.data.clients) {
// there is bug in RippleLib with unshift operation - if
// there is empty nodes in the path, it tries to create array node,
// and nothing gets created under it, so create '/clients' explicitly
$scope.userBlob.set('/clients', { rippletradecom: {} }, saveTx);
} else if ($scope.userBlob.data && $scope.userBlob.data.clients && _.isArray($scope.userBlob.data.clients)) {
// if '/clients' already set to array, clear it
$scope.userBlob.unset('/clients', function(e, r) {
if (e) return;
$scope.userBlob.set('/clients', { rippletradecom: {} }, saveTx);
});
} else {
saveTx();
}
} else {
// Get user's secret key
keychain.requestSecret(id.account, id.username, function(err, secret) {
if (err) {
console.log('client: txQueue: error while unlocking wallet: ', err);
return;
}

var transaction = ripple.Transaction.from_json(tx.tx_json);
var transaction = ripple.Transaction.from_json(tx.tx_json);

transaction.remote = network.remote;
transaction.secret(secret);
transaction.remote = network.remote;
transaction.secret(secret);

// If account is funded submit the transaction right away
if ($scope.account.Balance) {
// If account is funded submit the transaction right away
transaction.submit();
}

// If not, add it to the queue.
// (Will be submitted as soon as account gets funding)
else {
var item = {
tx_json: tx.tx_json,
type: tx.tx_json.TransactionType
};

// Additional details depending on a transaction type
if ('TrustSet' === item.type) {
item.details = tx.tx_json.LimitAmount;
}

$scope.userBlob.unshift("/clients/rippletradecom/txQueue", item);
}
});
});
}
}

/**
Expand All @@ -78,8 +95,7 @@ function rpTxQueue($scope, network, keychain, id)
// Get user's secret key
keychain.requestSecret(id.account, id.username, function (err, secret) {
if (err) {
console.log("client: txQueue: error while unlocking wallet: ", err);

console.log('client: txQueue: error while unlocking wallet: ', err);
return;
}

Expand Down