Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

Selectively disable failing swap buttons #271

Merged
merged 2 commits into from
Jun 9, 2020
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
31 changes: 19 additions & 12 deletions raiden_installer/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,18 +756,25 @@ def post(self, configuration_file_name):
ex_currency_amt["currency"], configuration_file.network
)
token_amount = TokenAmount(ex_currency_amt["target_amount"], currency)
exchange_costs = exchange.calculate_transaction_costs(token_amount, account)
total_cost = exchange_costs["total"]
self.render_json(
{
"exchange": exchange.name,
"currency": currency.ticker,
"target_amount": ex_currency_amt["target_amount"],
"as_wei": total_cost.as_wei,
"formatted": total_cost.formatted,
"utc_seconds": int(time.time()),
}
)
try:
exchange_costs = exchange.calculate_transaction_costs(token_amount, account)
total_cost = exchange_costs["total"]
self.render_json(
{
"exchange": exchange.name,
"currency": currency.ticker,
"target_amount": ex_currency_amt["target_amount"],
"as_wei": total_cost.as_wei,
"formatted": total_cost.formatted,
"utc_seconds": int(time.time()),
}
)
except ExchangeError as ex:
log.error("There was an error preparing the exchange", exc_info=ex)
self.set_status(
status_code=409,
reason=str(ex),
)


class GasPriceHandler(APIHandler):
Expand Down
6 changes: 6 additions & 0 deletions resources/templates/swap.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@
placeholder.remove();
estimationElement.appendChild(text);
}
else {
const error = document.createTextNode(`Swap not possible at the moment.`);
placeholder.remove();
estimationElement.appendChild(error);
button.setAttribute("disabled", true);
}
};

req.open("POST", API_COST_ESTIMATION_ENDPOINT, true);
Expand Down