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

Commit

Permalink
Merge branch 'hotfix/1.0.5-2'
Browse files Browse the repository at this point in the history
  • Loading branch information
justmoon committed Aug 27, 2014
2 parents f503568 + 36d406b commit 9670273
Showing 1 changed file with 24 additions and 78 deletions.
102 changes: 24 additions & 78 deletions src/js/tabs/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,21 @@ SendTab.prototype.angular = function (module)

// Now starting to work on resolving the recipient
send.recipient_resolved = false;
send.recipient_actual = void(0);
send.amount_actual = void(0);

$scope.reset_currency_deps();
};

$scope.check_dt_visibility = function () {
var send = $scope.send;

send.show_dt_field = ($routeParams.dt
|| send.dt
|| send.recipient_info.dest_tag_required)
&& !send.federation;
send.show_dt_field =
($routeParams.dt
|| send.dt
|| ('object' === typeof send.recipient_info &&
send.recipient_info.dest_tag_required))
&& !send.federation;
};

$scope.update_destination = function () {
Expand Down Expand Up @@ -175,7 +179,7 @@ SendTab.prototype.angular = function (module)
$federation.check_email(recipient)
.then(function (result) {
// Check if this request is still current, exit if not
var now_recipient = send.recipient_actual || send.recipient_address;
var now_recipient = send.recipient_address;
if (recipient !== now_recipient) return;

send.federation_record = result;
Expand Down Expand Up @@ -239,6 +243,7 @@ SendTab.prototype.angular = function (module)
var account = $network.remote.account(recipient);

send.path_status = 'checking';
send.recipient_info = null;
account.entry(function (e, data) {
$scope.$apply(function () {
// Check if this request is still current, exit if not
Expand Down Expand Up @@ -322,6 +327,17 @@ SendTab.prototype.angular = function (module)
});
}

// If this a bridge where we need a quote, we need to enter an
// amount first, before we can even find out who the recipient is. So
// if there is a quote_url, we want to bypass the recipient-based
// constraints.
if (send.quote_url) {
$scope.update_currency_choices();
return;
}

// If we don't have information about the recipient Ripple account yet,
// we'll just return. We'll get back here once we have that information.
if (!send.recipient_info.loaded) return;

if (send.recipient_info.exists) {
Expand All @@ -347,14 +363,6 @@ SendTab.prototype.angular = function (module)
})
.on('error', function () {})
.request();
} else if (send.recipient_info.exists) {
// Their account exists, but we couldn't grab their trust lines,
// probably because their owner directory is too large. So, we'll
// just show a default selection of currencies.

// If we do nothing here, we'll be showing the default currency list

// Do nothing
} else {
// If the account doesn't exist, we can only send XRP
send.currency_choices_constraints.accountLines = ["XRP"];
Expand Down Expand Up @@ -423,7 +431,9 @@ SendTab.prototype.angular = function (module)

$scope.reset_currency_deps();

if (!ripple.UInt160.is_valid(recipient)) {
// We should have a valid recipient unless it's a quoting bridge, in
// which case we should continue so we can request a quote.
if (!ripple.UInt160.is_valid(recipient) && !send.quote_url) {
return;
}

Expand Down Expand Up @@ -630,11 +640,6 @@ SendTab.prototype.angular = function (module)

$scope.reset_paths();

// Note that last_am_recipient and last_recipient are intentionally
// separate, the former is the last recipient that update_paths used.
send.last_am_recipient = recipient;
send.last_amount = send.amount_feedback;

send.path_status = 'pending';

// Determine if we need to update the paths.
Expand Down Expand Up @@ -744,66 +749,10 @@ SendTab.prototype.angular = function (module)
var pathFindTime = new Date();
};

$scope.handle_paths = function (data) {
if (!data.alternatives || !data.alternatives.length) {
$scope.send.path_status = "no-path";
} else {
$scope.send.path_status = "done";
$scope.send.alternatives = _.map(data.alternatives, function (raw) {
var alt = {};
alt.amount = Amount.from_json(raw.source_amount);
alt.send_max = alt.amount.product_human(Amount.from_json('1.01'));
alt.paths = raw.paths_computed
? raw.paths_computed
: raw.paths_canonical;

return alt;
});
// $scope.send.alt = $scope.send.alternatives[0];
}
};

$scope.$watch('userBlob.data.contacts', function (contacts) {
$scope.recipient_query = webutil.queryFromContacts(contacts);
}, true);

// update currency options based on existing trust lines
// the user can only send the currencies for which there exists trustlines
var updateCurrencyOptions = function(){
// create a list of currency codes from the trust line objects
var currencies = _.uniq(_.map($scope.lines, function (line) {
return line.currency;
}));

// add XRP if it's allowed
if (!$scope.send.recipient_info.disallow_xrp) {
currencies.unshift('XRP');
}

// create a currency object for each of the currency codes
for (var i=0; i < currencies.length; i++) {
currencies[i] = ripple.Currency.from_json(currencies[i]);

if (i === 0) {
$scope.send.currency_code = currencies[i].get_iso();
}
}

// create the display version of the currencies
currencies = _.map(currencies, function (currency) {
if ($scope.currencies_all_keyed[currency.get_iso()]) {
return currency.to_human({full_name:$scope.currencies_all_keyed[currency.get_iso()].name});
}

return currency.get_iso();
});

$scope.send.currency_choices = currencies;
$scope.send.currency = currencies[0];
}

$scope.$on('$balancesUpdate', updateCurrencyOptions);

$scope.$watch('account.max_spend', function () {
$scope.update_amount();
}, true);
Expand Down Expand Up @@ -840,7 +789,6 @@ SendTab.prototype.angular = function (module)
$scope.send.alt = null;

// Force pathfinding reset
$scope.send.last_am_recipient = null;
$scope.update_paths();
};

Expand Down Expand Up @@ -1122,8 +1070,6 @@ SendTab.prototype.angular = function (module)
});

$scope.reset();

updateCurrencyOptions();
}]);

/**
Expand Down

0 comments on commit 9670273

Please sign in to comment.