Skip to content

Commit

Permalink
use useCollectionBalanceDetails instead of deprecated hook, fix typ…
Browse files Browse the repository at this point in the history
…ing for params
  • Loading branch information
mithatakbulut committed Feb 26, 2025
1 parent aafe54d commit 3c0bffa
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 27 deletions.
7 changes: 4 additions & 3 deletions playgrounds/react-vite/src/tabs/Collectables.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Text } from '@0xsequence/design-system2';
import { useCollection } from '@0xsequence/marketplace-sdk/react';
import type { ContractInfo } from '@0xsequence/metadata';
import { useNavigate } from 'react-router';
import type { Collection, OrderbookKind } from '../../../../packages/sdk/src';
import type { OrderbookKind } from '../../../../packages/sdk/src';
import { useMarketplace } from '../lib/MarketplaceContext';
import { ROUTES } from '../lib/routes';
import { InfiniteScrollView } from './components/InfiniteScrollView';
Expand Down Expand Up @@ -41,7 +42,7 @@ export function Collectibles() {
collectionAddress={collectionAddress}
chainId={chainId}
orderbookKind={orderbookKind as OrderbookKind}
collection={collection as unknown as Collection}
collection={collection as unknown as ContractInfo}
collectionLoading={collectionLoading}
onCollectibleClick={handleCollectibleClick}
/>
Expand All @@ -50,7 +51,7 @@ export function Collectibles() {
collectionAddress={collectionAddress}
chainId={chainId}
orderbookKind={orderbookKind as OrderbookKind}
collection={collection as unknown as Collection}
collection={collection as unknown as ContractInfo}
collectionLoading={collectionLoading}
onCollectibleClick={handleCollectibleClick}
/>
Expand Down
30 changes: 15 additions & 15 deletions playgrounds/react-vite/src/tabs/components/InfiniteScrollView.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import { Text, useToast } from '@0xsequence/design-system2';
import { useCollectionBalance } from '@0xsequence/kit';
import {
type Collection,
type ContractType,
OrderSide,
type OrderbookKind,
} from '@0xsequence/marketplace-sdk';
import { OrderSide, type OrderbookKind } from '@0xsequence/marketplace-sdk';
import {
CollectibleCard,
useCollectionBalanceDetails,
useListCollectibles,
} from '@0xsequence/marketplace-sdk/react';
import type { ContractInfo, ContractType } from '@0xsequence/metadata';
import React from 'react';
import { useAccount } from 'wagmi';
import { CollectibleCardAction } from '../../../../../packages/sdk/src/react/ui/components/_internals/action-button/types';

interface InfiniteScrollViewProps {
collectionAddress: `0x${string}`;
chainId: string;
orderbookKind: OrderbookKind;
collection: Collection;
collection: ContractInfo;
collectionLoading: boolean;
onCollectibleClick: (tokenId: string) => void;
}
Expand All @@ -45,11 +40,16 @@ export function InfiniteScrollView({
});

const { data: collectionBalance, isLoading: collectionBalanceLoading } =
useCollectionBalance({
contractAddress: collectionAddress,
useCollectionBalanceDetails({
chainId: Number(chainId),
accountAddress: accountAddress || '',
includeMetadata: false,
filter: {
accountAddresses: accountAddress ? [accountAddress] : [],
omitNativeBalances: true,
contractWhitelist: [collectionAddress],
},
query: {
enabled: !!accountAddress,
},
});

const toast = useToast();
Expand Down Expand Up @@ -87,12 +87,12 @@ export function InfiniteScrollView({
chainId={chainId}
collectionAddress={collectionAddress}
orderbookKind={orderbookKind}
collectionType={collection?.contractType as ContractType}
collectionType={collection?.type as ContractType}
lowestListing={collectibleLowestListing}
onCollectibleClick={onCollectibleClick}
onOfferClick={({ order }) => console.log(order)}
balance={
collectionBalance?.find(
collectionBalance?.balances.find(
(balance) =>
balance.tokenID ===
collectibleLowestListing.metadata.tokenId,
Expand Down
23 changes: 14 additions & 9 deletions playgrounds/react-vite/src/tabs/components/PaginatedView.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Button, Text, useToast } from '@0xsequence/design-system2';
import { useCollectionBalance } from '@0xsequence/kit';
import {
type Collection,
type ContractType,
OrderSide,
type OrderbookKind,
} from '@0xsequence/marketplace-sdk';
import {
CollectibleCard,
useCollectionBalanceDetails,
useListCollectiblesPaginated,
} from '@0xsequence/marketplace-sdk/react';
import type { ContractInfo } from '@0xsequence/metadata';
import { useState } from 'react';
import type { Address } from 'viem';
import { useAccount } from 'wagmi';
Expand All @@ -19,7 +19,7 @@ interface PaginatedViewProps {
collectionAddress: Address;
chainId: string;
orderbookKind: OrderbookKind;
collection: Collection;
collection: ContractInfo;
collectionLoading: boolean;
onCollectibleClick: (tokenId: string) => void;
}
Expand Down Expand Up @@ -55,11 +55,16 @@ export function PaginatedView({
});

const { data: collectionBalance, isLoading: collectionBalanceLoading } =
useCollectionBalance({
contractAddress: collectionAddress,
useCollectionBalanceDetails({
chainId: Number(chainId),
accountAddress: accountAddress || '',
includeMetadata: false,
filter: {
accountAddresses: accountAddress ? [accountAddress] : [],
contractWhitelist: [collectionAddress],
omitNativeBalances: true,
},
query: {
enabled: !!accountAddress,
},
});

const toast = useToast();
Expand Down Expand Up @@ -111,12 +116,12 @@ export function PaginatedView({
chainId={chainId}
collectionAddress={collectionAddress}
orderbookKind={orderbookKind}
collectionType={collection?.contractType as ContractType}
collectionType={collection?.type as ContractType}
lowestListing={collectibleLowestListing}
onCollectibleClick={onCollectibleClick}
onOfferClick={({ order }) => console.log(order)}
balance={
collectionBalance?.find(
collectionBalance?.balances.find(
(balance) =>
balance.tokenID ===
collectibleLowestListing.metadata.tokenId,
Expand Down

0 comments on commit 3c0bffa

Please sign in to comment.