fix: create invoice for fresh merchant
This commit is contained in:
parent
eb01b3ab34
commit
6498f1aa96
6 changed files with 42 additions and 19 deletions
|
|
@ -49,7 +49,7 @@ def nostrmarket_start():
|
||||||
async def _wait_for_nostr_events():
|
async def _wait_for_nostr_events():
|
||||||
# wait for this extension to initialize
|
# wait for this extension to initialize
|
||||||
await asyncio.sleep(5)
|
await asyncio.sleep(5)
|
||||||
await wait_for_nostr_events(recieve_event_queue, send_req_queue)
|
await wait_for_nostr_events(recieve_event_queue)
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
task1 = loop.create_task(catch_everything_and_restart(wait_for_paid_invoices))
|
task1 = loop.create_task(catch_everything_and_restart(wait_for_paid_invoices))
|
||||||
|
|
|
||||||
2
crud.py
2
crud.py
|
|
@ -73,7 +73,7 @@ async def get_merchant_for_user(user_id: str) -> Optional[Merchant]:
|
||||||
return Merchant.from_row(row) if row else None
|
return Merchant.from_row(row) if row else None
|
||||||
|
|
||||||
|
|
||||||
async def delete_merchants(merchant_id: str) -> None:
|
async def delete_merchant(merchant_id: str) -> None:
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"DELETE FROM nostrmarket.merchants WHERE id = ?",
|
"DELETE FROM nostrmarket.merchants WHERE id = ?",
|
||||||
(merchant_id,),
|
(merchant_id,),
|
||||||
|
|
|
||||||
|
|
@ -34,3 +34,25 @@ async def connect_to_nostrclient_ws(
|
||||||
wst.start()
|
wst.start()
|
||||||
|
|
||||||
return ws
|
return ws
|
||||||
|
|
||||||
|
|
||||||
|
async def subscribe_to_direct_messages(public_key: str, since: int):
|
||||||
|
in_messages_filter = {"kind": 4, "#p": [public_key]}
|
||||||
|
out_messages_filter = {"kind": 4, "authors": [public_key]}
|
||||||
|
if since != 0:
|
||||||
|
in_messages_filter["since"] = since
|
||||||
|
out_messages_filter["since"] = since
|
||||||
|
print("### in_messages_filter", in_messages_filter)
|
||||||
|
print("### out_messages_filter", out_messages_filter)
|
||||||
|
|
||||||
|
await send_req_queue.put(
|
||||||
|
["REQ", f"direct-messages-in:{public_key}", in_messages_filter]
|
||||||
|
)
|
||||||
|
await send_req_queue.put(
|
||||||
|
["REQ", f"direct-messages-out:{public_key}", out_messages_filter]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def unsubscribe_from_direct_messages(public_key: str):
|
||||||
|
await send_req_queue.put(["CLOSE", f"direct-messages-in:{public_key}"])
|
||||||
|
await send_req_queue.put(["CLOSE", f"direct-messages-out:{public_key}"])
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ async function merchantDetails(path) {
|
||||||
'/nostrmarket/api/v1/merchant/' + this.merchantId,
|
'/nostrmarket/api/v1/merchant/' + this.merchantId,
|
||||||
this.adminkey
|
this.adminkey
|
||||||
)
|
)
|
||||||
|
// todo: refresh parent page
|
||||||
this.$emit('merchant-deleted', this.merchantId)
|
this.$emit('merchant-deleted', this.merchantId)
|
||||||
this.$q.notify({
|
this.$q.notify({
|
||||||
type: 'positive',
|
type: 'positive',
|
||||||
|
|
|
||||||
17
tasks.py
17
tasks.py
|
|
@ -14,7 +14,7 @@ from .crud import (
|
||||||
get_last_order_time,
|
get_last_order_time,
|
||||||
get_public_keys_for_merchants,
|
get_public_keys_for_merchants,
|
||||||
)
|
)
|
||||||
from .nostr.nostr_client import connect_to_nostrclient_ws
|
from .nostr.nostr_client import connect_to_nostrclient_ws, subscribe_to_direct_messages
|
||||||
from .services import handle_order_paid, process_nostr_message
|
from .services import handle_order_paid, process_nostr_message
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -65,25 +65,14 @@ async def subscribe_to_nostr_client(recieve_event_queue: Queue, send_req_queue:
|
||||||
await asyncio.sleep(5)
|
await asyncio.sleep(5)
|
||||||
|
|
||||||
|
|
||||||
async def wait_for_nostr_events(recieve_event_queue: Queue, send_req_queue: Queue):
|
async def wait_for_nostr_events(recieve_event_queue: Queue):
|
||||||
public_keys = await get_public_keys_for_merchants()
|
public_keys = await get_public_keys_for_merchants()
|
||||||
for p in public_keys:
|
for p in public_keys:
|
||||||
last_order_time = await get_last_order_time(p)
|
last_order_time = await get_last_order_time(p)
|
||||||
last_dm_time = await get_last_direct_messages_time(p)
|
last_dm_time = await get_last_direct_messages_time(p)
|
||||||
since = max(last_order_time, last_dm_time)
|
since = max(last_order_time, last_dm_time)
|
||||||
|
|
||||||
in_messages_filter = {"kind": 4, "#p": [p]}
|
await subscribe_to_direct_messages(p, since)
|
||||||
out_messages_filter = {"kind": 4, "authors": [p]}
|
|
||||||
if since != 0:
|
|
||||||
in_messages_filter["since"] = since
|
|
||||||
# out_messages_filter["since"] = since
|
|
||||||
print("### in_messages_filter", in_messages_filter)
|
|
||||||
print("### out_messages_filter", out_messages_filter)
|
|
||||||
|
|
||||||
await send_req_queue.put(["REQ", f"direct-messages-in:{p}", in_messages_filter])
|
|
||||||
await send_req_queue.put(
|
|
||||||
["REQ", f"direct-messages-out:{p}", out_messages_filter]
|
|
||||||
)
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
message = await recieve_event_queue.get()
|
message = await recieve_event_queue.get()
|
||||||
|
|
|
||||||
17
views_api.py
17
views_api.py
|
|
@ -22,12 +22,12 @@ from .crud import (
|
||||||
create_product,
|
create_product,
|
||||||
create_stall,
|
create_stall,
|
||||||
create_zone,
|
create_zone,
|
||||||
|
delete_merchant,
|
||||||
delete_merchant_direct_messages,
|
delete_merchant_direct_messages,
|
||||||
delete_merchant_orders,
|
delete_merchant_orders,
|
||||||
delete_merchant_products,
|
delete_merchant_products,
|
||||||
delete_merchant_stalls,
|
delete_merchant_stalls,
|
||||||
delete_merchant_zones,
|
delete_merchant_zones,
|
||||||
delete_merchants,
|
|
||||||
delete_product,
|
delete_product,
|
||||||
delete_stall,
|
delete_stall,
|
||||||
delete_zone,
|
delete_zone,
|
||||||
|
|
@ -61,7 +61,11 @@ from .models import (
|
||||||
Stall,
|
Stall,
|
||||||
Zone,
|
Zone,
|
||||||
)
|
)
|
||||||
from .nostr.nostr_client import publish_nostr_event
|
from .nostr.nostr_client import (
|
||||||
|
publish_nostr_event,
|
||||||
|
subscribe_to_direct_messages,
|
||||||
|
unsubscribe_from_direct_messages,
|
||||||
|
)
|
||||||
from .services import sign_and_send_to_nostr
|
from .services import sign_and_send_to_nostr
|
||||||
|
|
||||||
######################################## MERCHANT ########################################
|
######################################## MERCHANT ########################################
|
||||||
|
|
@ -74,7 +78,11 @@ async def api_create_merchant(
|
||||||
) -> Merchant:
|
) -> Merchant:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
merchant = await get_merchant_for_user(wallet.wallet.user)
|
||||||
|
assert merchant == None, "A merchant already exists for this user"
|
||||||
|
|
||||||
merchant = await create_merchant(wallet.wallet.user, data)
|
merchant = await create_merchant(wallet.wallet.user, data)
|
||||||
|
await subscribe_to_direct_messages(data.public_key, 0)
|
||||||
|
|
||||||
return merchant
|
return merchant
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
|
|
@ -117,7 +125,9 @@ async def api_delete_merchant(
|
||||||
await delete_merchant_stalls(merchant.id)
|
await delete_merchant_stalls(merchant.id)
|
||||||
await delete_merchant_direct_messages(merchant.id)
|
await delete_merchant_direct_messages(merchant.id)
|
||||||
await delete_merchant_zones(merchant.id)
|
await delete_merchant_zones(merchant.id)
|
||||||
await delete_merchants(merchant.id)
|
|
||||||
|
await unsubscribe_from_direct_messages(merchant.public_key)
|
||||||
|
await delete_merchant(merchant.id)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logger.warning(ex)
|
logger.warning(ex)
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
@ -646,4 +656,5 @@ async def api_stop(wallet: WalletTypeInfo = Depends(check_admin)):
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logger.warning(ex)
|
logger.warning(ex)
|
||||||
|
|
||||||
|
# todo: close websocket
|
||||||
return {"success": True}
|
return {"success": True}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue