Skip to content

Commit

Permalink
fix: always create default wallet for user (lnbits#2580)
Browse files Browse the repository at this point in the history
* fix: always create default wallet for user

* no assert in api

---------

Co-authored-by: dni ⚡ <[email protected]>
  • Loading branch information
motorina0 and dni authored Jul 15, 2024
1 parent 1bee84d commit 7d1e22c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
3 changes: 3 additions & 0 deletions lnbits/core/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,7 @@ async def create_user_account(
email: Optional[str] = None,
username: Optional[str] = None,
password: Optional[str] = None,
wallet_name: Optional[str] = None,
user_config: Optional[UserConfig] = None,
) -> User:
if not settings.new_accounts_allowed:
Expand All @@ -805,6 +806,8 @@ async def create_user_account(
password = pwd_context.hash(password) if password else None

account = await create_account(user_id, username, email, password, user_config)
wallet = await create_wallet(user_id=account.id, wallet_name=wallet_name)
account.wallets = [wallet]

for ext_id in settings.lnbits_user_default_extensions:
await update_user_extension(user_id=account.id, extension=ext_id, active=True)
Expand Down
7 changes: 2 additions & 5 deletions lnbits/core/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
satoshis_amount_as_fiat,
)

from ..crud import (
create_wallet,
)
from ..services import create_user_account, perform_lnurlauth

# backwards compatibility for extension
Expand Down Expand Up @@ -69,8 +66,8 @@ async def api_create_account(data: CreateWallet) -> Wallet:
status_code=HTTPStatus.FORBIDDEN,
detail="Account creation is disabled.",
)
account = await create_user_account()
return await create_wallet(user_id=account.id, wallet_name=data.name)
account = await create_user_account(wallet_name=data.name)
return account.wallets[0]


@api_router.get("/api/v1/lnurlscan/{code}")
Expand Down

0 comments on commit 7d1e22c

Please sign in to comment.