Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support both new, old db schema on NFTs & collections #1008

Merged
merged 2 commits into from
Jul 8, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Features

- [#1008](https://github.com/alleslabs/celatone-frontend/pull/1008) Support both new, old DB schema for NFTs
- [#994](https://github.com/alleslabs/celatone-frontend/pull/994) Add Sequencer, Mesa tier and TierSwitcher component

### Improvements
Expand Down
12 changes: 6 additions & 6 deletions src/lib/query/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { gql } from "graphql-request";
export const getCollectionsQuery = gql`
query getCollectionsQuery(
$offset: Int!
$pageSize: Int!
$limit: Int!
$expression: collections_bool_exp!
) {
collections(
limit: $pageSize
limit: $limit
offset: $offset
where: $expression
order_by: { name: asc }
Expand Down Expand Up @@ -107,10 +107,10 @@ export const getCollectionActivitiesQuery = gql`
query getCollectionActivitiesQuery(
$expression: collection_transactions_bool_exp
$offset: Int!
$pageSize: Int!
$limit: Int!
) {
collection_transactions(
limit: $pageSize
limit: $limit
offset: $offset
where: $expression
order_by: [
Expand Down Expand Up @@ -144,10 +144,10 @@ export const getCollectionMutateEventsQuery = gql`
query getCollectionMutateEventsQuery(
$collectionAddress: String!
$offset: Int!
$pageSize: Int!
$limit: Int!
) {
collection_mutation_events(
limit: $pageSize
limit: $limit
offset: $offset
where: { collection_id: { _eq: $collectionAddress } }
order_by: { block_height: desc }
Expand Down
32 changes: 16 additions & 16 deletions src/lib/query/collectionOld.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { gql } from "graphql-request";

export const getCollectionsQueryOld = gql`
query getCollectionsQuery(
query getCollectionsQueryOld(
$offset: Int!
$pageSize: Int!
$limit: Int!
$expression: collections_bool_exp!
) {
collections(
limit: $pageSize
limit: $limit
offset: $offset
where: $expression
order_by: { name: asc }
Expand All @@ -31,7 +31,7 @@ export const getCollectionsQueryOld = gql`
`;

export const getCollectionByCollectionAddressQueryOld = gql`
query getCollectionByCollectionAddressQuery($vmAddress: String!) {
query getCollectionByCollectionAddressQueryOld($vmAddress: String!) {
collections(where: { vm_address: { vm_address: { _eq: $vmAddress } } }) {
name
uri
Expand All @@ -50,7 +50,7 @@ export const getCollectionByCollectionAddressQueryOld = gql`
`;

export const getCollectionTotalBurnedCountQueryOld = gql`
query getCollectionTotalBurnedCountQuery($vmAddress: String!) {
query getCollectionTotalBurnedCountQueryOld($vmAddress: String!) {
nfts_aggregate(
where: {
collectionByCollection: {
Expand All @@ -67,7 +67,7 @@ export const getCollectionTotalBurnedCountQueryOld = gql`
`;

export const getCollectionCreatorQueryOld = gql`
query getCollectionCreatorQuery($vmAddress: String!) {
query getCollectionCreatorQueryOld($vmAddress: String!) {
collections(where: { vm_address: { vm_address: { _eq: $vmAddress } } }) {
vmAddressByCreator {
vm_address
Expand All @@ -89,7 +89,7 @@ export const getCollectionCreatorQueryOld = gql`
`;

export const getCollectionActivitiesCountQueryOld = gql`
query getCollectionActivitiesCountQuery($vmAddress: String!) {
query getCollectionActivitiesCountQueryOld($vmAddress: String!) {
collection_transactions_aggregate(
where: { collection: { vm_address: { vm_address: { _eq: $vmAddress } } } }
) {
Expand All @@ -101,7 +101,7 @@ export const getCollectionActivitiesCountQueryOld = gql`
`;

export const getCollectionMutateEventsCountQueryOld = gql`
query getCollectionMutateEventsCountQuery($vmAddress: String!) {
query getCollectionMutateEventsCountQueryOld($vmAddress: String!) {
collection_mutation_events_aggregate(
where: { collection: { vm_address: { vm_address: { _eq: $vmAddress } } } }
) {
Expand All @@ -113,7 +113,7 @@ export const getCollectionMutateEventsCountQueryOld = gql`
`;

export const getCollectionUniqueHoldersCountQueryOld = gql`
query getCollectionUniqueHoldersCountQuery($vmAddress: String!) {
query getCollectionUniqueHoldersCountQueryOld($vmAddress: String!) {
nfts_aggregate(
where: {
collectionByCollection: {
Expand All @@ -130,13 +130,13 @@ export const getCollectionUniqueHoldersCountQueryOld = gql`
`;

export const getCollectionActivitiesQueryOld = gql`
query getCollectionActivitiesQuery(
query getCollectionActivitiesQueryOld(
$expression: collection_transactions_bool_exp
$offset: Int!
$pageSize: Int!
$limit: Int!
) {
collection_transactions(
limit: $pageSize
limit: $limit
offset: $offset
where: $expression
order_by: [
Expand Down Expand Up @@ -169,13 +169,13 @@ export const getCollectionActivitiesQueryOld = gql`
`;

export const getCollectionMutateEventsQueryOld = gql`
query getCollectionMutateEventsQuery(
query getCollectionMutateEventsQueryOld(
$collectionAddress: String!
$offset: Int!
$pageSize: Int!
$limit: Int!
) {
collection_mutation_events(
limit: $pageSize
limit: $limit
offset: $offset
where: {
collection: { vm_address: { vm_address: { _eq: $collectionAddress } } }
Expand All @@ -194,7 +194,7 @@ export const getCollectionMutateEventsQueryOld = gql`
`;

export const getCollectionsByAccountQueryOld = gql`
query getCollectionsByAccountQuery($accountAddress: String!) {
query getCollectionsByAccountQueryOld($accountAddress: String!) {
collections(
where: {
nfts: { vmAddressByOwner: { vm_address: { _eq: $accountAddress } } }
Expand Down
4 changes: 2 additions & 2 deletions src/lib/query/nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ export const getNftMutateEventsCountQuery = gql`

export const getNftsByAccountQuery = gql`
query getNftsByAccountQuery(
$pageSize: Int!
$limit: Int!
$offset: Int!
$expression: nfts_bool_exp!
) {
nfts(
limit: $pageSize
limit: $limit
offset: $offset
order_by: { token_id: asc }
where: $expression
Expand Down
24 changes: 14 additions & 10 deletions src/lib/query/nftOld.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { gql } from "graphql-request";

export const getNftQueryOld = gql`
query getNftQuery($collectionAddress: String!, $nftAddress: String!) {
query getNftQueryOld($collectionAddress: String!, $nftAddress: String!) {
nfts(
where: {
collectionByCollection: {
Expand All @@ -28,7 +28,11 @@ export const getNftQueryOld = gql`
`;

export const getNftsQueryOld = gql`
query getNftsQuery($limit: Int!, $offset: Int!, $expression: nfts_bool_exp!) {
query getNftsQueryOld(
$limit: Int!
$offset: Int!
$expression: nfts_bool_exp!
) {
nfts(
limit: $limit
offset: $offset
Expand Down Expand Up @@ -56,7 +60,7 @@ export const getNftsQueryOld = gql`
`;

export const getNftTransactionsCountQueryOld = gql`
query getNftTransactionsCountQuery($nftAddress: String!) {
query getNftTransactionsCountQueryOld($nftAddress: String!) {
nft_transactions_aggregate(
where: { nft: { vm_address: { vm_address: { _eq: $nftAddress } } } }
) {
Expand All @@ -68,7 +72,7 @@ export const getNftTransactionsCountQueryOld = gql`
`;

export const getNftTransactionsQueryOld = gql`
query getNftTransactionsQuery(
query getNftTransactionsQueryOld(
$limit: Int!
$offset: Int!
$nftAddress: String!
Expand Down Expand Up @@ -101,7 +105,7 @@ export const getNftTransactionsQueryOld = gql`
`;

export const getNftMutateEventsQueryOld = gql`
query getNftMutateEventsQuery(
query getNftMutateEventsQueryOld(
$limit: Int!
$offset: Int!
$nftAddress: String!
Expand All @@ -124,7 +128,7 @@ export const getNftMutateEventsQueryOld = gql`
`;

export const getNftMutateEventsCountQueryOld = gql`
query getNftMutateEventsCountQuery($nftAddress: String!) {
query getNftMutateEventsCountQueryOld($nftAddress: String!) {
nft_mutation_events_aggregate(
where: { nft: { vm_address: { vm_address: { _eq: $nftAddress } } } }
) {
Expand All @@ -136,13 +140,13 @@ export const getNftMutateEventsCountQueryOld = gql`
`;

export const getNftsByAccountQueryOld = gql`
query getNftsByAccountQuery(
$pageSize: Int!
query getNftsByAccountQueryOld(
$limit: Int!
$offset: Int!
$expression: nfts_bool_exp!
) {
nfts(
limit: $pageSize
limit: $limit
offset: $offset
order_by: { token_id: asc }
where: $expression
Expand Down Expand Up @@ -172,7 +176,7 @@ export const getNftsByAccountQueryOld = gql`
`;

export const getNftsCountByAccountQueryOld = gql`
query getNftsCountByAccountQuery($accountAddress: String!) {
query getNftsCountByAccountQueryOld($accountAddress: String!) {
nfts_aggregate(
where: {
vmAddressByOwner: { vm_address: { _eq: $accountAddress } }
Expand Down
106 changes: 49 additions & 57 deletions src/lib/services/expression/nftExpression.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import { useMemo } from "react";

import type { HexAddr, HexAddr32 } from "lib/types";
import { isHexModuleAddress, isTxHash } from "lib/utils";

export const useCollectionsExpression = (search = "") =>
useMemo(() => {
if (search.trim().length === 0) return {};
export const getCollectionsExpression = (search = "") => {
if (search.trim().length === 0) return {};

return {
_or: [
{ name: { _iregex: search } },
{ id: { _eq: search.toLowerCase() } },
],
};
}, [search]);
return {
_or: [{ name: { _iregex: search } }, { id: { _eq: search.toLowerCase() } }],
};
};

export const useCollectionActivitiesExpression = (
export const getCollectionActivitiesExpression = (
collectionAddress: HexAddr32,
search = ""
) => {
Expand All @@ -35,56 +29,54 @@ export const useCollectionActivitiesExpression = (

const searchOption = isHash ? txHashSearch : tokenIdSearch;

return useMemo(
() => ({
collection_id: { _eq: collectionAddress },
...(search ? { _and: searchOption } : {}),
}),
[collectionAddress, search, searchOption]
);
return {
collection_id: { _eq: collectionAddress },
...(search ? { _and: searchOption } : {}),
};
};

export const useNftsExpression = (collectionAddress: HexAddr32, search = "") =>
useMemo(() => {
const orExpression = {
_or: [
{ token_id: { _iregex: search } },
...(isHexModuleAddress(search)
? [{ id: { _eq: search.toLowerCase() } }]
: []),
],
};
export const getNftsExpression = (
collectionAddress: HexAddr32,
search = ""
) => {
const orExpression = {
_or: [
{ token_id: { _iregex: search } },
...(isHexModuleAddress(search)
? [{ id: { _eq: search.toLowerCase() } }]
: []),
],
};

return {
collection: { _eq: collectionAddress },
is_burned: { _eq: false },
...(search.trim().length > 0 ? orExpression : {}),
};
}, [collectionAddress, search]);
return {
collection: { _eq: collectionAddress },
is_burned: { _eq: false },
...(search.trim().length > 0 ? orExpression : {}),
};
};

export const useNftsByAccountExpression = (
export const getNftsByAccountExpression = (
accountAddress: HexAddr,
collectionAddress?: HexAddr32,
search = ""
) =>
useMemo(() => {
const orExpression = {
_or: [
{ token_id: { _iregex: search } },
...(isHexModuleAddress(search)
? [{ id: { _eq: search.toLowerCase() } }]
: []),
],
};
) => {
const orExpression = {
_or: [
{ token_id: { _iregex: search } },
...(isHexModuleAddress(search)
? [{ id: { _eq: search.toLowerCase() } }]
: []),
],
};

const collectionExpression = {
collection: { _eq: collectionAddress?.toLowerCase() },
};
const collectionExpression = {
collection: { _eq: collectionAddress?.toLowerCase() },
};

return {
owner: { _eq: accountAddress },
is_burned: { _eq: false },
...(collectionAddress ? collectionExpression : {}),
...(search.trim().length > 0 ? orExpression : {}),
};
}, [accountAddress, collectionAddress, search]);
return {
owner: { _eq: accountAddress },
is_burned: { _eq: false },
...(collectionAddress ? collectionExpression : {}),
...(search.trim().length > 0 ? orExpression : {}),
};
};
Loading
Loading