From 660faa7fd130c650eebc1f0f43b39718d1744857 Mon Sep 17 00:00:00 2001 From: relativistic electron Date: Sun, 10 Jul 2022 17:52:23 +0200 Subject: [PATCH 001/117] working search field, no functionality --- src/cryptoadvance/specter/globalsearch.py | 8 ++++++ .../specter/server_endpoints/welcome.py | 9 ++++++- src/cryptoadvance/specter/static/helpers.js | 26 +++++++++++++++++++ .../specter/templates/base.jinja | 1 + .../templates/components/global_search.jinja | 13 ++++++++++ .../wallet/components/wallet_menu.jinja | 2 +- 6 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 src/cryptoadvance/specter/globalsearch.py create mode 100644 src/cryptoadvance/specter/templates/components/global_search.jinja diff --git a/src/cryptoadvance/specter/globalsearch.py b/src/cryptoadvance/specter/globalsearch.py new file mode 100644 index 0000000000..88f87aad0d --- /dev/null +++ b/src/cryptoadvance/specter/globalsearch.py @@ -0,0 +1,8 @@ +import os +import logging + +logger = logging.getLogger(__name__) + + +def do_global_search(search_term): + return search_term diff --git a/src/cryptoadvance/specter/server_endpoints/welcome.py b/src/cryptoadvance/specter/server_endpoints/welcome.py index 05d120918a..9185f2026e 100644 --- a/src/cryptoadvance/specter/server_endpoints/welcome.py +++ b/src/cryptoadvance/specter/server_endpoints/welcome.py @@ -1,5 +1,5 @@ import logging -import random +import random, json from binascii import unhexlify from flask import Blueprint @@ -10,6 +10,7 @@ from ..helpers import notify_upgrade from ..managers.wallet_manager import purposes +from ..globalsearch import do_global_search logger = logging.getLogger(__name__) @@ -19,6 +20,12 @@ welcome_endpoint = Blueprint("welcome_endpoint", __name__) +@welcome_endpoint.route("/global_search/", methods=["GET"]) +@login_required +def global_search(search_term): + return json.dumps(do_global_search(search_term)) + + @welcome_endpoint.route("/") @login_required def index(): diff --git a/src/cryptoadvance/specter/static/helpers.js b/src/cryptoadvance/specter/static/helpers.js index e646821a91..832b3113af 100644 --- a/src/cryptoadvance/specter/static/helpers.js +++ b/src/cryptoadvance/specter/static/helpers.js @@ -131,3 +131,29 @@ function numberWithCommas(x) { } return x.replace(/\B(?=(\d{3})+(?!\d))/g, ","); } + + + + + + +async function send_request(url, method_str, csrf_token, formData) { + if (!formData) { + formData = new FormData(); + } + formData.append("csrf_token", csrf_token) + d = { + method: method_str, + } + if (method_str == 'POST') { + d['body'] = formData; + } + + const response = await fetch(url, d); + if(response.status != 200){ + showError(await response.text()); + console.log(`Error while calling ${url} with ${method_str} ${formData}`) + return + } + return await response.json(); +} \ No newline at end of file diff --git a/src/cryptoadvance/specter/templates/base.jinja b/src/cryptoadvance/specter/templates/base.jinja index 11aff7ca4b..ccfe6acd35 100644 --- a/src/cryptoadvance/specter/templates/base.jinja +++ b/src/cryptoadvance/specter/templates/base.jinja @@ -66,6 +66,7 @@


{% if current_user.is_authenticated and not hwi_bridge %}
+ {% include "components/global_search.jinja" %} {% include "components/price_bar.jinja" %} diff --git a/src/cryptoadvance/specter/templates/components/global_search.jinja b/src/cryptoadvance/specter/templates/components/global_search.jinja new file mode 100644 index 0000000000..dacd280f1b --- /dev/null +++ b/src/cryptoadvance/specter/templates/components/global_search.jinja @@ -0,0 +1,13 @@ + + + diff --git a/src/cryptoadvance/specter/templates/wallet/components/wallet_menu.jinja b/src/cryptoadvance/specter/templates/wallet/components/wallet_menu.jinja index a0aa156221..45fc162da1 100644 --- a/src/cryptoadvance/specter/templates/wallet/components/wallet_menu.jinja +++ b/src/cryptoadvance/specter/templates/wallet/components/wallet_menu.jinja @@ -9,7 +9,7 @@ {% macro wallet_menu(active_menuitem, wallet_alias) -%}
{% endblock %} From 669999049006f61445bfb36ee7e51cb6e6297ae0 Mon Sep 17 00:00:00 2001 From: relativistic electron Date: Mon, 11 Jul 2022 12:33:21 +0200 Subject: [PATCH 012/117] unsigned psbt search works --- src/cryptoadvance/specter/globalsearch.py | 20 ++++++++++++++++++- .../templates/components/global_search.jinja | 2 +- .../wallet/send/components/send_nav.jinja | 2 +- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/cryptoadvance/specter/globalsearch.py b/src/cryptoadvance/specter/globalsearch.py index 5777228e42..9416bda976 100644 --- a/src/cryptoadvance/specter/globalsearch.py +++ b/src/cryptoadvance/specter/globalsearch.py @@ -138,7 +138,7 @@ def add_all_in_wallet(wallet): ], ) - current_recieve_address = HtmlElement( + recieve = HtmlElement( sidebar_wallet, id="btn_receive", function=lambda x: search_in_structure(x, [wallet.address]), @@ -147,6 +147,24 @@ def add_all_in_wallet(wallet): ], ) + send = HtmlElement( + sidebar_wallet, + id="btn_send", + visible_on_endpoints=[ + url_for("wallets_endpoint.wallet", wallet_alias=wallet.alias) + ], + ) + unsigned = HtmlElement( + send, + id="btn_send_pending", + function=lambda x: search_in_structure( + x, [psbt.to_dict() for psbt in wallet.pending_psbts.values()] + ), + visible_on_endpoints=[ + url_for("wallets_endpoint.wallet", wallet_alias=wallet.alias) + ], + ) + for wallet in specter.wallet_manager.wallets.values(): add_all_in_wallet(wallet) return html_root diff --git a/src/cryptoadvance/specter/templates/components/global_search.jinja b/src/cryptoadvance/specter/templates/components/global_search.jinja index 80710fd6e9..ad1d2280da 100644 --- a/src/cryptoadvance/specter/templates/components/global_search.jinja +++ b/src/cryptoadvance/specter/templates/components/global_search.jinja @@ -87,7 +87,7 @@ let url="{{ url_for('wallets_endpoint_api.global_search', search_term='search_term') }}"; - url = url.replace('search_term', JSON.stringify( search_term)); + url = url.replace('search_term', encodeURIComponent(JSON.stringify( search_term))); console.log(url) send_request(url, 'GET', "{{ csrf_token() }}").then((answer)=> { if (!answer){return} diff --git a/src/cryptoadvance/specter/templates/wallet/send/components/send_nav.jinja b/src/cryptoadvance/specter/templates/wallet/send/components/send_nav.jinja index 31d0c2e48c..7260776122 100644 --- a/src/cryptoadvance/specter/templates/wallet/send/components/send_nav.jinja +++ b/src/cryptoadvance/specter/templates/wallet/send/components/send_nav.jinja @@ -10,7 +10,7 @@