Skip to content

Add account purpose for #758#766

Merged
gudnuf merged 1 commit intogift-cards-2from
add-account-purpose
Jan 27, 2026
Merged

Add account purpose for #758#766
gudnuf merged 1 commit intogift-cards-2from
add-account-purpose

Conversation

@gudnuf
Copy link
Contributor

@gudnuf gudnuf commented Jan 12, 2026

This PR is to solve this comment: #758 (comment)

  • Add a new purpose column to the account's table.
  • Handles accounts based on their purpose
  • Creates accounts with their purpose. Spark accounts are always transactional for now, and cashu account are transactional | gift-card.
  • The cashu account purpose is set based on whether the mint is closed loop or not.

@gudnuf gudnuf requested a review from jbojcic1 January 12, 2026 21:50
@vercel
Copy link

vercel bot commented Jan 12, 2026

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

Project Deployment Review Updated (UTC)
agicash Ready Ready Preview, Comment Jan 27, 2026 4:22pm

Request Review

@gudnuf gudnuf self-assigned this Jan 12, 2026
@supabase
Copy link

supabase bot commented Jan 12, 2026

Updates to Preview Branch (add-account-purpose) ↗︎

Deployments Status Updated
Database Tue, 27 Jan 2026 16:22:21 UTC
Services Tue, 27 Jan 2026 16:22:21 UTC
APIs Tue, 27 Jan 2026 16:22:21 UTC

Tasks are run on every commit but only new migration files are pushed.
Close and reopen this PR if you want to apply changes from existing seed or migration files.

Tasks Status Updated
Configurations Tue, 27 Jan 2026 16:22:22 UTC
Migrations Tue, 27 Jan 2026 16:22:22 UTC
Seeding Tue, 27 Jan 2026 16:22:22 UTC
Edge Functions Tue, 27 Jan 2026 16:22:22 UTC

View logs for this Workflow Run ↗︎.
Learn more about Supabase for Git ↗︎.

@gudnuf
Copy link
Contributor Author

gudnuf commented Jan 12, 2026

@jbojcic1 the first commit here adds the account purpose feature and the second two commits are other feedback that Bob wanted me to do. They utilize the account purpose so I put them here so you could see the usage too

@gudnuf gudnuf mentioned this pull request Jan 13, 2026
mintInfo: ExtendedMintInfo | null | undefined,
): 'gift-card' | 'transactional' => {
// TODO: This should check this.mintInfo?.agicash?.closed_loop once Agicash mints change to that
// TODO: Should the mint explicitly signal the purpose?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We will have other types of mints like loyalty points, subscription credits, reward points / cash back, etc.

I keep wondering what the best way to handle this on the mint side is and now I'm wondering if it would be better to specify the purpose in the agicash mint info rather than the closed_loop flag that I added to PROTOCOL_EXTENSIONS

Copy link
Collaborator

Choose a reason for hiding this comment

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

will those all also be closed_loop or you see more settings added to the mint? if all closed loop, probably better to keep as is

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think there's many possibilities. Most will be closed loop, but the meaning of closed loop may change. For example, we may have mints that are only allowed to pay invoices that they themselves generated or we might have mints that have multiple valid destinations in the loop. And then the behavior of the mint could be different based on the type. Gift card mints just issue ecash that can only be spent at a specific location, but cash back mints will work differently (not sure how yet).

We can always change later if needed

Copy link
Collaborator

@jbojcic1 jbojcic1 Jan 27, 2026

Choose a reason for hiding this comment

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

yeah lets keep as is and change later. it's hard to predict something like that. i do feel like purpose should not be moved to mint side for now. seems like a concept that is higher level than the mint atm

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need to specify cashu here now that we have purpose set, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mm thats for the generic typing. If we remove that the the accounts will just be Account not CashuAccount. We could change the useAccounts hook to type gift card accounts as CashuAccount, wdyt?

Copy link
Contributor Author

@gudnuf gudnuf Jan 27, 2026

Choose a reason for hiding this comment

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

I pushed a change in this commit f725a99 that updates the useAccounts hook to make it so that if you specify gift-card the accounts returned will be cashu. Also the way I did it as a union makes it so that if you try to set type to 'spark' and purpose to 'gift-card' ts will give an error.

I pushed so you could see and maybe you have a suggestion, but I'm not sure if this is better than just specifying the type along with the purpose.

Pros/cons:

New overload approach

Overload is nice because it encodes "gift cards are always cashu" in the type system and makes it impossible to accidentally write { type: 'spark', purpose: 'gift-card' }, but it makes the makes the hook signature more complex.

Manual specify type

The original way I had it is more obvious what type you're getting and keeps the hook simpler, but potentially redundant and doesn't prevent you from writing { type: 'spark', purpose: 'gift-card' }

Copy link
Collaborator

Choose a reason for hiding this comment

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

Other pro of manual type is that if we can later have gift cards for different types we don't need to change anything but we are probably far from there so I'd just keep what you did here.

Alterantively we could keep both type and purpose but have dedicated hook called useGiftCardAccounts which wraps it so we don't need to repeat it all the time

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm keeping it

mintInfo: ExtendedMintInfo | null | undefined,
): 'gift-card' | 'transactional' => {
// TODO: This should check this.mintInfo?.agicash?.closed_loop once Agicash mints change to that
// TODO: Should the mint explicitly signal the purpose?
Copy link
Collaborator

Choose a reason for hiding this comment

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

will those all also be closed_loop or you see more settings added to the mint? if all closed loop, probably better to keep as is

): UseSuspenseQueryResult<ExtendedAccount<T>[]>;
export function useAccounts<T extends AccountType = AccountType>(
select?: UseAccountsSelect<T>,
): UseSuspenseQueryResult<ExtendedAccount<T>[]> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

if we decide to keep this approach I think it would be less confusing to do it like this:

export function useAccounts(
  select: UseAccountsSelect<'cashu', 'gift-card'>,
): UseSuspenseQueryResult<ExtendedAccount<'cashu'>[]>;
export function useAccounts<
  T extends AccountType = AccountType,
  P extends AccountPurpose = AccountPurpose,
>(
  select?: UseAccountsSelect<T, P>,
): UseSuspenseQueryResult<ExtendedAccount<T>[]>;
export function useAccounts<
  T extends AccountType = AccountType,
  P extends AccountPurpose = AccountPurpose,
>(
  select?: UseAccountsSelect<T, P>,
): UseSuspenseQueryResult<ExtendedAccount<T>[]> {
...

this way you actually utilise the second generic param instead of having it but using & { purpose: 'gift-card' }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yea nice, that was left over from a previous attempt before doing these overloads. Fixed

Copy link
Collaborator

@jbojcic1 jbojcic1 left a comment

Choose a reason for hiding this comment

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

Approved, pls just check #766 (comment)

@gudnuf gudnuf force-pushed the add-account-purpose branch from f9d089c to 888e577 Compare January 27, 2026 16:21
@gudnuf gudnuf merged commit ae37b7b into gift-cards-2 Jan 27, 2026
5 checks passed
@gudnuf gudnuf deleted the add-account-purpose branch January 27, 2026 16:42
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.

2 participants

Comments