feat: add default pay link creation for users with username in user account setup
This commit is contained in:
parent
e5c39cdbd0
commit
dffc54c0d2
1 changed files with 59 additions and 0 deletions
|
|
@ -86,6 +86,14 @@ async def create_user_account_no_ckeck(
|
|||
except Exception as e:
|
||||
logger.error(f"Error enabeling default extension {ext_id}: {e}")
|
||||
|
||||
# Create default pay link for users with username
|
||||
if account.username and "lnurlp" in user_extensions:
|
||||
try:
|
||||
await _create_default_pay_link(account, wallet) # TODO: determine if this should pass `conn=conn`?
|
||||
logger.info(f"Created default pay link for user {account.username}")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to create default pay link for user {account.username}: {e}")
|
||||
|
||||
user = await get_user_from_account(account, conn=conn)
|
||||
if not user:
|
||||
raise ValueError("Cannot find user for account.")
|
||||
|
|
@ -192,3 +200,54 @@ async def init_admin_settings(super_user: str | None = None) -> SuperSettings:
|
|||
|
||||
editable_settings = EditableSettings.from_dict(settings.dict())
|
||||
return await create_admin_settings(account.id, editable_settings.dict())
|
||||
|
||||
|
||||
async def _create_default_pay_link(account: Account, wallet) -> None:
|
||||
"""Create a default pay link for new users with username (Bitcoinmat receiving address)"""
|
||||
try:
|
||||
# Try dynamic import that works with extensions in different locations
|
||||
import importlib
|
||||
import sys
|
||||
|
||||
# First try the standard import path
|
||||
try:
|
||||
lnurlp_crud = importlib.import_module("lnbits.extensions.lnurlp.crud")
|
||||
lnurlp_models = importlib.import_module("lnbits.extensions.lnurlp.models")
|
||||
except ImportError:
|
||||
# If that fails, try importing from external extensions path
|
||||
# This handles cases where extensions are in /var/lib/lnbits/extensions
|
||||
try:
|
||||
# Add extensions path to sys.path if not already there
|
||||
extensions_path = settings.lnbits_extensions_path or "/var/lib/lnbits/extensions"
|
||||
if extensions_path not in sys.path:
|
||||
sys.path.insert(0, extensions_path)
|
||||
|
||||
lnurlp_crud = importlib.import_module("lnurlp.crud")
|
||||
lnurlp_models = importlib.import_module("lnurlp.models")
|
||||
except ImportError as e:
|
||||
logger.warning(f"lnurlp extension not found in any location: {e}")
|
||||
return
|
||||
|
||||
create_pay_link = lnurlp_crud.create_pay_link
|
||||
CreatePayLinkData = lnurlp_models.CreatePayLinkData
|
||||
|
||||
|
||||
pay_link_data = CreatePayLinkData(
|
||||
description="Bitcoinmat Receiving Address",
|
||||
wallet=wallet.id,
|
||||
# Note default `currency` is satoshis when set as NULL in db
|
||||
min=1, # minimum 1 sat
|
||||
max=500000, # maximum 500,000 sats
|
||||
comment_chars=0,
|
||||
username=account.username, # use the username as lightning address
|
||||
zaps=True,
|
||||
disposable=False,
|
||||
)
|
||||
|
||||
await create_pay_link(pay_link_data)
|
||||
|
||||
logger.info(f"Successfully created default pay link for user {account.username}")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to create default pay link: {e}")
|
||||
# Don't raise - we don't want user creation to fail if pay link creation fails
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue