Merge pull request #1322 from iWarpBTC/fix_boltcard_refund
Fix: Boltcard refunds
This commit is contained in:
commit
3b1fb1c1a4
2 changed files with 11 additions and 8 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
import secrets
|
import secrets
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import List, Optional, Union
|
from typing import List, Optional
|
||||||
|
|
||||||
from lnbits.helpers import urlsafe_short_hash
|
from lnbits.helpers import urlsafe_short_hash
|
||||||
|
|
||||||
|
|
@ -66,9 +66,9 @@ async def update_card(card_id: str, **kwargs) -> Optional[Card]:
|
||||||
return Card(**row) if row else None
|
return Card(**row) if row else None
|
||||||
|
|
||||||
|
|
||||||
async def get_cards(wallet_ids: Union[str, List[str]]) -> List[Card]:
|
async def get_cards(wallet_ids: List[str]) -> List[Card]:
|
||||||
if isinstance(wallet_ids, str):
|
if len(wallet_ids) == 0:
|
||||||
wallet_ids = [wallet_ids]
|
return []
|
||||||
|
|
||||||
q = ",".join(["?"] * len(wallet_ids))
|
q = ",".join(["?"] * len(wallet_ids))
|
||||||
rows = await db.fetchall(
|
rows = await db.fetchall(
|
||||||
|
|
@ -130,7 +130,7 @@ async def delete_card(card_id: str) -> None:
|
||||||
for hit in hits:
|
for hit in hits:
|
||||||
await db.execute("DELETE FROM boltcards.hits WHERE id = ?", (hit.id,))
|
await db.execute("DELETE FROM boltcards.hits WHERE id = ?", (hit.id,))
|
||||||
# Delete refunds
|
# Delete refunds
|
||||||
refunds = await get_refunds([hit])
|
refunds = await get_refunds([hit.id])
|
||||||
for refund in refunds:
|
for refund in refunds:
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"DELETE FROM boltcards.refunds WHERE id = ?", (refund.hit_id,)
|
"DELETE FROM boltcards.refunds WHERE id = ?", (refund.hit_id,)
|
||||||
|
|
@ -169,7 +169,7 @@ async def get_hit(hit_id: str) -> Optional[Hit]:
|
||||||
return Hit.parse_obj(hit)
|
return Hit.parse_obj(hit)
|
||||||
|
|
||||||
|
|
||||||
async def get_hits(cards_ids: Union[str, List[str]]) -> List[Hit]:
|
async def get_hits(cards_ids: List[str]) -> List[Hit]:
|
||||||
if len(cards_ids) == 0:
|
if len(cards_ids) == 0:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
@ -266,7 +266,7 @@ async def get_refund(refund_id: str) -> Optional[Refund]:
|
||||||
return Refund.parse_obj(refund)
|
return Refund.parse_obj(refund)
|
||||||
|
|
||||||
|
|
||||||
async def get_refunds(hits_ids: List[Hit]) -> List[Refund]:
|
async def get_refunds(hits_ids: List[str]) -> List[Refund]:
|
||||||
if len(hits_ids) == 0:
|
if len(hits_ids) == 0:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -158,5 +158,8 @@ async def api_refunds(
|
||||||
for card in cards:
|
for card in cards:
|
||||||
cards_ids.append(card.id)
|
cards_ids.append(card.id)
|
||||||
hits = await get_hits(cards_ids)
|
hits = await get_hits(cards_ids)
|
||||||
|
hits_ids = []
|
||||||
|
for hit in hits:
|
||||||
|
hits_ids.append(hit.id)
|
||||||
|
|
||||||
return [refund.dict() for refund in await get_refunds(hits)]
|
return [refund.dict() for refund in await get_refunds(hits_ids)]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue