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

Implement nftOwnersByStore #520

Open
wants to merge 5 commits into
base: beta
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"parserOptions": {
"project": "./tsconfig.lint.json",
"ecmaVersion": 2018,
"sourceType": "module"
"sourceType": "module",
"tsconfigRootDir": "./"
},
"plugins": [
"@typescript-eslint",
Expand Down
4 changes: 2 additions & 2 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useNx": true,
"version": "0.6.0-beta-prerelease.0",
"version": "0.6.0-beta-prerelease.2",
"packages": [
"packages/*"
]
}
}
9,799 changes: 3,692 additions & 6,107 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,10 @@
"eslint-plugin-simple-import-sort": "^5.0.3",
"fetch-mock": "^9.11.0",
"graphql": "^16.6.0",
"isomorphic-fetch": "^3.0.0",
"jest": "^29.1.1",
"jest-environment-jsdom": "^29.1.2",
"lerna": "^7.0.0",
"lerna": "^8.0.0",
"lerna-jest": "^0.5.4",
"serve": "^14.0.1",
"superagent": "^8.0.3",
"ts-jest": "^29.0.3",
"typescript": "^4.8.4",
"@near-wallet-selector/wallet-utils": "^8.9.7"
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mintbase-js/auth",
"version": "0.6.0-beta-prerelease.0",
"version": "0.6.0-beta-prerelease.2",
"description": "Wallet and auth functions for Mintbase JS SDK",
"main": "lib/index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions packages/data/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mintbase-js/data",
"version": "0.6.0-beta-prerelease.0",
"version": "0.6.0-beta-prerelease.2",
"description": "Query wrappers for Mintbase JS SDK",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand All @@ -21,7 +21,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"@mintbase-js/sdk": "^0.5.2-beta.0",
"@mintbase-js/sdk": "^0.6.0-beta-prerelease.2",
"cross-fetch": "^4.0.0",
"graphql-request": "^5.2.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/data/src/api/dynamicNftMetadata/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Example usage:
import { dynamicNftMetadata } from '@mintbase-js/data'

const props = {
contractAddress: 'dynamic.mintbase2.near',
contractAddress: 'dynamic.mintbasev2.near',
internalMetadataId: 0,
isActive: true,
network: "mainnet",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { mbjs } from '@mintbase-js/sdk';

export const dynamicNftMetadataMockActive = {
nft_metadata: [
{
metadataId: 'dynamic.mintbase2.near:deadbeef2',
metadataId: `dynamic.${mbjs.keys.mbContractV2}:deadbeef2`,
internalMetadataId: 0,
contractAddress: 'dynamic.mintbase2.near',
contractAddress: `dynamic.${mbjs.keys.mbContractV2}`,
reference: 'https://arweave.net/reference2',
referenceBlob: {
media: 'https://arweave.net/media2',
Expand All @@ -25,8 +27,8 @@ export const dynamicNftMetadataMockActive = {
export const dynamicNftMetadataMockInactive = {
nft_metadata: [
{
metadataId: 'dynamic.mintbase2.near:deadbeef0',
contractAddress: 'dynamic.mintbase2.near',
metadataId: `dynamic.${mbjs.keys.mbContractV2}:deadbeef0`,
contractAddress: `dynamic.${mbjs.keys.mbContractV2}`,
internalMetadataId: 0,
reference: 'https://arweave.net/reference0',
referenceBlob: {
Expand All @@ -36,8 +38,8 @@ export const dynamicNftMetadataMockInactive = {
isActive: false,
},
{
metadataId: 'dynamic.mintbase2.near:deadbeef1',
contractAddress: 'dynamic.mintbase2.near',
metadataId: `dynamic.${mbjs.keys.mbContractV2}:deadbeef1`,
contractAddress: `dynamic.${mbjs.keys.mbContractV2}`,
internalMetadataId: 0,
reference: 'https://arweave.net/reference1',
referenceBlob: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { DynamicNftMetadataResult } from './dynamicNftMetadata.types';

import { GraphQLClient } from 'graphql-request';
import { dynamicNftMetadataMockInactive, dynamicNftMetadataMockActive } from './dynamicNftMetadata.mock';
import { Network } from '@mintbase-js/sdk';
import { Network, mbjs } from '@mintbase-js/sdk';

jest.mock('graphql-request');

const props = {
contractAddress: 'dynamic.mintbase2.near',
contractAddress: `dynamic.${mbjs.keys.mbContractV2}`,
internalMetadataId: 0,
network: 'mainnet' as Network,
};
Expand Down
28 changes: 28 additions & 0 deletions packages/data/src/api/nftOwnersByStore/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[//]: # `{ "title": "userOwnedTokens", "order": "2.0.21" }`
# userOwnedTokens

{% hint style="warning" %}
This is a work in progress, please reach out to us on [Telegram](https://t.me/mintdev) for support.

For the most reliable data, reference our [existing graphql docs](https://docs.mintbase.io/dev/read-data/mintbase-graph).
{% endhint %}

Returns all owners of NFTs on `storeId`.

### nftOwnersByStore({storeId: string, network?: "mainnet" | "testnet"}): Promise<ParsedDataReturn<stringp[]>>

This is an example of a data api method.

Example:

{% code title="nftOwnersByStore.ts" overflow="wrap" lineNumbers="true" %}
```typescript
import { nftOwnersByStore } from '@mintbase-js/data'

const { data, error } = await nftOwnersByStore("mystore.mintbase1.near");

if (error) {console.log('error', error)}

console.log(data) // => ...
```
{% endcode %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { gql } from 'graphql-request';
import { QUERY_OPS_PREFIX } from '../../constants';

export const nftOwnersByStoreQuery = gql`
query ${QUERY_OPS_PREFIX}_getNftOwnersByStoreQuery(
$storeId: String!
) {
nft_tokens(
distinct_on: owner,
where: { nft_contract_id: { _eq: $contractId } }
) {
owner
}
}
`;
37 changes: 37 additions & 0 deletions packages/data/src/api/nftOwnersByStore/nftOwnersByStore.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { GraphQLClient } from 'graphql-request';
import { nftOwnersByStore } from './nftOwnersByStore';
import { NftOwnersByStoreQueryResult } from './nftOwnersByStore.types';

jest.mock('graphql-request');

describe('getMetadataByMetadataId', () => {
beforeEach(() => {
jest.spyOn(console, 'error').mockImplementation(() => {
// console.log('Suppressed console error.');
});
});

it('returns data', async () => {
(GraphQLClient as jest.Mock).mockImplementationOnce(() => ({
request: (): Promise<NftOwnersByStoreQueryResult> =>
Promise.resolve({
nft_tokens: [{ owner: 'owner1.near' }, { owner: 'owner2.near' }],
}),
}));

const result = await nftOwnersByStore('test');
expect(result?.data).toStrictEqual(['owner1.near', 'owner2.near']);
});

it('should handle errors', async () => {
const errMessage = 'exploded';
(GraphQLClient as jest.Mock).mockImplementationOnce(() => ({
request: (): Promise<NftOwnersByStoreQueryResult> =>
Promise.reject(new Error(errMessage)),
}));

const call = await nftOwnersByStore('test');

expect(call).toStrictEqual({ error: errMessage });
});
});
25 changes: 25 additions & 0 deletions packages/data/src/api/nftOwnersByStore/nftOwnersByStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Network } from '@mintbase-js/sdk';
import { fetchGraphQl } from '../../graphql/fetch';
import { ParsedDataReturn } from '../../types';
import { parseData } from '../../utils';
import { nftOwnersByStoreQuery } from './nftOwnersByStore.query';
import { NftOwnersByStoreQueryResult } from './nftOwnersByStore.types';

export const nftOwnersByStore = async (
storeId: string,
network?: Network,
): Promise<ParsedDataReturn<string[]>> => {
const { data, error } = await fetchGraphQl<NftOwnersByStoreQueryResult>({
query: nftOwnersByStoreQuery,
variables: {
storeId,
},
...(network && { network: network }),
});

const errorMsg = error
? `Error fetching NFT owners by store, ${error}`
: '';

return parseData<string[]>(data.nft_tokens.map(t => t.owner), error, errorMsg);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface NftOwnersByStoreQueryResult {
nft_tokens: { owner: string }[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ export const tokenOwnersByMetadataIdMock = {
},
},
};

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { META_SERVICE_HOST_TESTNET } from '../../constants';
import { OWNED_MINTED_ORDER_BY, ParsedDataReturn, UserTokensFilter, UserTokensQueryResult } from '../../types';
import { OWNED_MINTED_ORDER_BY, ParsedDataReturn, UserTokensQueryResult } from '../../types';
import fetchMock from 'fetch-mock';
import { Network, mbjs } from '@mintbase-js/sdk';
import { getUserMintedTokens } from '../userMintedTokens/userMintedTokens';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { META_SERVICE_HOST_TESTNET } from '../../constants';
import { OWNED_MINTED_ORDER_BY, ParsedDataReturn, UserTokensFilter, UserTokensQueryResult } from '../../types';
import { OWNED_MINTED_ORDER_BY, ParsedDataReturn, UserTokensQueryResult } from '../../types';

import fetchMock from 'fetch-mock';
import { Network, mbjs } from '@mintbase-js/sdk';
Expand Down
35 changes: 0 additions & 35 deletions packages/react/package.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/react/src/MintbaseWalletContext.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
// import { invokeContractMethod } from './transactions';
import React from 'react';
import { render, screen, act, waitFor } from '@testing-library/react';
import { act, render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { useMbWallet, MintbaseWalletContextProvider } from './MintbaseWalletContext';
import {
Expand Down
32 changes: 0 additions & 32 deletions packages/react/src/hooks/methods/nearPrice.ts

This file was deleted.

9 changes: 0 additions & 9 deletions packages/react/src/hooks/methods/nearPrice.types.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/react/src/hooks/useNearPrice.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from 'react';
import { nearPrice } from './methods/nearPrice';
import { nearPrice } from '@mintbase-js/data';

type UseNearPriceReturn = {
nearPrice: number;
Expand Down
2 changes: 1 addition & 1 deletion packages/rpc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mintbase-js/rpc",
"version": "0.6.0-beta-prerelease.0",
"version": "0.6.0-beta-prerelease.2",
"description": "NEAR RPC interactions for Mintbase JS SDK",
"main": "lib/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/rpc/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const callViewMethod = async <T>({
}: {
contractId: string;
method: string;
args?: Record<string, any>;
args?: Record<string, unknown>;
network?: string;
rpc?: RPC_OPTIONS;
}): Promise<T> => {
Expand Down
7 changes: 2 additions & 5 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mintbase-js/sdk",
"version": "0.6.0-beta-prerelease.0",
"version": "0.6.0-beta-prerelease.2",
"description": "Core functions for Mintbase JS SDK",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand All @@ -21,9 +21,6 @@
"license": "MIT",
"dependencies": {
"bn.js": "5.2.1",
"near-api-js": "^2.1.4"
},
"devDependencies": {
"@near-wallet-selector/core": "8.9.3"
"near-api-js": "^3.0.0"
}
}
1 change: 0 additions & 1 deletion packages/sdk/src/createMetadata/createMetadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { dateToTimestamp } from '../utils';

describe('createMetadata method tests', () => {
const contractAddress = `test.${mbjs.keys.mbContractV2}`;
// const contractAddressV2 = 'test.mintbase2.near';
const reference = 'test';
const media = 'test';

Expand Down
Loading
Loading