From b748dc3cb0ac604f81723bde18ab931dd404d569 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Fri, 5 May 2023 14:27:07 +0300 Subject: [PATCH] chore: code clean-up --- templates/nostrclient/index.html | 80 +++++++++++++++++++++++++++----- views_api.py | 2 - 2 files changed, 68 insertions(+), 14 deletions(-) diff --git a/templates/nostrclient/index.html b/templates/nostrclient/index.html index 78dd952..bbd8f23 100644 --- a/templates/nostrclient/index.html +++ b/templates/nostrclient/index.html @@ -110,17 +110,17 @@
- Test Endpoint
- - + +
- Private Key (optional): + Sender Private Key:
+
+
+ Sender Public Key: +
+
+ +
+
Test Message: @@ -165,7 +179,7 @@
- Public Key (hex or npub): + Receiver Public Key:
@@ -198,8 +212,8 @@
- - + +
Sent Data: @@ -292,8 +306,10 @@ nostrrelayLinks: [], filter: '', testData: { + show: false, wsConnection: null, senderPrivateKey: null, + senderPublicKey: null, recieverPublicKey: null, message: null, sentData: '', @@ -405,6 +421,38 @@ LNbits.utils.notifyApiError(error) }) }, + toggleTestPanel: async function() { + if (this.testData.show) { + await this.hideTestPannel() + } else { + await this.showTestPanel() + } + }, + showTestPanel: async function() { + this.testData = { + show: true, + wsConnection: null, + senderPrivateKey: this.$q.localStorage.getItem('lnbits.nostrclient.senderPrivateKey') || '', + recieverPublicKey: null, + message: null, + sentData: '', + receivedData: '' + } + await this.closeWebsocket() + this.connectToWebsocket() + }, + hideTestPannel: async function() { + await this.closeWebsocket() + this.testData = { + show: false, + wsConnection: null, + senderPrivateKey: null, + recieverPublicKey: null, + message: null, + sentData: '', + receivedData: '' + } + }, sendTestMessage: async function () { try { const {data} = await LNbits.api.request( @@ -423,6 +471,7 @@ data.private_key || '' ) const event = JSON.parse(data.event_json)[1] + this.testData.senderPublicKey = event.pubkey await this.sendDataToWebSocket(data.event_json) const subscription = JSON.stringify([ 'REQ', @@ -469,6 +518,16 @@ this.testData.wsConnection.onerror = updateReciveData this.testData.wsConnection.onclose = updateReciveData }, + closeWebsocket: async function () { + try { + if (this.testData.wsConnection) { + this.testData.wsConnection.close() + await this.sleep(100) + } + } catch (error) { + console.warn(error) + } + }, exportlnurldeviceCSV: function () { var self = this LNbits.utils.exportCSV(self.relayTable.columns, this.nostrLinks) @@ -479,9 +538,6 @@ var self = this this.getRelays() setInterval(this.getRelays, 5000) - this.testData.senderPrivateKey = - this.$q.localStorage.getItem('lnbits.nostrclient.senderPrivateKey') || - '' } }) diff --git a/views_api.py b/views_api.py index e7c5f06..12f4f79 100644 --- a/views_api.py +++ b/views_api.py @@ -93,8 +93,6 @@ async def api_test_endpoint(data: TestMessage) -> TestMessageResponse: ) private_key.sign_event(dm) - print("### api_test_endpoint", data) - return TestMessageResponse(private_key=private_key.hex(), public_key=to_public_key, event_json=dm.to_message()) except (ValueError, AssertionError) as ex: raise HTTPException(