Skip to content

fix(receive): handle tokens with unsupported units gracefully - #1036

Merged
gudnuf merged 1 commit into
masterfrom
fix/handle-unsupported-token-unit
May 8, 2026
Merged

gudnuf merged 1 commit into
masterfrom
fix/handle-unsupported-token-unit

Conversation

@gudnuf

@gudnuf gudnuf commented Apr 28, 2026 •

Copy link
Copy Markdown
Contributor

On master when a user inputs a token with an unsupported unit the app crashes:

image

This PR makes the UI handle the error by not building the source account (because we can't convert the token amount to Money) and rendering the error display.

You can test with this token which has a unit of eur:

cashuBo2FteBtodHRwczovL3Rlc3RudXQuY2FzaHUuc3BhY2VhdWNldXJhdIGiYWlIAcl-4uZMFwhhcIWkYWEQYXN4QDY1NGU2ZjAzOTUyNTkyNmYwYjQ2ZmFkMGEyOWUxY2EwMzUxMDRmYmY3NTc0MmJmZTBjMTBlOWQ0ZGY0Y2IwMWFhY1ghA4PYroqlkDOr2wihN_PetoV7Hb1dN25CaJZCZ7CF1ahMYWSjYWVYIP9C1b64EWSH0kIazyN5WqP7oJiWQCOBHr_kja2kLpzMYXNYIASN9_hjQrcZwmRwOyISoxoNZuUMyOCLvy8mKnu5JWmqYXJYIB7jqp4iJAWwFfq8SJzGe6-kevml5alCTsMjMTNbBAaepGFhAmFzeEA1Y2Y0MDE1ZmMwNDk2MmViYWZmMDcxZWQwNDRmOGYyZDk4M2JkZmVmNzZhMTdlOWJjYzU0YzI5YTJkOWMyNGRiYWNYIQMPFDvthb0w8HDtbMmpR0ORqr8BwYJYdkWr1cP0b8p5JWFko2FlWCC9T_88HKPnuVHo1u4te6fiaiyS6TdFWo74zkDmAjHTO2FzWCAKqbxFulHwz01jNRCDK748GooahWNNQyE-NiznhQpwymFyWCDWqVP-gzwg9ZUsWP_L28elZcHuTDVUt2xjAQLVxPfEK6RhYQFhc3hANmYxYjBlZDllNDkyYjc5MWYzMzAzYWYzODlmNmVkMDFkMzlhMGRmZjlkNGZlYjkxZTYwM2EzOTdmMDRiMjVlZmFjWCEDyZiV9Sn-894-AjeMXzfEPbnqqJ4if7Cw_iTX5w3Wp4JhZKNhZVgg4m9L5Eh6llNlHe90Kf7k-2YwqM4dzyGG6NiV5cUAVUJhc1ggK4J7iE0YcgOpuCkt6XUQhxxvuppag3CdOBDkBrzuK0thclggjgrYOYB_opSy68FryfAUD9VCa7uKrozMIc7b5L2infSkYWEBYXN4QGIzZWUxMWVjY2IwNGU1NTcxMzRkMWQyNTA3MzBkMGY4MDgxZmFhYWY5YWM5MjNmNTM3NzJkNWIwMDBmYTZjMWFhY1ghAm3WP40PcibFplJzG3iCH9VxXvQ1XxZe8LqVqVo76l55YWSjYWVYIC_qkOlb6hHKFhk5F2XDvsWHeEcFPWeSXNnbL7W8zwCxYXNYID3abf4Y6uVnTZ6VQjVl6_8F34dHcNHMfbYmrecJG8BgYXJYIIhMmTXTFzoA3Glimd5neChXTIMR7ldeVzJLTwIMTCEMpGFhAWFzeEA5N2RlMmZlYzVkNDVmZDdiNmEwN2JjNTQxZmM5YmU3MmYzN2MwZDFjZDYyZDY2NjVkYTUzZDNiM2U4N2ZjMzQ5YWNYIQJZpl2d91gtJ49IzcOlUGmREDHCqmyn3zFJDIhx_KeskGFko2FlWCCA6PGKut-yg8MOoUjXnlrPf6_6nGS_9qrPeemyxAI3kWFzWCDSJ2GGdWHvd3M3NKS-7JZkjI1oIYu18VMFiLOHxzxBOmFyWCAXf2UiTFEpMxJJXkWcvj5BWKo95QCSPXdeEI_OZFNoLA

@vercel

vercel Bot commented Apr 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agicash Ready Ready Preview, Comment May 8, 2026 3:57pm

Request Review

@supabase

supabase Bot commented Apr 28, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project hrebgkfhjpkbxpztqqke because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@gudnuf
gudnuf requested a review from jbojcic1 April 28, 2026 17:36
@gudnuf gudnuf self-assigned this Apr 28, 2026
@gudnuf
gudnuf marked this pull request as ready for review April 28, 2026 17:37
Comment thread app/features/accounts/account.ts Outdated
Comment thread app/features/shared/cashu.ts Outdated
Comment thread app/features/shared/cashu.ts Outdated
Comment thread app/features/receive/receive-cashu-token-hooks.ts Outdated
Comment thread app/features/receive/claim-cashu-token-service.ts Outdated
Comment thread app/features/receive/receive-cashu-token-hooks.ts Outdated
Comment thread app/features/receive/receive-cashu-token.tsx Outdated
Comment thread app/features/receive/receive-cashu-token.tsx Outdated
Comment thread app/features/send/share-cashu-token.tsx Outdated
Comment thread app/features/shared/cashu.ts
Comment thread app/features/shared/cashu.ts
Comment thread app/routes/_protected.receive.cashu_.token.tsx Outdated
Comment thread app/features/receive/receive-cashu-token-unsupported-page.tsx Outdated
Comment thread app/features/receive/receive-cashu-token-unsupported-page.tsx Outdated
Comment thread app/features/receive/receive-cashu-token-unsupported-page.tsx Outdated
@gudnuf

gudnuf commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

@jbojcic1 i completely changed the approach to just validate the token in the route loader rather than trying to thread unsupported tokens through the actual receive flow

@gudnuf
gudnuf requested a review from jbojcic1 May 1, 2026 21:29

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would call this unsupported cashu token page. The token is not invalid but just not supported by our wallet atm.

Comment thread app/lib/cashu/utils.ts Outdated
};

const cashuProtocolUnitToCurrency: {
export const cashuProtocolUnitToCurrency: {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would create some validate token method and export that

loaderData,
}: Route.ComponentProps) {
const { token } = loaderData;
if (!loaderData.valid) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd call this loader data property isTokenSupported

@gudnuf

gudnuf commented May 6, 2026

Copy link
Copy Markdown
Contributor Author

@jbojcic1 I took all your suggestions

Pasting or deep-linking a Cashu token whose unit isn't sat or usd
crashed /receive/cashu/token because tokenToMoney threw synchronously
inside render-path hooks.

The route loaders now run validateCashuToken right after decode and
short-circuit to UnsupportedCashuTokenPage with a reason-specific
message. Send flow is unaffected — internally-generated tokens always
have a supported unit derived from Currency. validateCashuToken
returns a discriminated union so future checks (empty proofs,
blocklisted mint, etc.) plug in as additional early-return branches.
@orveth
orveth force-pushed the fix/handle-unsupported-token-unit branch from 13c7eeb to e2835eb Compare May 8, 2026 15:54
@gudnuf
gudnuf merged commit 4788ff2 into master May 8, 2026
5 checks passed
@gudnuf
gudnuf deleted the fix/handle-unsupported-token-unit branch May 8, 2026 15:58

This branch was successfully deployed

1 active deployment
Preview — e2835ebd Deployed May 8, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants