Browse Source

fix /wallet for usr&nme case.

fee_issues
fiatjaf 5 years ago
parent
commit
ad1c561862
  1. 19
      LNbits/__init__.py

19
LNbits/__init__.py

@ -111,7 +111,7 @@ def lnurlwallet():
def wallet(): def wallet():
usr = request.args.get("usr") usr = request.args.get("usr")
wallet_id = request.args.get("wal") wallet_id = request.args.get("wal")
wallet_name = request.args.get("nme") or DEFAULT_USER_WALLET_NAME wallet_name = request.args.get("nme")
# just usr: return a the first user wallet or create one if none found # just usr: return a the first user wallet or create one if none found
# usr and wallet_id: return that wallet or create it if it doesn't exist # usr and wallet_id: return that wallet or create it if it doesn't exist
@ -139,11 +139,14 @@ def wallet():
user_wallets = db.fetchall("SELECT * FROM wallets WHERE user = ?", (usr,)) user_wallets = db.fetchall("SELECT * FROM wallets WHERE user = ?", (usr,))
if not wallet_id: if not wallet_id:
# if not given, fetch the first wallet from this user or create if user_wallets and not wallet_name:
# ------------------------------------------------------------- # fetch the first wallet from this user
if user_wallets: # -------------------------------------
wallet_id = user_wallets[0]["id"] wallet_id = user_wallets[0]["id"]
else: else:
# create for this user
# --------------------
wallet_name = wallet_name or DEFAULT_USER_WALLET_NAME
wallet_id = uuid.uuid4().hex wallet_id = uuid.uuid4().hex
db.execute( db.execute(
""" """
@ -159,13 +162,15 @@ def wallet():
# ------------------------------------------------------------ # ------------------------------------------------------------
db.execute( db.execute(
""" """
INSERT OR REPLACE INTO wallets (id, name, user, adminkey, inkey) INSERT OR REPLACE INTO wallets (id, user, name, adminkey, inkey)
VALUES (?, ?, ?, VALUES (?, ?,
coalesce((SELECT name FROM wallets WHERE id = ?), ?),
coalesce((SELECT adminkey FROM wallets WHERE id = ?), ?), coalesce((SELECT adminkey FROM wallets WHERE id = ?), ?),
coalesce((SELECT inkey FROM wallets WHERE id = ?), ?) coalesce((SELECT inkey FROM wallets WHERE id = ?), ?)
) )
""", """,
(wallet_id, wallet_name, usr, (wallet_id, usr,
wallet_id, wallet_name or DEFAULT_USER_WALLET_NAME,
wallet_id, uuid.uuid4().hex, wallet_id, uuid.uuid4().hex,
wallet_id, uuid.uuid4().hex), wallet_id, uuid.uuid4().hex),
) )

Loading…
Cancel
Save