Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Updates to Preview Branch (add-account-purpose) ↗︎
Tasks are run on every commit but only new migration files are pushed.
View logs for this Workflow Run ↗︎. |
|
@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 |
| 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? |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
I don't think we need to specify cashu here now that we have purpose set, right?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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' }
There was a problem hiding this comment.
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
| 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? |
There was a problem hiding this comment.
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
be1d220 to
94f4b47
Compare
94f4b47 to
f9d089c
Compare
| ): UseSuspenseQueryResult<ExtendedAccount<T>[]>; | ||
| export function useAccounts<T extends AccountType = AccountType>( | ||
| select?: UseAccountsSelect<T>, | ||
| ): UseSuspenseQueryResult<ExtendedAccount<T>[]> { |
There was a problem hiding this comment.
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' }
There was a problem hiding this comment.
Oh yea nice, that was left over from a previous attempt before doing these overloads. Fixed
jbojcic1
left a comment
There was a problem hiding this comment.
Approved, pls just check #766 (comment)
f9d089c to
888e577
Compare
This PR is to solve this comment: #758 (comment)
purposecolumn to the account's table.transactionalfor now, and cashu account aretransactional | gift-card.