Skip to content

Commit

Permalink
fix: date issues and some new api fields (#40)
Browse files Browse the repository at this point in the history
* fix: date issues and some new api fields
  • Loading branch information
dni authored Aug 6, 2024
1 parent 9f00ee5 commit 2b14deb
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 220 deletions.
3 changes: 3 additions & 0 deletions boltz_client/boltz.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class BoltzSwapStatusResponse:
failureReason: Optional[str] = None
zeroConfRejected: Optional[str] = None
transaction: Optional[dict] = None
failureDetails: Optional[str] = None


@dataclass
Expand All @@ -81,6 +82,7 @@ class BoltzSwapResponse:
expectedAmount: int
timeoutBlockHeight: int
blindingKey: Optional[str] = None
referralId: Optional[str] = None


@dataclass
Expand All @@ -92,6 +94,7 @@ class BoltzReverseSwapResponse:
timeoutBlockHeight: int
onchainAmount: int
blindingKey: Optional[str] = None
referralId: Optional[str] = None


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion boltz_client/onchain_wally.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def create_liquid_tx(
blinding_key: Optional[str] = None,
) -> str:
try:
import wallycore as wally
import wallycore as wally # type: ignore
except ImportError as exc:
raise ImportError(
"`wallycore` is not installed, but required for liquid support."
Expand Down
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"short_description": "Perform onchain/offchain swaps with Liquid support",
"tile": "/boltz/static/image/boltz.png",
"donate": "dni@600.wtf",
"min_lnbits_version": "0.12.5",
"min_lnbits_version": "0.12.11",
"contributors": [
{
"name": "dni",
Expand Down
8 changes: 4 additions & 4 deletions crud.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from time import time
from datetime import datetime
from typing import List, Optional, Union

from lnbits.db import Database
Expand Down Expand Up @@ -56,7 +56,7 @@ async def create_submarine_swap(

swap = SubmarineSwap(
id=swap_id,
time=time(),
time=datetime.now(),
refund_privkey=refund_privkey_wif,
payment_hash=payment_hash,
status="pending",
Expand Down Expand Up @@ -122,7 +122,7 @@ async def create_reverse_submarine_swap(
swap_id = urlsafe_short_hash()
reverse_swap = ReverseSubmarineSwap(
id=swap_id,
time=time(),
time=datetime.now(),
claim_privkey=claim_privkey_wif,
preimage=preimage_hex,
status="pending",
Expand Down Expand Up @@ -181,7 +181,7 @@ async def create_auto_reverse_submarine_swap(
) -> AutoReverseSubmarineSwap:
swap_id = urlsafe_short_hash()
swap = AutoReverseSubmarineSwap(
id=swap_id, time=time(), count=0, **create_swap.dict()
id=swap_id, time=datetime.now(), count=0, **create_swap.dict()
)
await db.execute(
insert_query("boltz.auto_reverse_submarineswap", swap),
Expand Down
9 changes: 5 additions & 4 deletions models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Optional, Union
from datetime import datetime
from typing import Optional

from fastapi import Query
from pydantic import BaseModel
Expand All @@ -19,7 +20,7 @@ class SubmarineSwap(BaseModel):
feerate: bool
feerate_value: Optional[int]
payment_hash: str
time: Union[str, float]
time: datetime
status: str
refund_privkey: str
refund_address: str
Expand Down Expand Up @@ -52,7 +53,7 @@ class ReverseSubmarineSwap(BaseModel):
feerate_value: Optional[int]
onchain_address: str
instant_settlement: bool
time: Union[str, float]
time: datetime
status: str
boltz_id: str
preimage: str
Expand Down Expand Up @@ -85,7 +86,7 @@ class AutoReverseSubmarineSwap(BaseModel):
balance: int
onchain_address: str
instant_settlement: bool
time: Union[str, float]
time: datetime
count: int


Expand Down
397 changes: 202 additions & 195 deletions poetry.lock

Large diffs are not rendered by default.

13 changes: 5 additions & 8 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,11 @@ async def on_invoice_paid(payment: Payment) -> None:
# not a boltz invoice
return

await payment.set_pending(False)

if payment.extra:
swap_id = payment.extra.get("swap_id")
if swap_id:
swap = await get_submarine_swap(swap_id)
if swap:
await update_swap_status(swap_id, "complete")
swap_id = payment.extra.get("swap_id")
if swap_id:
swap = await get_submarine_swap(swap_id)
if swap:
await update_swap_status(swap_id, "complete")


async def check_for_auto_swap(payment: Payment) -> None:
Expand Down
11 changes: 4 additions & 7 deletions templates/boltz/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@
field: 'time',
sortable: true,
format: function (val, row) {
const value = parseFloat(val) * 1000
return new Date(value).toUTCString()
return new Date(val).toLocaleString()
}
},
{
Expand Down Expand Up @@ -195,8 +194,7 @@
field: 'time',
sortable: true,
format: function (val, row) {
const value = parseFloat(val) * 1000
return new Date(value).toUTCString()
return new Date(val).toLocaleString()
}
},
{
Expand Down Expand Up @@ -268,8 +266,7 @@
field: 'time',
sortable: true,
format: function (val, row) {
const value = parseFloat(val) * 1000
return new Date(value).toUTCString()
return new Date(val).toLocaleString()
}
},
{
Expand Down Expand Up @@ -487,7 +484,7 @@
status: res.data.status,
mempool: res.data.mempool,
timeout_block_height: res.data.timeout_block_height,
date: new Date().toUTCString()
date: new Date().toLocaleString()
}
this.statusDialog.show = true
})
Expand Down

0 comments on commit 2b14deb

Please sign in to comment.