diff --git a/app/features/accounts/account-hooks.ts b/app/features/accounts/account-hooks.ts index 4f04d9101..74af28ab9 100644 --- a/app/features/accounts/account-hooks.ts +++ b/app/features/accounts/account-hooks.ts @@ -251,11 +251,14 @@ export function useAccounts(select?: { currency?: Currency; type?: T; isOnline?: boolean; + excludeStarAccounts?: boolean; + starAccountsOnly?: boolean; }): UseSuspenseQueryResult[]> { const user = useUser(); const accountRepository = useAccountRepository(); - const { currency, type, isOnline } = select ?? {}; + const { currency, type, isOnline, excludeStarAccounts, starAccountsOnly } = + select ?? {}; return useSuspenseQuery({ ...accountsQueryOptions({ userId: user.id, accountRepository }), @@ -280,13 +283,19 @@ export function useAccounts(select?: { if (isOnline !== undefined && account.isOnline !== isOnline) { return false; } + if (excludeStarAccounts && account.isStarAccount) { + return false; + } + if (starAccountsOnly && !account.isStarAccount) { + return false; + } return true; }, ); return filteredData; }, - [currency, type, isOnline, user], + [currency, type, isOnline, excludeStarAccounts, starAccountsOnly, user], ), }); } @@ -409,15 +418,18 @@ export function useAddCashuAccount() { return mutateAsync; } +/** + * @returns the total balance of all accounts for the given currency excluding Star accounts. + */ export function useBalance(currency: Currency) { - const { data: accounts } = useAccounts({ currency }); - const balance = accounts.reduce( - (acc, account) => { - const accountBalance = getAccountBalance(account); - return acc.add(accountBalance); - }, - new Money({ amount: 0, currency }), - ); + const { data: accounts } = useAccounts({ + currency, + excludeStarAccounts: true, + }); + const balance = accounts.reduce((acc, account) => { + const accountBalance = getAccountBalance(account); + return acc.add(accountBalance); + }, Money.zero(currency)); return balance; } diff --git a/app/features/accounts/account-icons.tsx b/app/features/accounts/account-icons.tsx index afd0c86f8..d4882df8b 100644 --- a/app/features/accounts/account-icons.tsx +++ b/app/features/accounts/account-icons.tsx @@ -1,15 +1,17 @@ -import { LandmarkIcon, Zap } from 'lucide-react'; +import { LandmarkIcon, StarIcon, Zap } from 'lucide-react'; import type { ReactNode } from 'react'; import type { AccountType } from './account'; const CashuIcon = () => ; const NWCIcon = () => ; +const StarsIcon = () => ; -const iconsByAccountType: Record = { +const iconsByAccountType: Record = { cashu: , nwc: , + star: , }; -export function AccountTypeIcon({ type }: { type: AccountType }) { +export function AccountTypeIcon({ type }: { type: AccountType | 'star' }) { return iconsByAccountType[type]; } diff --git a/app/features/accounts/account-repository.ts b/app/features/accounts/account-repository.ts index 7c948d420..f066ed7bb 100644 --- a/app/features/accounts/account-repository.ts +++ b/app/features/accounts/account-repository.ts @@ -167,7 +167,7 @@ export class AccountRepository { proofs: string; }; - const { wallet, isOnline } = await this.getPreloadedWallet( + const { wallet, isOnline, isStarAccount } = await this.getPreloadedWallet( details.mint_url, data.currency, ); @@ -181,6 +181,7 @@ export class AccountRepository { keysetCounters: details.keyset_counters, proofs: await this.encryption.decrypt(details.proofs), wallet, + isStarAccount, } as T; } @@ -231,7 +232,7 @@ export class AccountRepository { unit: getCashuUnit(currency), bip39seed: seed ?? undefined, }); - return { wallet, isOnline: false }; + return { wallet, isOnline: false, isStarAccount: undefined }; } throw error; } @@ -266,7 +267,11 @@ export class AccountRepository { // The constructor does not set the keysetId, so we need to set it manually wallet.keysetId = activeKeyset.id; - return { wallet, isOnline: true }; + return { + wallet, + isOnline: true, + isStarAccount: mintInfo.internalMeltsOnly, + }; } } diff --git a/app/features/accounts/account-selector.tsx b/app/features/accounts/account-selector.tsx index 46727a142..702441969 100644 --- a/app/features/accounts/account-selector.tsx +++ b/app/features/accounts/account-selector.tsx @@ -45,7 +45,7 @@ function AccountItem({ account }: { account: AccountSelectorOption }) { return (
- +
{account.name}
diff --git a/app/features/accounts/account.ts b/app/features/accounts/account.ts index 7b833b55f..02ccfee70 100644 --- a/app/features/accounts/account.ts +++ b/app/features/accounts/account.ts @@ -9,6 +9,7 @@ export type Account = { name: string; type: AccountType; isOnline: boolean; + isStarAccount?: boolean; currency: Currency; createdAt: string; /** diff --git a/app/features/receive/receive-cashu-token-service.ts b/app/features/receive/receive-cashu-token-service.ts index 098866204..beb2f347c 100644 --- a/app/features/receive/receive-cashu-token-service.ts +++ b/app/features/receive/receive-cashu-token-service.ts @@ -199,7 +199,7 @@ export class ReceiveCashuTokenService { sourceAccount: CashuAccountWithTokenFlags, otherAccounts: CashuAccountWithTokenFlags[], ): CashuAccountWithTokenFlags[] { - if (sourceAccount.isTestMint) { + if (sourceAccount.isTestMint || sourceAccount.isStarAccount) { // Tokens sourced from test mint can only be claimed to the same mint return sourceAccount.canReceive ? [sourceAccount] : []; } diff --git a/app/features/receive/receive-cashu-token.tsx b/app/features/receive/receive-cashu-token.tsx index 571116577..28efb757f 100644 --- a/app/features/receive/receive-cashu-token.tsx +++ b/app/features/receive/receive-cashu-token.tsx @@ -208,7 +208,9 @@ export default function ReceiveToken({
diff --git a/app/features/settings/accounts/all-accounts.tsx b/app/features/settings/accounts/all-accounts.tsx index d2cf154b7..aa33b6ee4 100644 --- a/app/features/settings/accounts/all-accounts.tsx +++ b/app/features/settings/accounts/all-accounts.tsx @@ -14,7 +14,10 @@ import type { Currency } from '~/lib/money'; import { LinkWithViewTransition } from '~/lib/transitions'; function CurrencyAccounts({ currency }: { currency: Currency }) { - const { data: accounts } = useAccounts({ currency }); + const { data: accounts } = useAccounts({ + currency, + excludeStarAccounts: true, + }); return (
diff --git a/app/features/settings/settings.tsx b/app/features/settings/settings.tsx index a0d4f61d9..f45232be1 100644 --- a/app/features/settings/settings.tsx +++ b/app/features/settings/settings.tsx @@ -111,7 +111,9 @@ export default function Settings() { - + {defaultAccount.name}