Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sstraatemans committed Oct 25, 2024
1 parent 1e547ef commit 4b0bfae
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const mockGetTokens = vi.mocked(getTokens);
vi.mock('@/components/Token', () => ({
Token: ({ tokenId }: { tokenId: string }) => <div>{tokenId}</div>,
}));
vi.mock('@/utils/fetchOnSaleTokens', () => ({
fetchOnSaleTokens: console.log,
}));

const dummyAccountContext = {
account: null,
Expand Down
25 changes: 4 additions & 21 deletions packages/apps/marmalade-marketplace/src/pages/mytokens/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { ListingHeader } from '@/components/ListingHeader';
import { Token } from '@/components/Token';
import { getTokens, NonFungibleTokenBalance } from '@/graphql/queries/client';
import { useAccount } from '@/hooks/account';
import { database } from '@/utils/firebase';
import { fetchOnSaleTokens } from '@/utils/fetchOnSaleTokens';

import { ChainId } from '@kadena/client';
import {
Badge,
Expand All @@ -12,7 +13,7 @@ import {
ProgressCircle,
Stack,
} from '@kadena/kode-ui';
import { collection, getDocs, query, where } from 'firebase/firestore';

import { useEffect, useState } from 'react';

const MyTokens = () => {
Expand All @@ -23,24 +24,6 @@ const MyTokens = () => {
const [isLoading, setIsLoading] = useState<boolean>(false);
const { account } = useAccount();

const fetchOnSaleTokens = async (accountName?: string) => {
if (accountName) {
//const querySnapshot = await getDocs(query(collection(database, 'sales')));
const salesRef = collection(database, 'sales');
const q = await query(
salesRef,
where('seller.account', '==', account?.accountName),
);
const querySnapshot = await getDocs(q);

const docs: NonFungibleTokenBalance[] = [];
querySnapshot.forEach((doc) => {
docs.push(doc.data() as NonFungibleTokenBalance);
});
setOnSaleTokens(docs);
}
};

const fetchTokens = async (accountName?: string) => {
if (accountName) {
const tokens = await getTokens(accountName);
Expand All @@ -52,7 +35,7 @@ const MyTokens = () => {
useEffect(() => {
setIsLoading(true);
fetchTokens(account?.accountName);
fetchOnSaleTokens(account?.accountName);
fetchOnSaleTokens(account?.accountName!, setOnSaleTokens);
}, [account?.accountName]);

return (
Expand Down
22 changes: 22 additions & 0 deletions packages/apps/marmalade-marketplace/src/utils/fetchOnSaleTokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { NonFungibleTokenBalance } from '@/graphql/queries/client';
import { database } from '@/utils/firebase';
import { collection, getDocs, query, where } from 'firebase/firestore';
import { Dispatch, SetStateAction } from 'react';

export const fetchOnSaleTokens = async (
accountName: string,
cb: Dispatch<SetStateAction<NonFungibleTokenBalance[]>>,
) => {
if (accountName) {
//const querySnapshot = await getDocs(query(collection(database, 'sales')));
const salesRef = collection(database, 'sales');
const q = await query(salesRef, where('seller.account', '==', accountName));
const querySnapshot = await getDocs(q);

const docs: NonFungibleTokenBalance[] = [];
querySnapshot.forEach((doc) => {
docs.push(doc.data() as NonFungibleTokenBalance);
});
cb(docs);
}
};

0 comments on commit 4b0bfae

Please sign in to comment.