Skip to content

Wallet v2 #2169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 173 commits into
base: master
Choose a base branch
from
Open

Wallet v2 #2169

wants to merge 173 commits into from

Conversation

ekzyis
Copy link
Member

@ekzyis ekzyis commented May 18, 2025

Description

close #1495 fix #2234

TODOs

  • ✅ refactor vault (Migrate vault entries to new schema #2092)
    • ℹ️ new Vault table no longer contains foreign keys to wallets or users
    • ℹ️ wallets now point to the vault within their config, not separated from it
  • ✅ support multiple receive and send protocols per wallet on the backend (Wallet schema v2 #2146)
    • ℹ️ new wallet schema consists of the following tables:
      • WalletTemplate
      • UserWallet
      • ProtocolWallet
      • table for each send and recv protocol (WalletSendNWC, WalletRecvNWC, ...)
  • ✅ store send and receive config in separate tables for easier integrity checks (Wallet schema v2 #2146)
  • ✅ JSDoc for protocols
    • ✅ wallets/lib (shared by client and server)
    • ✅ wallets/client
    • ✅ wallets/server
  • ✅ separate wallets from protocols in frontend for better UX
    • ℹ️ we now show cards of wallets which have protocols inside of them
    • ℹ️ users can easier find a wallet to attach by just looking at their names/logos, instead of having to know if they have a wallet that supports a protocol that we also support
  • ✅ create a list of wallets with the protocols they support
    • ✅ insert wallets with protocol support into static WalletTemplate table
    • ✅ double-check protocol support per wallet and if I missed any
    • add placeholder wallets like Phoenix?
    • ✅ proper input labels, placeholder, help etc. (compare with master)
  • ✅ restructure wallets/ folder
    • ℹ️ client/server wallet imports are now split on the highest level: client only imports stuff from wallets/client/ and server only from wallets/server/
    • ℹ️ everything (exclusively) wallet related, including validation, was moved to the wallets/ folder
  • ✅ wallet I/O
    • ✅ load plaintext wallets
    • ✅ load encrypted wallets
    • ✅ save plaintext wallets
    • ✅ save encrypted wallets
    • ✅ client-side form validation
    • ✅ server-side form validation
    • ✅ wallet network tests
    • ✅ save LNC (requires generating other fields)
    • ✅ create new wallets from template
    • ✅ fix LND gRPC macaroon transform to invalid value 🤔
  • ✅ wallet API
    • ✅ payments
    • ✅ invoices
  • ✅ update existing code to use wallet v2 API
    • ✅ send p2p zap
    • ✅ receive p2p zap
    • ✅ lightning address
    • ✅ autowithdrawals
    • ✅ manual withdrawals
  • 🚧 let users search for their wallet
    • ℹ️ (fuzzy) search should have autocomplete for wallet names
  • include wizard / multi-step forms probably not in this PR
  • ✅ wallet encryption
    • ✅ remove the requirement to have device sync enabled for a gun
      • ℹ️ wallets are now always encrypted and saved on server
    • ✅ generate key by default
    • ✅ show locked wallets if wrong key and prompt to enter passphrase
    • ✅ encrypt wallets with new key on passphrase export
    • ✅ reset option if passphrase lost
  • ✅ wallet migration
    • ✅ migration of old CryptoKey
    • ✅ migrate local wallets (device sync was not enabled)
    • ✅ merge local wallets with existing wallets during migration
      • ℹ️ local wallets currently create a wallet separate from existing receiving credentials
  • 🚧 wallet status
    • ℹ️ set wallet send/recv status via trigger instead of deriving from logs
  • ✅ wallet logs
    • ✅ always store all wallet logs on the server
      • ℹ️ no code to manage different sources
      • ℹ️ consistent logs across all devices
    • show status of wallet network tests on attach in dedicated UI instead of relying on wallet logs
    • don't show "logs", show wallet events like a wallet
      • ℹ️ this means that there won't be multiple log messages for the same payment. we will just show the current status of a payment, just like a wallet would do.
    • ✅ wallet logs for templates
    • ✅ pagination
    • ✅ log message context
  • ✅ wallet settings
    • ✅ detach
    • ✅ enabled
    • ✅ priority via DnD
    • ✅ priority via DnD on mobile
    • ✅ (global) limits (dust, fee, balance)
  • ✅ create another wallet from a template when there's already one
  • ✅ make sure state is updated when a wallet is updated (WALLETS vs WALLET query)
    • ✅ refetch WALLET on save or detach
    • ✅ refetch WALLETS if wallets changed
  • ✅ handle device-dependant wallets like WebLN
  • ✅ append and validate domain in lightning address input
  • ✅ make sure this fixes duplicate lost hat/horse when wallet is disabled #2234
  • ✅ update lightning address form in wallet receive prompt
  • ✅ update code to pay QR code with WebLN
  • ✅ split CUSTOM wallet into NWC and LN_ADDR wallet
  • ✅ handle IndexedDB not available
  • ✅ Q&A:
    • can key hash and wallet encryption get out of sync?
      • ℹ️ in that case, the passphrase prompt would ask for the wrong key
      • ✅ update: we now always compare key hashes on the server
    • ✅ payments
    • ✅ migration

Additional context

I will do

  • derived wallet status
  • wallet search

in a follow-up PR to not block the review of this PR any longer.

Screenshots

we now show wallets instead of protocols:

2025-06-28-011954_1920x1080_scrot

each wallet can now support multiple protocols for send or receive:

2025-06-28-012050_1920x1080_scrot

Checklist

Are your changes backwards compatible? Please answer below:

no

On a scale of 1-10 how well and how have you QA'd this change and any features it might affect? Please answer below:

8

  • migration was tested with prod db dump and docker/db/wallet-seed.sql. seed contains some wallets for test_wallet_v2 user.
  • passphrase for seed wallets: media fit youth secret combine live cupboard response enable loyal kitchen angle

For frontend changes: Tested on mobile, light and dark mode? Please answer below:

yes

Did you introduce any new environment variables? If so, call them out explicitly here:

no

@ekzyis ekzyis added the wallets label May 18, 2025
Copy link

gitguardian bot commented May 18, 2025

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secret in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
16991000 Triggered Generic High Entropy Secret e476705 docker/db/wallet-seed.sql View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@ekzyis ekzyis marked this pull request as draft May 18, 2025 05:22
@ekzyis ekzyis force-pushed the wallet-v2 branch 16 times, most recently from 8ab0a08 to afcc412 Compare May 23, 2025 22:58
@ekzyis ekzyis force-pushed the wallet-v2 branch 5 times, most recently from d9af095 to e94cfe7 Compare May 31, 2025 09:04
@ekzyis ekzyis force-pushed the wallet-v2 branch 6 times, most recently from 412f2c6 to 690b10b Compare June 4, 2025 13:16
@ekzyis ekzyis marked this pull request as ready for review June 28, 2025 19:46
@ekzyis ekzyis requested a review from huumn June 28, 2025 19:46
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Promise Handling and Feedback Timing Issues

The onClick handler in DeleteWalletLogsObstacle attempts to both resolve (onDelete()) and reject (onClose()) the same promise in its success path, which is invalid. Furthermore, the success toast is displayed after the modal is closed by onClose(), potentially hiding the feedback. The onClose() call should be removed from the success path, and the toast should be displayed before the modal closes.

wallets/client/hooks/logger.js#L194-L205

const onClick = useCallback(async () => {
try {
await deleteLogs()
onDelete()
onClose()
toaster.success('deleted wallet logs')
} catch (err) {
console.error('failed to delete wallet logs:', err)
toaster.danger('failed to delete wallet logs')
}
}, [onClose, deleteLogs, toaster])

Fix in Cursor


Bug: Template Log ID Precision Issue

Template logs use Date.now() as their ID, which can lead to duplicate IDs if multiple logs are created within the same millisecond. This causes React rendering issues due to duplicate keys and potential log management problems. A TODO comment in the code acknowledges this and suggests using window.performance.now() for better precision.

wallets/client/hooks/logger.js#L15-L18

const addTemplateLog = useCallback(({ level, message }) => {
// TODO(wallet-v2): Date.now() might return the same value for two logs
// use window.performance.now() instead?
setTemplateLogs(prev => [{ id: Date.now(), level, message, createdAt: new Date() }, ...prev])

Fix in Cursor


Bug: `useEffectOnce` Hook Ignores Dependency Changes

The useEffectOnce hook accepts a deps parameter, but the user-provided effect function (func) only executes once. This is because didMount.current prevents func() from being called on subsequent renders, even when deps change and trigger the underlying useEffect to re-run. Consequently, the deps parameter is effectively ignored after the initial execution, leading to inconsistent behavior.

components/use-effect-once.js#L6-L14

export default function useEffectOnce (func, deps) {
const didMount = useRef(false)
useEffect(() => {
if (!didMount.current) {
didMount.current = true
return func()
}
}, deps)

Fix in Cursor


Was this report helpful? Give feedback by reacting with 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

duplicate lost hat/horse when wallet is disabled redesign of attached wallet page
1 participant