Add references to trades list

master
Mark Veidemanis 2 years ago
parent 49bb686040
commit cdebded0f6
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -116,6 +116,8 @@ class LocalPlatformClient(ABC):
if dash["contact_count"] > 0: if dash["contact_count"] > 0:
for contact in dash["contact_list"]: for contact in dash["contact_list"]:
contact_id = contact["data"]["contact_id"] contact_id = contact["data"]["contact_id"]
reference = await db.tx_to_ref(str(contact_id))
contact["reference"] = reference
dash_tmp[contact_id] = contact dash_tmp[contact_id] = contact
return dash_tmp return dash_tmp

@ -4,7 +4,7 @@ from core.util import logs
log = logs.get_logger("db") 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): def convert(data):
@ -28,6 +28,7 @@ async def get_refs():
:return: list of trade IDs :return: list of trade IDs
:rtype: list :rtype: list
""" """
r = aioredis.from_url("redis://redis:6379", db=0)
references = [] references = []
ref_keys = await r.keys("trade.*.reference") ref_keys = await r.keys("trade.*.reference")
for key in ref_keys: for key in ref_keys:
@ -44,6 +45,7 @@ async def tx_to_ref(tx):
:return: reference :return: reference
:rtype: string :rtype: string
""" """
r = aioredis.from_url("redis://redis:6379", db=0)
refs = await get_refs() refs = await get_refs()
for reference in refs: for reference in refs:
ref_data = await r.hgetall(f"trade.{reference}") ref_data = await r.hgetall(f"trade.{reference}")
@ -62,6 +64,7 @@ async def ref_to_tx(reference):
:return: trade ID :return: trade ID
:rtype: string :rtype: string
""" """
r = aioredis.from_url("redis://redis:6379", db=0)
ref_data = convert(await r.hgetall(f"trade.{reference}")) ref_data = convert(await r.hgetall(f"trade.{reference}"))
if not ref_data: if not ref_data:
return False return False
@ -74,6 +77,7 @@ async def get_ref_map():
:return: dict of references keyed by TXID :return: dict of references keyed by TXID
:rtype: dict :rtype: dict
""" """
r = aioredis.from_url("redis://redis:6379", db=0)
references = {} references = {}
ref_keys = await r.keys("trade.*.reference") ref_keys = await r.keys("trade.*.reference")
for key in ref_keys: for key in ref_keys:
@ -90,6 +94,7 @@ async def get_ref(reference):
:return: dict of trade information :return: dict of trade information
:rtype: dict :rtype: dict
""" """
r = aioredis.from_url("redis://redis:6379", db=0)
ref_data = await r.hgetall(f"trade.{reference}") ref_data = await r.hgetall(f"trade.{reference}")
ref_data = convert(ref_data) ref_data = convert(ref_data)
if "subclass" not in ref_data: if "subclass" not in ref_data:
@ -107,6 +112,7 @@ async def get_tx(tx):
:return: dict of trade information :return: dict of trade information
:rtype: dict :rtype: dict
""" """
r = aioredis.from_url("redis://redis:6379", db=0)
tx_data = await r.hgetall(f"tx.{tx}") tx_data = await r.hgetall(f"tx.{tx}")
tx_data = convert(tx_data) tx_data = convert(tx_data)
if not tx_data: if not tx_data:
@ -115,6 +121,7 @@ async def get_tx(tx):
async def get_subclass(reference): async def get_subclass(reference):
r = aioredis.from_url("redis://redis:6379", db=0)
obj = await r.hget(f"trade.{reference}", "subclass") obj = await r.hget(f"trade.{reference}", "subclass")
subclass = convert(obj) subclass = convert(obj)
return subclass return subclass
@ -126,6 +133,7 @@ async def del_ref(reference):
:param reference: trade reference to delete :param reference: trade reference to delete
:type reference: string :type reference: string
""" """
r = aioredis.from_url("redis://redis:6379", db=0)
tx = await ref_to_tx(reference) tx = await ref_to_tx(reference)
await r.delete(f"trade.{reference}") await r.delete(f"trade.{reference}")
await r.delete(f"trade.{tx}.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 :param references: list of references to reconcile against
:type references: list :type references: list
""" """
r = aioredis.from_url("redis://redis:6379", db=0)
messages = [] messages = []
ref_map = await get_ref_map() ref_map = await get_ref_map()
for tx, reference in ref_map.items(): for tx, reference in ref_map.items():

@ -61,10 +61,11 @@ class ContactData(MyModel):
class ContactActions(MyModel): class ContactActions(MyModel):
advertisement_public_view: str | None advertisement_public_view: str | None
advertisement_url: str | None advertisement_url: str | None
message_post_url: str message_post_url: str | None
messages_url: str messages_url: str | None
release_url: str release_url: str | None
cancel_url: str | None cancel_url: str | None
dispute_url: str | None
class Contact(MyModel): class Contact(MyModel):

@ -14,8 +14,8 @@
hx-get="{{ list_url }}"> hx-get="{{ list_url }}">
<thead> <thead>
<th>id</th> <th>id</th>
<th>ref</th>
<th>buyer</th> <th>buyer</th>
<th>seller</th>
<th>amount</th> <th>amount</th>
<th>crypto</th> <th>crypto</th>
<th>provider</th> <th>provider</th>
@ -27,18 +27,23 @@
<td> <td>
<a <a
class="has-text-grey" class="has-text-grey"
onclick="window.prompt('Copy to clipboard: Ctrl+C, Enter', '{{ item.data.contact_id }}/');"> onclick="window.prompt('Copy to clipboard: Ctrl+C, Enter', '{{ item.data.contact_id }}');">
<span class="icon" data-tooltip="Copy to clipboard"> <span class="icon" data-tooltip="Copy to clipboard">
<i class="fa-solid fa-copy" aria-hidden="true"></i> <i class="fa-solid fa-copy" aria-hidden="true"></i>
</span> </span>
</a> </a>
</td> </td>
<td>
<a
class="has-text-grey"
data-tooltip="Copy to clipboard"
onclick="window.prompt('Copy to clipboard: Ctrl+C, Enter', '{{ item.reference }}');">
<code>{{ item.reference }}</code>
</a>
</td>
<td data-tooltip="{{ item.data.buyer.name }} <td data-tooltip="{{ item.data.buyer.name }}
Trades: {{ item.data.buyer.trade_count }} Trades: {{ item.data.buyer.trade_count }}
Last online: {{ item.data.buyer.last_online }}">{{ item.data.buyer.username }}</td> Last online: {{ item.data.buyer.last_online }}">{{ item.data.buyer.username }}</td>
<td data-tooltip="{{ item.data.seller.name }}
Trades: {{ item.data.seller.trade_count }}
Last online: {{ item.data.seller.last_online }}">{{ item.data.seller.username }}</td>
<td>{{ item.data.amount }} {{ item.data.currency }}</td> <td>{{ item.data.amount }} {{ item.data.currency }}</td>
<td>{{ item.data.amount_xmr }} XMR</td> <td>{{ item.data.amount_xmr }} XMR</td>
<td>{{ item.data.advertisement.payment_method }}</td> <td>{{ item.data.advertisement.payment_method }}</td>

Loading…
Cancel
Save