Skip to content

Add Stellar Wallet Linking Endpoint and Trigger On-Chain Player Registration #308

Description

@phertyameen

Description:

The stellarWallet field exists on the User entity and wallet-based login already works via StellarWalletLoginProvider. However, there is no dedicated flow for an existing email/password user to link their Stellar wallet after signup. Additionally, when a wallet is linked — whether through first-time wallet login or manual linking — registerPlayerOnChain is never called. This issue closes both gaps.

Current Behavior:

StellarWalletLoginProvider auto-creates users with a stellarWallet on first wallet login but never calls registerPlayerOnChain
Email/password users have a stellarWallet field that is always null with no way to populate it
BlockchainService.registerPlayerOnChain exists (after Issue 11) but is never triggered anywhere

Expected Behavior:

When a user logs in via Stellar wallet for the first time and a new account is auto-created, registerPlayerOnChain is called automatically
Existing email/password users can link their Stellar wallet via a dedicated endpoint, after which registerPlayerOnChain is called
Re-linking or duplicate registration attempts are handled gracefully

Requirements:

New endpoint:

PATCH /users/link-wallet

  • JWT protected: user must be authenticated
  • Accepts a stellarWallet address in the request body
  • Validates the address is a valid Stellar public key format (the validation logic already exists in AuthService.isValidStellarAddress — reuse it)
  • Checks the wallet is not already linked to another account
  • Saves the wallet to user.stellarWallet
  • After saving, calls blockchainService.registerPlayerOnChain(stellarWallet, username, iqLevel)
  • The iqLevel passed to the contract should be derived from user.level (already on the User entity)

Update StellarWalletLoginProvider:

After the auto-create block where a new user is created, call blockchainService.registerPlayerOnChain(...) with the new user's wallet, username, and level
This call must be non-blocking, wrap in try/catch and do not let it affect the login response

Suggested file to create:

backend/src/users/providers/link-wallet.provider.ts

BlockchainService dependency:

BlockchainService must be injected into UsersModule via BlockchainModule import (covered in Issue 15) before this issue can be completed.

Acceptance Criteria:

  • PATCH /users/link-wallet endpoint exists and is JWT protected
  • The endpoint validates the Stellar address format before saving
  • The endpoint rejects a wallet already linked to a different account
  • registerPlayerOnChain is called after a wallet is successfully linked
  • StellarWalletLoginProvider calls registerPlayerOnChain after auto-creating a new wallet user
  • Both calls are non-blocking and wrapped in try/catch

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fields

    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions