Skip to content

handle offline mints in the UI#672

Merged
gudnuf merged 1 commit intomasterfrom
offline-mints
Oct 21, 2025
Merged

handle offline mints in the UI#672
gudnuf merged 1 commit intomasterfrom
offline-mints

Conversation

@gudnuf
Copy link
Copy Markdown
Contributor

@gudnuf gudnuf commented Oct 9, 2025

closes #595

If fetching any of the mint data fails with a NetworkError, we flag the account as offline. Now the account will be loaded into the app with isOnline: false, so we can handle offline mints in the UI by adding "Offline" badges and disabling usage of the account.

I also filter out any pending token-swaps, send-swaps, receive-quotes, and send-quotes where the accounId is offline.

@gudnuf gudnuf requested a review from jbojcic1 October 9, 2025 21:40
@gudnuf gudnuf self-assigned this Oct 9, 2025
@vercel
Copy link
Copy Markdown

vercel Bot commented Oct 9, 2025

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

Project Deployment Preview Comments Updated (UTC)
agicash Ready Ready Preview Comment Oct 20, 2025 11:18pm

💡 Enable Vercel Agent with $100 free credit for automated AI reviews

Comment thread app/features/user/user-hooks.tsx Outdated
@gudnuf gudnuf added the P1 High label Oct 9, 2025
Comment thread app/features/accounts/account-service.ts Outdated
Comment thread app/features/accounts/account-hooks.ts Outdated
Comment thread app/features/accounts/account-hooks.ts Outdated
Comment thread app/features/shared/cashu.ts Outdated
Comment thread app/features/shared/error.ts Outdated
}
}

export const accountOfflineToast = {
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.

should this maybe go into accounts feature?

Comment thread app/features/settings/accounts/all-accounts.tsx Outdated
Comment thread app/features/send/send-input.tsx Outdated
inputValue: Money,
convertedValue: Money | undefined,
) => {
if (!sendAccount.isOnline) {
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 wonder if this belongs to getQuote instead and then we could just throw the domain error instead maybe?

className="w-[100px]"
onClick={() => reverseTransaction({ transaction })}
onClick={() => {
if (!account.isOnline) {
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.

would it make more sense to still let it try and then handle network error? or that is problematic because network error only happens when background processing?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think that works, in this case it will throw the network error when wallet.getKeys is called from CashuTokenSwapService.create. I will try. If we do this, we just have to make sure the whatever we are creating that depends on the mint being online throws before anything is actually created in our db.

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 was thinking if we should maybe do something like that plus have some dedicated error and then we could handle it by showing the toast for it from the global handler instead of checking in bunch of different places

But maybe we can also keep like this for now. It's more work but leaves it more open to change later

Comment thread app/features/accounts/account-selector.tsx Outdated
Copy link
Copy Markdown
Contributor Author

@gudnuf gudnuf left a comment

Choose a reason for hiding this comment

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

I addressed all of the nits, but I need to think more on how to handle offline mints when the user attempts to send/receive and then I'll move the offline account toast if that's still needed.

I will probably do what you've suggested. The other idea I had is that the CashuMint class lets us pass a custom request, so we could throw the DomainError from there so that any cashu wallet method will throw the DomainError that the mint is offline, but I'm not sure if that's a good idea yet.

Comment thread app/features/shared/cashu.ts Outdated
Comment thread app/features/send/send-input.tsx Outdated
Comment thread app/features/settings/accounts/all-accounts.tsx Outdated
Comment thread app/features/accounts/account-hooks.ts Outdated
return filteredData;
},
[select?.currency, select?.type, user],
[select, user],
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.

we should do individual properties and instead of entire select. because if caller does this:

const accounts. = useAccounts({ isOnline: true })

the instance of select object will be different on every render even though the individual property value is the same and that will make this useCallback useless

<Badge>Default</Badge>
</div>
)}
{account.isDefault ||
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.

nit but I would format this as:

{(account.isDefault || !account.isOnline) && (...)}

@jbojcic1
Copy link
Copy Markdown
Collaborator

jbojcic1 commented Oct 20, 2025

I addressed all of the nits, but I need to think more on how to handle offline mints when the user attempts to send/receive and then I'll move the offline account toast if that's still needed.

I will probably do what you've suggested. The other idea I had is that the CashuMint class lets us pass a custom request, so we could throw the DomainError from there so that any cashu wallet method will throw the DomainError that the mint is offline, but I'm not sure if that's a good idea yet.

lets just leave it as is for now. approved but pls handle last comments and this before merge

@gudnuf
Copy link
Copy Markdown
Contributor Author

gudnuf commented Oct 20, 2025

closing to trigger ci

@gudnuf gudnuf closed this Oct 20, 2025
@gudnuf gudnuf reopened this Oct 20, 2025
@supabase
Copy link
Copy Markdown

supabase Bot commented Oct 20, 2025

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 merged commit c17b661 into master Oct 21, 2025
5 checks passed
@gudnuf gudnuf deleted the offline-mints branch October 21, 2025 03:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 High

Projects

None yet

Development

Successfully merging this pull request may close these issues.

handle failure to load mint

2 participants