From 63a8b95893cfc68beb3985a1dfb8da727c9c50c7 Mon Sep 17 00:00:00 2001 From: tecnovert Date: Wed, 28 Sep 2022 21:19:53 +0200 Subject: [PATCH] debug: notifications --- basicswap/http_server.py | 2 ++ basicswap/js_server.py | 17 ++++++++++ basicswap/templates/header.html | 58 +++++++++++++++++++-------------- 3 files changed, 53 insertions(+), 24 deletions(-) diff --git a/basicswap/http_server.py b/basicswap/http_server.py index dad5527..c92c590 100644 --- a/basicswap/http_server.py +++ b/basicswap/http_server.py @@ -47,6 +47,7 @@ from .js_server import ( js_rates, js_rate, js_index, + js_generatenotification, ) from .ui.util import ( PAGE_LIMIT, @@ -680,6 +681,7 @@ class HttpHandler(BaseHTTPRequestHandler): 'rate': js_rate, 'rates': js_rates, 'rateslist': js_rates_list, + 'generatenotification': js_generatenotification, }.get(url_split[2], js_index) return func(self, url_split, post_string, is_json) except Exception as ex: diff --git a/basicswap/js_server.py b/basicswap/js_server.py index e370427..645ceec 100644 --- a/basicswap/js_server.py +++ b/basicswap/js_server.py @@ -5,6 +5,7 @@ # file LICENSE or http://www.opensource.org/licenses/mit-license.php. import json +import random import urllib.parse from .util import ( @@ -13,6 +14,7 @@ from .util import ( from .basicswap_util import ( strBidState, SwapTypes, + NotificationTypes as NT, ) from .chainparams import ( Coins, @@ -389,3 +391,18 @@ def js_rate(self, url_split, post_string, is_json): def js_index(self, url_split, post_string, is_json): return bytes(json.dumps(self.server.swap_client.getSummary()), 'UTF-8') + + +def js_generatenotification(self, url_split, post_string, is_json): + swap_client = self.server.swap_client + r = random.randint(0, 3) + if r == 0: + swap_client.notify(NT.OFFER_RECEIVED, {'offer_id': random.randbytes(28).hex()}) + elif r == 1: + swap_client.notify(NT.BID_RECEIVED, {'type': 'atomic', 'bid_id': random.randbytes(28).hex(), 'offer_id': random.randbytes(28).hex()}) + elif r == 2: + swap_client.notify(NT.BID_ACCEPTED, {'bid_id': random.randbytes(28).hex()}) + elif r == 3: + swap_client.notify(NT.BID_RECEIVED, {'type': 'xmr', 'bid_id': random.randbytes(28).hex(), 'offer_id': random.randbytes(28).hex()}) + + return bytes(json.dumps({'type': r}), 'UTF-8') diff --git a/basicswap/templates/header.html b/basicswap/templates/header.html index bf54b8d..bcad2b4 100644 --- a/basicswap/templates/header.html +++ b/basicswap/templates/header.html @@ -19,34 +19,44 @@ {% if debug_ui_mode == true %}

Debug UI mode: Active

{% endif %} + {% if ws_url %} {% endif %}