Skip to content

Commit

Permalink
Merge pull request #183 from Mintbase/burn-and-tokens-by-status
Browse files Browse the repository at this point in the history
✨ Burn structure + Tokens by status query
  • Loading branch information
SurgeCode committed Nov 23, 2022
2 parents f6033c9 + 8a06d13 commit fd674e2
Show file tree
Hide file tree
Showing 31 changed files with 444 additions and 191 deletions.
85 changes: 65 additions & 20 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,80 @@
"plugin:react/recommended"
],
"ignorePatterns": [
"jest.config.js", "lib/**", "src-v2/**", "packages/data/src/graphql/codegen/**", "*.js"
"jest.config.js",
"lib/**",
"src-v2/**",
"packages/data/src/graphql/codegen/**",
"*.js"
],

"rules": {
"@typescript-eslint/explicit-function-return-type": "error",
"@typescript-eslint/no-use-before-define": "off",
"brace-style": ["error", "1tbs", { "allowSingleLine": true }],
"comma-dangle": ["error", "always-multiline"],
"brace-style": [
"error",
"1tbs",
{
"allowSingleLine": true
}
],
"comma-dangle": [
"error",
"always-multiline"
],
"consistent-return": "error",
"eol-last": ["error", "always"],
"indent": ["error", 2],
"max-len": ["error", {
"code": 100,
"tabWidth": 4,
"ignoreStrings": true,
"ignoreComments": true,
"ignoreUrls": true
}],
"no-multiple-empty-lines": ["error", { "max": 2, "maxBOF": 1 }],
"object-curly-spacing": ["error", "always"],
"semi": ["error", "always"],
"space-before-blocks": ["error", "always"],
"keyword-spacing": ["error", { "before": true, "after": true }],
"quotes": ["error", "single"],
"eol-last": [
"error",
"always"
],
"indent": [
"error",
2
],
"max-len": [
"error",
{
"code": 200,
"tabWidth": 4,
"ignoreStrings": true,
"ignoreComments": true,
"ignoreUrls": true
}
],
"no-multiple-empty-lines": [
"error",
{
"max": 2,
"maxBOF": 1
}
],
"object-curly-spacing": [
"error",
"always"
],
"semi": [
"error",
"always"
],
"space-before-blocks": [
"error",
"always"
],
"keyword-spacing": [
"error",
{
"before": true,
"after": true
}
],
"quotes": [
"error",
"single"
],
"react/prop-types": "off",
"react/react-in-jsx-scope": "off"
},
"env": {
"browser": true,
"es6": true
}
}
}
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
- name: Publish Push Prerelease
if: ${{ github.event.head_commit.message }}
run: |
lerna version --conventional-commits --yes --skip-git --preid ${{ github.ref_name }}
lerna version prerelease --yes --skip-git --preid ${{ github.ref_name }}
git add --all
git commit -m "🤖 npm publish version $(cat ./lerna.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[",]//g')"
lerna publish from-package --yes --dist-tag prerelease
Expand Down
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */

process.env.NEAR_DATA_ENV='testnet'
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
coveragePathIgnorePatterns: ['lib/', 'constants.ts'],
modulePathIgnorePatterns: ['lib/'],
testTimeout: 60000,
moduleNameMapper: {
'@near-wallet-selector/meteor-wallet': '<rootDir>/jest.stub.js'
}
Expand Down
4 changes: 4 additions & 0 deletions jest.stub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-disable no-undef */
module.exports = {
setupMeteorWallet: jest.fn(),
};
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useNx": true,
"useWorkspaces": true,
"version": "0.1.0-modular-refactor.0",
"version": "0.1.0-burn-and-tokens-by-status.0",
"packages": [
"packages/*"
]
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/app/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "mintbase-next-test-suite",
"version": "0.1.0-modular-refactor.0",
"version": "0.1.0-burn-and-tokens-by-status.0",
"private": true,
"scripts": {
"dev": "next dev",
"lint": "eslint . --fix --ext ts --ext tsx"
},
"dependencies": {
"@mintbase-js/sdk": "^0.1.0-modular-refactor.0",
"@mintbase-js/sdk": "^0.1.0-burn-and-tokens-by-status.0",
"next": "12.3.1",
"react": "18.2.0",
"react-dom": "18.2.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mintbase-js/auth",
"version": "0.1.0-modular-refactor.0",
"version": "0.1.0-burn-and-tokens-by-status.0",
"description": "Wallet and auth functions for Mintbase JS SDK",
"main": "lib/index.js",
"scripts": {
Expand All @@ -19,7 +19,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"@mintbase-js/sdk": "^0.1.0-modular-refactor.0",
"@mintbase-js/sdk": "^0.1.0-burn-and-tokens-by-status.0",
"@near-wallet-selector/coin98-wallet": "^7.2.0",
"@near-wallet-selector/core": "^7.1.0",
"@near-wallet-selector/default-wallets": "^7.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/data/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mintbase-js/data",
"version": "0.1.0-modular-refactor.0",
"version": "0.1.0-burn-and-tokens-by-status.0",
"description": "Query wrappers for Mintbase JS SDK",
"main": "lib/index.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions packages/data/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './tokenListingCounts/tokenListingCountsByMetaId';
export * from './ownedTokens/ownedTokens';
export * from './tokensByStatus/tokensByStatus';
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('tokenListingCountsByMetaId', () => {
});

it('should use the upper bound of token counts for display', async () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const makeAggregate = (val: string): any => ({
aggregate: {
count: val,
Expand Down
51 changes: 51 additions & 0 deletions packages/data/src/api/tokensByStatus/tokensByStatus.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* eslint-disable @typescript-eslint/camelcase */
import { GraphQLClient } from 'graphql-request';
import { GraphqlFetchingError } from '../../graphql/fetch';
import { TokensByStatus, tokensByStatus } from './tokensByStatus';

jest.mock('graphql-request');

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

it('should handle errors', async () => {
const errMessage = 'exploded';
const exploded = new GraphqlFetchingError(errMessage);
(GraphQLClient as jest.Mock).mockImplementationOnce(() => ({
request: (): Promise<TokensByStatus> => Promise.reject(errMessage),
}));
await expect(tokensByStatus('test.id')).rejects.toThrow(exploded);
});

it('should show correct values for each type', async () => {
const unburnedTokensMock = getNodeObjectFromTokenIds(['27', '28', '30']);
const burnedTokensMock = getNodeObjectFromTokenIds(['29']);
const listedTokensMock = getNodeObjectFromTokenIds(['27', '28']);
(GraphQLClient as jest.Mock).mockImplementationOnce(() => ({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
request: (): Promise<any> =>
Promise.resolve({
listedTokens: listedTokensMock,
burnedTokens: burnedTokensMock,
unburnedTokens: unburnedTokensMock,
}),
}));

const { listedTokens, burnedTokens, unlistedTokens } = await tokensByStatus('test.id');
expect(listedTokens).toStrictEqual(['27', '28']);
expect(burnedTokens).toStrictEqual(['29']);
expect(unlistedTokens).toStrictEqual(['30']);
});
});

function getNodeObjectFromTokenIds(tokenIds: string[]): { nodes: { token_id: string }[] } {
const arr: { token_id: string }[] = [];
tokenIds.forEach((token: string) => {
arr.push({ token_id: token });
});
return { nodes: arr };
}
48 changes: 48 additions & 0 deletions packages/data/src/api/tokensByStatus/tokensByStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { NftTokensAggregate } from '../../graphql/codegen/graphql';
import { fetchGraphQl } from '../../graphql/fetch';
import { tokensByStatusQuery } from './tokensByStatusQuery';

export type TokensByStatus = {
listedTokens: string[];
burnedTokens: string[];
unlistedTokens: string[];
};

export type TokenByStatusQueryResults = {
listedTokens: NftTokensAggregate;
burnedTokens: NftTokensAggregate;
unburnedTokens: NftTokensAggregate;
};

export const tokensByStatus = async (metadataId: string, ownedBy?: string): Promise<TokensByStatus> => {
const { data, error } = await fetchGraphQl<TokenByStatusQueryResults>({
query: tokensByStatusQuery,
variables: {
metadataId,
ownedBy,
},
});

if (error) {
console.error('Error fetching token listing by status', error.message);
throw error;
}
const listedTokens = getTokenArrayFromNodes(data.listedTokens.nodes);
const burnedTokens = getTokenArrayFromNodes(data.burnedTokens.nodes);
const unburnedTokens = getTokenArrayFromNodes(data.unburnedTokens.nodes);
const unlistedTokens = unburnedTokens.filter((el: string) => !listedTokens.includes(el));

return {
listedTokens,
burnedTokens,
unlistedTokens,
};
};

function getTokenArrayFromNodes(nodes: { token_id: string }[]): string[] {
const arr: string[] = [];
nodes.forEach((token: { token_id: string }) => {
arr.push(token.token_id);
});
return arr;
}
48 changes: 48 additions & 0 deletions packages/data/src/api/tokensByStatus/tokensByStatusQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { gql } from 'graphql-request';
import { QUERY_OPS_PREFIX } from '../../constants';

export const tokensByStatusQuery = gql`
query ${QUERY_OPS_PREFIX}_tokensByStatus (
$metadataId: String!
$ownedBy: String
) {
# unburned tokens count
unburnedTokens: nft_tokens_aggregate(
where: {
metadata_id: { _eq: $metadataId }
burned_timestamp: { _is_null: true }
owner: { _eq: $ownedBy}
}
) {
nodes {
token_id
}
}
burnedTokens: nft_tokens_aggregate(
where: {
metadata_id: { _eq: $metadataId }
burned_timestamp: { _is_null: false }
owner: { _eq: $ownedBy}
}
) {
nodes {
token_id
}
}
#listed tokens
listedTokens: mb_views_active_listings_aggregate(
where: {
metadata_id: { _eq: $metadataId }
listed_by: { _eq: $ownedBy}
}
) {
nodes {
token_id
}
}
}
`;
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mintbase-js/react",
"version": "0.1.0-modular-refactor.0",
"version": "0.1.0-burn-and-tokens-by-status.0",
"description": "React app tools for Mintbase JS SDK",
"main": "lib/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mintbase-js/sdk",
"version": "0.1.0-modular-refactor.0",
"version": "0.1.0-burn-and-tokens-by-status.0",
"description": "Core functions for Mintbase JS SDK",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down

0 comments on commit fd674e2

Please sign in to comment.