diff --git a/basicswap/http_server.py b/basicswap/http_server.py index a994b4a..e56a783 100644 --- a/basicswap/http_server.py +++ b/basicswap/http_server.py @@ -11,9 +11,11 @@ import shlex import traceback import threading import http.client -from urllib import parse + from http.server import BaseHTTPRequestHandler, HTTPServer from jinja2 import Environment, PackageLoader +from socket import error as SocketError +from urllib import parse from . import __version__ from .util import ( @@ -30,7 +32,6 @@ from .basicswap_util import ( strTxState, strBidState, ) - from .js_server import ( js_error, js_url_to_function, @@ -616,14 +617,20 @@ class HttpHandler(BaseHTTPRequestHandler): def do_GET(self): response = self.handle_http(200, self.path) - self.wfile.write(response) + try: + self.wfile.write(response) + except SocketError as e: + self.server.swap_client.log.debug(f"do_GET SocketError {e}") def do_POST(self): post_string = self.rfile.read(int(self.headers.get("Content-Length"))) is_json = True if "json" in self.headers.get("Content-Type", "") else False response = self.handle_http(200, self.path, post_string, is_json) - self.wfile.write(response) + try: + self.wfile.write(response) + except SocketError as e: + self.server.swap_client.log.debug(f"do_POST SocketError {e}") def do_HEAD(self): self.putHeaders(200, "text/html") diff --git a/basicswap/js_server.py b/basicswap/js_server.py index 194b846..233021c 100644 --- a/basicswap/js_server.py +++ b/basicswap/js_server.py @@ -328,9 +328,10 @@ def formatBids(swap_client, bids, filters) -> bytes: offer = swap_client.getOffer(b[3]) ci_to = swap_client.ci(offer.coin_to) if offer else None + bid_rate: int = 0 if b[10] is None else b[10] amount_to = None if ci_to: - amount_to = ci_to.format_amount((b[4] * b[10]) // ci_from.COIN()) + amount_to = ci_to.format_amount((b[4] * bid_rate) // ci_from.COIN()) bid_data = { "bid_id": b[2].hex(), @@ -341,7 +342,7 @@ def formatBids(swap_client, bids, filters) -> bytes: "coin_to": ci_to.coin_name() if ci_to else "Unknown", "amount_from": ci_from.format_amount(b[4]), "amount_to": amount_to, - "bid_rate": swap_client.ci(b[14]).format_amount(b[10]), + "bid_rate": swap_client.ci(b[14]).format_amount(bid_rate), "bid_state": strBidState(b[5]), "addr_from": b[11], "addr_to": offer.addr_to if offer else None,