diff --git a/crud.py b/crud.py
index 9fe889b..70a54fb 100644
--- a/crud.py
+++ b/crud.py
@@ -22,14 +22,15 @@ async def create_tpos(data: CreateTposData) -> Tpos:
tpos_id = urlsafe_short_hash()
tpos = Tpos(id=tpos_id, **data.dict())
await db.execute(
- insert_query("tpos.pos", data),
- data.dict(),
+ insert_query("tpos.pos", tpos),
+ tpos.dict(),
)
return tpos
async def get_tpos(tpos_id: str) -> Optional[Tpos]:
row = await db.fetchone("SELECT * FROM tpos.pos WHERE id = :id", {"id": tpos_id})
+ print(row)
return Tpos(**row) if row else None
@@ -39,13 +40,15 @@ async def start_lnurlcharge(tpos_id: str):
now = await get_current_timestamp()
withdraw_time_seconds = (
- tpos.withdrawbtwn * 60 if tpos.withdrawtimeopt != "secs" else tpos.withdrawbtwn
+ tpos.withdraw_between * 60
+ if tpos.withdraw_time_option != "secs"
+ else tpos.withdraw_between
)
assert (
- now - tpos.withdrawtime > withdraw_time_seconds
+ now - tpos.withdraw_time > withdraw_time_seconds
), f"""
Last withdraw was made too recently, please try again in
- {int(withdraw_time_seconds - (now - tpos.withdrawtime))} secs
+ {int(withdraw_time_seconds - (now - tpos.withdraw_time))} secs
"""
token = urlsafe_short_hash()
@@ -87,9 +90,11 @@ async def get_clean_tpos(tpos_id: str) -> Optional[TposClean]:
async def update_tpos_withdraw(data: Tpos, tpos_id: str) -> Tpos:
# Calculate the time between withdrawals in seconds
now = await get_current_timestamp()
- time_elapsed = now - data.withdrawtime
+ time_elapsed = now - data.withdraw_time
withdraw_time_seconds = (
- data.withdrawbtwn * 60 if data.withdrawtimeopt != "secs" else data.withdrawbtwn
+ data.withdraw_between * 60
+ if data.withdraw_time_option != "secs"
+ else data.withdraw_between
)
logger.debug(f"Time between: {time_elapsed} seconds")
diff --git a/migrations.py b/migrations.py
index 3726220..fe15899 100644
--- a/migrations.py
+++ b/migrations.py
@@ -129,3 +129,28 @@ async def m009_tax_inclusive(db):
"ALTER TABLE tpos.pos ADD COLUMN tax_inclusive BOOL NOT NULL DEFAULT true;"
)
await db.execute("ALTER TABLE tpos.pos ADD COLUMN tax_default FLOAT DEFAULT 0;")
+
+
+async def m010_rename_tpos_withdraw_columns(db):
+ """
+ Add rename tpos withdraw columns
+ """
+ await db.execute(
+ """
+ CREATE TABLE tpos.pos_backup AS
+ SELECT
+ id, name, currency, items, wallet, tax_inclusive,
+ tax_default, tip_wallet, tip_options,
+ withdrawtime AS withdraw_time,
+ withdrawbtwn AS withdraw_between,
+ withdrawlimit AS withdraw_limit,
+ withdrawamt AS withdraw_amount,
+ withdrawtimeopt AS withdraw_time_option,
+ withdrawpremium AS withdraw_premium,
+ withdrawpindisabled AS withdraw_pin_disabled,
+ withdrawpin AS withdraw_pin
+ FROM tpos.pos
+ """
+ )
+ await db.execute("DROP TABLE tpos.pos")
+ await db.execute("ALTER TABLE tpos.pos_backup RENAME TO pos")
diff --git a/models.py b/models.py
index 00298ca..9dfd0fd 100644
--- a/models.py
+++ b/models.py
@@ -10,45 +10,47 @@ class CreateTposData(BaseModel):
wallet: Optional[str]
name: Optional[str]
currency: Optional[str]
- tip_options: str = Field("[]")
- tip_wallet: str = Field("")
- withdrawlimit: int = Field(None, ge=1)
- withdrawpin: int = Field(None, ge=1)
- withdrawamt: int = Field(None, ge=0)
- withdrawtime: int = Field(0)
- withdrawtimeopt: Optional[str]
- withdrawbtwn: int = Field(10, ge=1)
- withdrawpremium: float = Field(None)
- withdrawpindisabled: bool = Field(False)
tax_inclusive: bool = Field(True)
tax_default: float = Field(None)
+ tip_options: str = Field("[]")
+ tip_wallet: str = Field("")
+ withdraw_time: int = Field(0)
+ withdraw_between: int = Field(10, ge=1)
+ withdraw_limit: Optional[int] = Field(None, ge=1)
+ withdraw_pin: Optional[int] = Field(None, ge=1)
+ withdraw_amount: Optional[int] = Field(None, ge=0)
+ withdraw_time_option: Optional[str] = Field(None)
+ withdraw_premium: Optional[float] = Field(None)
+ withdraw_pin_disabled: bool = Field(False)
class TposClean(BaseModel):
id: str
name: str
currency: str
- tip_options: Optional[str]
- withdrawlimit: Optional[int]
- withdrawamt: int
- withdrawtime: int
- withdrawtimeopt: Optional[str]
- withdrawbtwn: int
- withdrawpremium: Optional[float]
- withdrawpindisabled: Optional[bool]
- items: Optional[str]
tax_inclusive: bool
- tax_default: Optional[float]
+ tax_default: Optional[float] = None
+ withdraw_time: int
+ withdraw_between: int
+ withdraw_limit: Optional[int] = None
+ withdraw_amount: Optional[int] = None
+ withdraw_time_option: Optional[str] = None
+ withdraw_premium: Optional[float] = None
+ withdraw_pin_disabled: Optional[bool] = None
+ items: Optional[str] = None
+ tip_options: Optional[str] = None
@property
- def withdrawamtposs(self) -> int:
- return self.withdrawlimit - self.withdrawamt if self.withdrawlimit else 0
+ def withdraw_maximum(self) -> int:
+ if not self.withdraw_amount or not self.withdraw_limit:
+ return 0
+ return self.withdraw_limit - self.withdraw_amount
class Tpos(TposClean, BaseModel):
wallet: str
- tip_wallet: Optional[str]
- withdrawpin: Optional[int]
+ tip_wallet: Optional[str] = None
+ withdraw_pin: Optional[int] = None
class LnurlCharge(BaseModel):
diff --git a/static/js/tpos.js b/static/js/tpos.js
index 8ade174..f659a47 100644
--- a/static/js/tpos.js
+++ b/static/js/tpos.js
@@ -11,9 +11,9 @@ const tposJS = async () => {
return {
tposId: tpos.id,
currency: tpos.currency,
- withdrawamtposs: tpos.withdrawamtposs,
- atmPremium: tpos.withdrawpremium / 100,
- withdrawpinopen: withdrawpinopen,
+ atmPremium: tpos.withdraw_premium / 100,
+ withdraw_maximum: withdraw_maximum,
+ withdraw_pin_open: withdraw_pin_open,
tip_options: null,
exchangeRate: null,
stack: [],
@@ -262,12 +262,12 @@ const tposJS = async () => {
if (this.atmPremium > 0) {
this.exchangeRate = this.exchangeRate / (1 + this.atmPremium)
}
- if (this.withdrawpinopen != 0) {
- this.atmPin = this.withdrawpinopen
+ if (this.withdraw_pin_open != 0) {
+ this.atmPin = this.withdraw_pin_open
this.atmSubmit()
return
}
- if (this.withdrawamtposs > 0) {
+ if (this.withdraw_maximum > 0) {
this.atmBox = true
}
},
@@ -289,7 +289,7 @@ const tposJS = async () => {
atmGetWithdraw: function () {
self = this
var dialog = this.invoiceDialog
- if (this.sat > this.withdrawamtposs) {
+ if (this.sat > this.withdraw_maximum) {
this.$q.notify({
type: 'negative',
message: 'Amount exceeds the maximum withdrawal limit.'
@@ -710,7 +710,7 @@ const tposJS = async () => {
created: function () {
var getRates = this.getRates
getRates()
- this.pinDisabled = tpos.withdrawpindisabled
+ this.pinDisabled = tpos.withdraw_pin_disabled
this.taxInclusive = tpos.tax_inclusive
this.taxDefault = tpos.tax_default
diff --git a/templates/tpos/index.html b/templates/tpos/index.html
index ea47174..99f9022 100644
--- a/templates/tpos/index.html
+++ b/templates/tpos/index.html
@@ -7,7 +7,7 @@