Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions app/features/accounts/account-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,20 @@ export function useAccounts<T extends AccountType = AccountType>(select?: {
(data: Account[]) => {
const extendedData = AccountService.getExtendedAccounts(user, data);

if (!currency && !type && isOnline === undefined) {
return extendedData as ExtendedAccount<T>[];
if (
!currency &&
!type &&
isOnline === undefined &&
!excludeClosedLoopAccounts &&
!onlyIncludeClosedLoopAccounts
) {
return extendedData
.slice()
.sort(
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I needed to add this sort because I noticed that the order of accounts returned by upsert user db function was different then the order returned by making a get call to get all accounts which was making gift-cards page show one order on initial render and different after rerender

(a, b) =>
new Date(a.createdAt).getTime() -
new Date(b.createdAt).getTime(),
) as ExtendedAccount<T>[];
}

const filteredData = extendedData.filter(
Expand All @@ -193,7 +205,12 @@ export function useAccounts<T extends AccountType = AccountType>(select?: {
},
);

return filteredData;
return filteredData
.slice()
.sort(
(a, b) =>
new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime(),
);
},
[
currency,
Expand Down
4 changes: 2 additions & 2 deletions app/features/accounts/account-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class AccountRepository {
*/
async get(id: string, options?: Options): Promise<Account> {
// Currently we limit the number of proofs returned to 6000
// We will need to handle that somehow later (e.g. require use to swap when the limit is reaching)
// We will need to handle that somehow later (e.g. require user to swap when the limit is reaching)
const query = this.db
.from('accounts')
.select('*, cashu_proofs(*)')
Expand All @@ -82,7 +82,7 @@ export class AccountRepository {
*/
async getAll(userId: string, options?: Options): Promise<Account[]> {
// Currently we limit the number of proofs returned to 6000
// We will need to handle that somehow later (e.g. require use to swap when the limit is reaching)
// We will need to handle that somehow later (e.g. require user to swap when the limit is reaching)
const query = this.db
.from('accounts')
.select('*, cashu_proofs(*)')
Expand Down
25 changes: 7 additions & 18 deletions app/features/gift-cards/add-gift-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,31 @@ import {
import { Button } from '~/components/ui/button';
import { WalletCard, WalletCardBackground } from '~/components/wallet-card';
import { useAddCashuAccount } from '~/features/accounts/account-hooks';
import { NotFoundError } from '~/features/shared/error';
import { useToast } from '~/hooks/use-toast';
import type { Currency } from '~/lib/money/types';
import { LinkWithViewTransition } from '~/lib/transitions';
import { DISCOVER_MINTS } from './use-discover-cards';
import type { GiftCardInfo } from './use-discover-cards';

type AddGiftCardProps = {
mintUrl: string;
currency: Currency;
giftCard: GiftCardInfo;
};

/**
* Add Gift Card component - displays the full size gift card image
* and an "Add Card" button to add the discover card to the user's wallet.
*/
export function AddGiftCard({ mintUrl, currency }: AddGiftCardProps) {
export function AddGiftCard({ giftCard }: AddGiftCardProps) {
const [isAdding, setIsAdding] = useState(false);
const addAccount = useAddCashuAccount();
const navigate = useNavigate();
const { toast } = useToast();

const mint = DISCOVER_MINTS.find(
(m) => m.url === mintUrl && m.currency === currency,
);

if (!mint) {
throw new NotFoundError('Card not found');
}

const handleAddCard = async () => {
setIsAdding(true);
try {
await addAccount({
name: mint.name,
currency: mint.currency,
mintUrl: mint.url,
name: giftCard.name,
currency: giftCard.currency,
mintUrl: giftCard.url,
type: 'cashu',
});
toast({
Expand Down Expand Up @@ -85,7 +74,7 @@ export function AddGiftCard({ mintUrl, currency }: AddGiftCardProps) {
className="absolute inset-0 mx-auto flex max-w-sm items-center justify-center px-4"
>
<WalletCard className="w-full max-w-none">
<WalletCardBackground src={mint.image} alt={mint.name} />
<WalletCardBackground src={giftCard.image} alt={giftCard.name} />
</WalletCard>
</LinkWithViewTransition>
</PageContent>
Expand Down
211 changes: 0 additions & 211 deletions app/features/gift-cards/card-stack-animation.ts

This file was deleted.

6 changes: 6 additions & 0 deletions app/features/gift-cards/card-stack-constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { CARD_ASPECT_RATIO, CARD_SIZES } from '~/components/wallet-card';

export const VERTICAL_CARD_OFFSET_IN_STACK = 52;

export const CARD_WIDTH = CARD_SIZES.default.width;
export const CARD_HEIGHT = Math.round(CARD_WIDTH / CARD_ASPECT_RATIO);
22 changes: 0 additions & 22 deletions app/features/gift-cards/card-stack.constants.ts

This file was deleted.

Loading