mirror of
https://github.com/basicswap/basicswap.git
synced 2024-12-22 11:39:34 +00:00
debug: notifications
This commit is contained in:
parent
ef0f5ea1ea
commit
63a8b95893
3 changed files with 53 additions and 24 deletions
|
@ -47,6 +47,7 @@ from .js_server import (
|
||||||
js_rates,
|
js_rates,
|
||||||
js_rate,
|
js_rate,
|
||||||
js_index,
|
js_index,
|
||||||
|
js_generatenotification,
|
||||||
)
|
)
|
||||||
from .ui.util import (
|
from .ui.util import (
|
||||||
PAGE_LIMIT,
|
PAGE_LIMIT,
|
||||||
|
@ -680,6 +681,7 @@ class HttpHandler(BaseHTTPRequestHandler):
|
||||||
'rate': js_rate,
|
'rate': js_rate,
|
||||||
'rates': js_rates,
|
'rates': js_rates,
|
||||||
'rateslist': js_rates_list,
|
'rateslist': js_rates_list,
|
||||||
|
'generatenotification': js_generatenotification,
|
||||||
}.get(url_split[2], js_index)
|
}.get(url_split[2], js_index)
|
||||||
return func(self, url_split, post_string, is_json)
|
return func(self, url_split, post_string, is_json)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import random
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
from .util import (
|
from .util import (
|
||||||
|
@ -13,6 +14,7 @@ from .util import (
|
||||||
from .basicswap_util import (
|
from .basicswap_util import (
|
||||||
strBidState,
|
strBidState,
|
||||||
SwapTypes,
|
SwapTypes,
|
||||||
|
NotificationTypes as NT,
|
||||||
)
|
)
|
||||||
from .chainparams import (
|
from .chainparams import (
|
||||||
Coins,
|
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):
|
def js_index(self, url_split, post_string, is_json):
|
||||||
return bytes(json.dumps(self.server.swap_client.getSummary()), 'UTF-8')
|
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')
|
||||||
|
|
|
@ -19,34 +19,44 @@
|
||||||
{% if debug_ui_mode == true %}
|
{% if debug_ui_mode == true %}
|
||||||
<p>Debug UI mode: Active</p>
|
<p>Debug UI mode: Active</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<button id="test_btn" type="button">Add Notification</button>
|
||||||
|
|
||||||
{% if ws_url %}
|
{% if ws_url %}
|
||||||
<script>
|
<script>
|
||||||
var ws = new WebSocket("{{ ws_url }}"),
|
var ws = new WebSocket("{{ ws_url }}"),
|
||||||
floating_div = document.createElement('div');
|
floating_div = document.createElement('div');
|
||||||
floating_div.classList.add('floatright');
|
floating_div.classList.add('floatright');
|
||||||
messages = document.createElement('ul');
|
messages = document.createElement('ul');
|
||||||
messages.setAttribute('id', 'ul_updates');
|
messages.setAttribute('id', 'ul_updates');
|
||||||
ws.onmessage = function (event) {
|
ws.onmessage = function (event) {
|
||||||
let json = JSON.parse(event.data);
|
let json = JSON.parse(event.data);
|
||||||
|
|
||||||
let event_message = 'Unknown event';
|
let event_message = 'Unknown event';
|
||||||
if (json['event'] == 'new_offer') {
|
if (json['event'] == 'new_offer') {
|
||||||
event_message = '<a href=/offer/' + json['offer_id'] + '>New offer</a>';
|
event_message = '<a href=/offer/' + json['offer_id'] + '>New offer</a>';
|
||||||
} else
|
} else
|
||||||
if (json['event'] == 'new_bid') {
|
if (json['event'] == 'new_bid') {
|
||||||
event_message = '<a href=/bid/' + json['bid_id'] + '>New bid</a> on offer <a href=/offer/' + json['offer_id'] + '>' + json['offer_id'] + '</a>';
|
event_message = '<a href=/bid/' + json['bid_id'] + '>New bid</a> on offer <a href=/offer/' + json['offer_id'] + '>' + json['offer_id'] + '</a>';
|
||||||
} else
|
} else
|
||||||
if (json['event'] == 'bid_accepted') {
|
if (json['event'] == 'bid_accepted') {
|
||||||
event_message = '<a href=/bid/' + json['bid_id'] + '>Bid accepted</a>';
|
event_message = '<a href=/bid/' + json['bid_id'] + '>Bid accepted</a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
let messages = document.getElementById('ul_updates'),
|
let messages = document.getElementById('ul_updates'),
|
||||||
message = document.createElement('li');
|
message = document.createElement('li');
|
||||||
message.innerHTML = event_message;
|
message.innerHTML = event_message;
|
||||||
messages.appendChild(message);
|
messages.appendChild(message);
|
||||||
};
|
};
|
||||||
floating_div.appendChild(messages);
|
floating_div.appendChild(messages);
|
||||||
document.body.appendChild(floating_div);
|
document.body.appendChild(floating_div);
|
||||||
|
|
||||||
|
const xhr_notification_debug = new XMLHttpRequest();
|
||||||
|
function test_notification() {
|
||||||
|
console.log('1');
|
||||||
|
xhr_notification_debug.open('GET', '/json/generatenotification');
|
||||||
|
xhr_notification_debug.send();
|
||||||
|
console.log('2');
|
||||||
|
}
|
||||||
|
document.getElementById("test_btn").addEventListener("click", test_notification);
|
||||||
</script>
|
</script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
Loading…
Reference in a new issue