Skip to content

Commit

Permalink
Merge pull request #67 from lnbits/atm_pin_toggle
Browse files Browse the repository at this point in the history
Atm pin toggle
  • Loading branch information
arcbtc authored Feb 11, 2024
2 parents 30dfae3 + 83775c2 commit c190946
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 362 deletions.
14 changes: 10 additions & 4 deletions crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ async def create_tpos(wallet_id: str, data: CreateTposData) -> TPoS:
tpos_id = urlsafe_short_hash()
await db.execute(
"""
INSERT INTO tpos.pos (id, wallet, name, currency, tip_options, tip_wallet, withdrawlimit, withdrawpin, withdrawamt, withdrawtime, withdrawbtwn)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
INSERT INTO tpos.pos (id, wallet, name, currency, tip_options, tip_wallet, withdrawlimit, withdrawpin, withdrawamt, withdrawtime, withdrawbtwn, withdrawtimeopt, withdrawpindisabled)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""",
(
tpos_id,
Expand All @@ -36,6 +36,8 @@ async def create_tpos(wallet_id: str, data: CreateTposData) -> TPoS:
0,
0,
data.withdrawbtwn,
data.withdrawtimeopt,
data.withdrawpindisabled,
),
)
tpos = await get_tpos(tpos_id)
Expand All @@ -53,7 +55,9 @@ async def start_lnurlcharge(tpos_id: str):
assert tpos, f"TPoS with {tpos_id} not found!"

now = await get_current_timestamp()
withdraw_time_seconds = tpos.withdrawbtwn * 60
withdraw_time_seconds = (
tpos.withdrawbtwn * 60 if tpos.withdrawtimeopt != "secs" else tpos.withdrawbtwn
)
assert (
now - tpos.withdrawtime > withdraw_time_seconds
), f"Last withdraw was made too recently, please try again in {int(withdraw_time_seconds - (now - tpos.withdrawtime))} secs"
Expand Down Expand Up @@ -105,7 +109,9 @@ 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
withdraw_time_seconds = data.withdrawbtwn * 60
withdraw_time_seconds = (
data.withdrawbtwn * 60 if data.withdrawtimeopt != "secs" else data.withdrawbtwn
)

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

Expand Down
9 changes: 9 additions & 0 deletions migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,12 @@ async def m007_atm_premium(db):
Add a premium % to ATM withdraws
"""
await db.execute("ALTER TABLE tpos.pos ADD COLUMN withdrawpremium FLOAT;")



async def m008_atm_time_option_and_pin_toggle(db):
"""
Add a time mins/sec and pin toggle
"""
await db.execute("ALTER TABLE tpos.pos ADD COLUMN withdrawtimeopt TEXT DEFAULT 'mins';")
await db.execute("ALTER TABLE tpos.pos ADD COLUMN withdrawpindisabled BOOL NOT NULL DEFAULT false;")
6 changes: 6 additions & 0 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ class CreateTposData(BaseModel):
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)


class TPoS(BaseModel):
Expand All @@ -33,8 +35,10 @@ class TPoS(BaseModel):
withdrawpin: Optional[int]
withdrawamt: int
withdrawtime: int
withdrawtimeopt: Optional[str]
withdrawbtwn: int
withdrawpremium: Optional[float]
withdrawpindisabled: Optional[bool]
items: Optional[str]

@classmethod
Expand All @@ -54,8 +58,10 @@ class TPoSClean(BaseModel):
withdrawlimit: Optional[int]
withdrawamt: int
withdrawtime: int
withdrawtimeopt: Optional[str]
withdrawbtwn: int
withdrawpremium: Optional[float]
withdrawpindisabled: Optional[bool]
items: Optional[str]

@classmethod
Expand Down
Loading

0 comments on commit c190946

Please sign in to comment.