Skip to content

Commit c190946

Browse files
authored
Merge pull request #67 from lnbits/atm_pin_toggle
Atm pin toggle
2 parents 30dfae3 + 83775c2 commit c190946

File tree

7 files changed

+186
-362
lines changed

7 files changed

+186
-362
lines changed

crud.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ async def create_tpos(wallet_id: str, data: CreateTposData) -> TPoS:
2121
tpos_id = urlsafe_short_hash()
2222
await db.execute(
2323
"""
24-
INSERT INTO tpos.pos (id, wallet, name, currency, tip_options, tip_wallet, withdrawlimit, withdrawpin, withdrawamt, withdrawtime, withdrawbtwn)
25-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
24+
INSERT INTO tpos.pos (id, wallet, name, currency, tip_options, tip_wallet, withdrawlimit, withdrawpin, withdrawamt, withdrawtime, withdrawbtwn, withdrawtimeopt, withdrawpindisabled)
25+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2626
""",
2727
(
2828
tpos_id,
@@ -36,6 +36,8 @@ async def create_tpos(wallet_id: str, data: CreateTposData) -> TPoS:
3636
0,
3737
0,
3838
data.withdrawbtwn,
39+
data.withdrawtimeopt,
40+
data.withdrawpindisabled,
3941
),
4042
)
4143
tpos = await get_tpos(tpos_id)
@@ -53,7 +55,9 @@ async def start_lnurlcharge(tpos_id: str):
5355
assert tpos, f"TPoS with {tpos_id} not found!"
5456

5557
now = await get_current_timestamp()
56-
withdraw_time_seconds = tpos.withdrawbtwn * 60
58+
withdraw_time_seconds = (
59+
tpos.withdrawbtwn * 60 if tpos.withdrawtimeopt != "secs" else tpos.withdrawbtwn
60+
)
5761
assert (
5862
now - tpos.withdrawtime > withdraw_time_seconds
5963
), f"Last withdraw was made too recently, please try again in {int(withdraw_time_seconds - (now - tpos.withdrawtime))} secs"
@@ -105,7 +109,9 @@ async def update_tpos_withdraw(data: TPoS, tpos_id: str) -> TPoS:
105109
# Calculate the time between withdrawals in seconds
106110
now = await get_current_timestamp()
107111
time_elapsed = now - data.withdrawtime
108-
withdraw_time_seconds = data.withdrawbtwn * 60
112+
withdraw_time_seconds = (
113+
data.withdrawbtwn * 60 if data.withdrawtimeopt != "secs" else data.withdrawbtwn
114+
)
109115

110116
logger.debug(f"Time between: {time_elapsed} seconds")
111117

migrations.py

+9
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,12 @@ async def m007_atm_premium(db):
106106
Add a premium % to ATM withdraws
107107
"""
108108
await db.execute("ALTER TABLE tpos.pos ADD COLUMN withdrawpremium FLOAT;")
109+
110+
111+
112+
async def m008_atm_time_option_and_pin_toggle(db):
113+
"""
114+
Add a time mins/sec and pin toggle
115+
"""
116+
await db.execute("ALTER TABLE tpos.pos ADD COLUMN withdrawtimeopt TEXT DEFAULT 'mins';")
117+
await db.execute("ALTER TABLE tpos.pos ADD COLUMN withdrawpindisabled BOOL NOT NULL DEFAULT false;")

models.py

+6
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ class CreateTposData(BaseModel):
1818
withdrawpin: int = Field(None, ge=1)
1919
withdrawamt: int = Field(None, ge=0)
2020
withdrawtime: int = Field(0)
21+
withdrawtimeopt: Optional[str]
2122
withdrawbtwn: int = Field(10, ge=1)
2223
withdrawpremium: float = Field(None)
24+
withdrawpindisabled: bool = Field(False)
2325

2426

2527
class TPoS(BaseModel):
@@ -33,8 +35,10 @@ class TPoS(BaseModel):
3335
withdrawpin: Optional[int]
3436
withdrawamt: int
3537
withdrawtime: int
38+
withdrawtimeopt: Optional[str]
3639
withdrawbtwn: int
3740
withdrawpremium: Optional[float]
41+
withdrawpindisabled: Optional[bool]
3842
items: Optional[str]
3943

4044
@classmethod
@@ -54,8 +58,10 @@ class TPoSClean(BaseModel):
5458
withdrawlimit: Optional[int]
5559
withdrawamt: int
5660
withdrawtime: int
61+
withdrawtimeopt: Optional[str]
5762
withdrawbtwn: int
5863
withdrawpremium: Optional[float]
64+
withdrawpindisabled: Optional[bool]
5965
items: Optional[str]
6066

6167
@classmethod

0 commit comments

Comments
 (0)