From cdebded0f66e378ab79bae6a4cd743e1b61f3d2b Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Sun, 12 Mar 2023 11:40:23 +0000 Subject: [PATCH] Add references to trades list --- core/clients/platform.py | 2 ++ core/lib/db.py | 11 ++++++++++- core/lib/schemas/agora_s.py | 7 ++++--- core/templates/partials/platform-trades.html | 15 ++++++++++----- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/core/clients/platform.py b/core/clients/platform.py index 604e448..09a6bf9 100644 --- a/core/clients/platform.py +++ b/core/clients/platform.py @@ -116,6 +116,8 @@ class LocalPlatformClient(ABC): if dash["contact_count"] > 0: for contact in dash["contact_list"]: contact_id = contact["data"]["contact_id"] + reference = await db.tx_to_ref(str(contact_id)) + contact["reference"] = reference dash_tmp[contact_id] = contact return dash_tmp diff --git a/core/lib/db.py b/core/lib/db.py index a26ac71..88fe502 100644 --- a/core/lib/db.py +++ b/core/lib/db.py @@ -4,7 +4,7 @@ from core.util import logs log = logs.get_logger("db") -r = aioredis.from_url("redis://redis:6379", db=0) +r = aioredis.from_url("redis://redis:6379", db=0) # noqa def convert(data): @@ -28,6 +28,7 @@ async def get_refs(): :return: list of trade IDs :rtype: list """ + r = aioredis.from_url("redis://redis:6379", db=0) references = [] ref_keys = await r.keys("trade.*.reference") for key in ref_keys: @@ -44,6 +45,7 @@ async def tx_to_ref(tx): :return: reference :rtype: string """ + r = aioredis.from_url("redis://redis:6379", db=0) refs = await get_refs() for reference in refs: ref_data = await r.hgetall(f"trade.{reference}") @@ -62,6 +64,7 @@ async def ref_to_tx(reference): :return: trade ID :rtype: string """ + r = aioredis.from_url("redis://redis:6379", db=0) ref_data = convert(await r.hgetall(f"trade.{reference}")) if not ref_data: return False @@ -74,6 +77,7 @@ async def get_ref_map(): :return: dict of references keyed by TXID :rtype: dict """ + r = aioredis.from_url("redis://redis:6379", db=0) references = {} ref_keys = await r.keys("trade.*.reference") for key in ref_keys: @@ -90,6 +94,7 @@ async def get_ref(reference): :return: dict of trade information :rtype: dict """ + r = aioredis.from_url("redis://redis:6379", db=0) ref_data = await r.hgetall(f"trade.{reference}") ref_data = convert(ref_data) if "subclass" not in ref_data: @@ -107,6 +112,7 @@ async def get_tx(tx): :return: dict of trade information :rtype: dict """ + r = aioredis.from_url("redis://redis:6379", db=0) tx_data = await r.hgetall(f"tx.{tx}") tx_data = convert(tx_data) if not tx_data: @@ -115,6 +121,7 @@ async def get_tx(tx): async def get_subclass(reference): + r = aioredis.from_url("redis://redis:6379", db=0) obj = await r.hget(f"trade.{reference}", "subclass") subclass = convert(obj) return subclass @@ -126,6 +133,7 @@ async def del_ref(reference): :param reference: trade reference to delete :type reference: string """ + r = aioredis.from_url("redis://redis:6379", db=0) tx = await ref_to_tx(reference) await r.delete(f"trade.{reference}") await r.delete(f"trade.{tx}.reference") @@ -138,6 +146,7 @@ async def cleanup(subclass, references): :param references: list of references to reconcile against :type references: list """ + r = aioredis.from_url("redis://redis:6379", db=0) messages = [] ref_map = await get_ref_map() for tx, reference in ref_map.items(): diff --git a/core/lib/schemas/agora_s.py b/core/lib/schemas/agora_s.py index c8c1f6a..003a653 100644 --- a/core/lib/schemas/agora_s.py +++ b/core/lib/schemas/agora_s.py @@ -61,10 +61,11 @@ class ContactData(MyModel): class ContactActions(MyModel): advertisement_public_view: str | None advertisement_url: str | None - message_post_url: str - messages_url: str - release_url: str + message_post_url: str | None + messages_url: str | None + release_url: str | None cancel_url: str | None + dispute_url: str | None class Contact(MyModel): diff --git a/core/templates/partials/platform-trades.html b/core/templates/partials/platform-trades.html index 6c864d9..d34ad60 100644 --- a/core/templates/partials/platform-trades.html +++ b/core/templates/partials/platform-trades.html @@ -14,8 +14,8 @@ hx-get="{{ list_url }}"> id + ref buyer - seller amount crypto provider @@ -27,18 +27,23 @@ + onclick="window.prompt('Copy to clipboard: Ctrl+C, Enter', '{{ item.data.contact_id }}');"> + + + {{ item.reference }} + + {{ item.data.buyer.username }} - {{ item.data.seller.username }} {{ item.data.amount }} {{ item.data.currency }} {{ item.data.amount_xmr }} XMR {{ item.data.advertisement.payment_method }}