Skip to content
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
132 changes: 66 additions & 66 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
{
"name": "near.monorepo",
"version": "1.0.0",
"description": "Near Contract and React Monorepo",
"private": true,
"scripts": {
"apollo:generate": "yarn workspace @near/apollo generate",
"gql:dev": "yarn workspace @near/graphql dev:testnet",
"gql:dev:mainnet": "yarn workspace @near/graphql dev:mainnet",
"gql:start:mainnet": "yarn workspace @near/graphql start:mainnet",
"gql:start:testnet": "yarn workspace @near/graphql start:testnet",
"web:dev": "yarn workspace @near/web dev",
"web:build": "yarn workspace @near/web build",
"contract:build": "yarn workspace @near/contracts build:contract",
"contract:cargo:tests": "yarn workspace @near/contracts test:rust",
"contract:lib:tests": "yarn workspace @near/contracts test:lib",
"postinstall": "husky install",
"format:rust": "sh ./format_rust.sh",
"precommit": "lint-staged",
"setup:testnet:web": "node .github/utilities/set_testnet_environments.js"
},
"husky": {
"hooks": {
"pre-commit": "yarn precommit"
}
},
"lint-staged": {
"*.{ts,tsx}": [
"yarn prettier --config .prettierrc --write **/*.{ts,tsx}"
],
"*.{js,jsx}": [
"yarn prettier --config .prettierrc --write **/*.{js,jsx}"
],
"*.rs": [
"sh ./format_rust.sh"
]
},
"workspaces": {
"packages": [
"packages/*"
],
"nohoist": [
"**/tailwindcss",
"**/tailwindcss/**",
"**/postcss",
"**/postcss/**",
"**/autoprefixer",
"**/autoprefixer/**"
]
},
"license": "MIT",
"devDependencies": {
"@commitlint/cli": "^16.0.1",
"@commitlint/config-conventional": "^16.0.0",
"@types/jest": "^27.5.0",
"@typescript-eslint/eslint-plugin": "^5.22.0",
"@typescript-eslint/parser": "^5.22.0",
"eslint": "^8.15.0",
"eslint-plugin-react": "^7.29.4",
"husky": "^8.0.1",
"lint-staged": "^12.4.1",
"nodemon": "^2.0.15",
"prettier": "^2.6.2",
"sequelize": "^6.21.2",
"@types/sequelize": "^4.28.13"
}
{
"name": "near.monorepo",
"version": "1.0.0",
"description": "Near Contract and React Monorepo",
"private": true,
"scripts": {
"apollo:generate": "yarn workspace @near/apollo generate",
"gql:dev": "yarn workspace @near/graphql dev:testnet",
"gql:dev:mainnet": "yarn workspace @near/graphql dev:mainnet",
"gql:start:mainnet": "yarn workspace @near/graphql start:mainnet",
"gql:start:testnet": "yarn workspace @near/graphql start:testnet",
"web:dev": "yarn workspace @near/web dev",
"web:build": "yarn workspace @near/web build",
"contract:build": "yarn workspace @near/contracts build:contract",
"contract:cargo:tests": "yarn workspace @near/contracts test:rust",
"contract:lib:tests": "yarn workspace @near/contracts test:lib",
"postinstall": "husky install",
"format:rust": "sh ./format_rust.sh",
"precommit": "lint-staged",
"setup:testnet:web": "node .github/utilities/set_testnet_environments.js"
},
"husky": {
"hooks": {
"pre-commit": "yarn precommit"
}
},
"lint-staged": {
"*.{ts,tsx}": [
"yarn prettier --config .prettierrc --write **/*.{ts,tsx}"
],
"*.{js,jsx}": [
"yarn prettier --config .prettierrc --write **/*.{js,jsx}"
],
"*.rs": [
"sh ./format_rust.sh"
]
},
"workspaces": {
"packages": [
"packages/*"
],
"nohoist": [
"**/tailwindcss",
"**/tailwindcss/**",
"**/postcss",
"**/postcss/**",
"**/autoprefixer",
"**/autoprefixer/**"
]
},
"license": "MIT",
"devDependencies": {
"@commitlint/cli": "^16.0.1",
"@commitlint/config-conventional": "^16.0.0",
"@types/jest": "^27.5.0",
"@typescript-eslint/eslint-plugin": "^5.22.0",
"@typescript-eslint/parser": "^5.22.0",
"eslint": "^8.15.0",
"eslint-plugin-react": "^7.29.4",
"husky": "^8.0.1",
"lint-staged": "^12.4.1",
"nodemon": "^2.0.15",
"prettier": "^2.6.2",
"sequelize": "^6.21.2",
"@types/sequelize": "^4.28.13"
}
}
24 changes: 22 additions & 2 deletions packages/apollo/src/generated/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,18 @@ export type QueryNftStakingProjectsArgs = {
limit?: InputMaybe<Scalars["Int"]>;
offset?: InputMaybe<Scalars["Int"]>;
search?: InputMaybe<Scalars["String"]>;
showStaked?: InputMaybe<StakedEnum>;
};

export type QueryStakingArgs = {
collection_id: Scalars["ID"];
};

export enum StakedEnum {
No = "No",
Yes = "Yes",
}

export type StakedNft = {
__typename?: "StakedNFT";
collection_id?: Maybe<Scalars["ID"]>;
Expand Down Expand Up @@ -371,8 +377,10 @@ export type LaunchPadProjectQuery = {
};

export type NftStakingProjectsConnectionQueryVariables = Exact<{
search?: InputMaybe<Scalars["String"]>;
limit?: InputMaybe<Scalars["Int"]>;
offset?: InputMaybe<Scalars["Int"]>;
showStaked?: InputMaybe<StakedEnum>;
}>;

export type NftStakingProjectsConnectionQuery = {
Expand Down Expand Up @@ -736,8 +744,18 @@ export type LaunchPadProjectQueryResult = Apollo.QueryResult<
LaunchPadProjectQueryVariables
>;
export const NftStakingProjectsConnectionDocument = gql`
query NFTStakingProjectsConnection($limit: Int, $offset: Int) {
nft_staking_projects(limit: $limit, offset: $offset) {
query NFTStakingProjectsConnection(
$search: String
$limit: Int
$offset: Int
$showStaked: StakedEnum
) {
nft_staking_projects(
search: $search
limit: $limit
offset: $offset
showStaked: $showStaked
) {
pageSize
totalCount
itemsPerPage
Expand Down Expand Up @@ -778,8 +796,10 @@ export const NftStakingProjectsConnectionDocument = gql`
* @example
* const { data, loading, error } = useNftStakingProjectsConnectionQuery({
* variables: {
* search: // value for 'search'
* limit: // value for 'limit'
* offset: // value for 'offset'
* showStaked: // value for 'showStaked'
* },
* });
*/
Expand Down
14 changes: 12 additions & 2 deletions packages/apollo/src/graphql/nft_staking_connection.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
query NFTStakingProjectsConnection($limit: Int, $offset: Int) {
nft_staking_projects(limit: $limit, offset: $offset) {
query NFTStakingProjectsConnection(
$search: String
$limit: Int
$offset: Int
$showStaked: StakedEnum
) {
nft_staking_projects(
search: $search
limit: $limit
offset: $offset
showStaked: $showStaked
) {
pageSize
totalCount
itemsPerPage
Expand Down
84 changes: 77 additions & 7 deletions packages/graphql/src/modules/nft-staking/resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { CommonErrors } from "@/errors";
import { GraphQLContext } from "@/types";
import { NFTStaking } from "@/types/nft-staking";
import {
NFTStaking,
NFTStakingFilters,
PaginatedNFTStakingFilters,
} from "@/types/nft-staking";
import { QueryTypes } from "sequelize";
import { StakedEnum } from "@near/apollo";
import {
findCollectionMetadata,
findStakingProgram,
Expand Down Expand Up @@ -82,18 +87,83 @@ export default {
},
async nft_staking_projects(
_root: unknown,
{ limit, offset }: PaginationFilters & { search: string },
filters: Partial<PaginatedNFTStakingFilters>,
{ sequelize }: GraphQLContext
) {
type BindParameterClause = (offset: number) => string;
type QueryClause = string | BindParameterClause;
type FiltersMap<K extends string> = {
[key in K]: {
active: boolean;
joinClause?: QueryClause;
whereClause?: QueryClause;
params?: any[];
};
};

const evalQueryClause = (clause: QueryClause, offset: number) =>
typeof clause == "string" ? clause : clause(offset);

const filtersMap: FiltersMap<keyof NFTStakingFilters> = {
search: {
active: !!filters.search,
whereClause: (offset: number) =>
`(s.collection_id ILIKE $${1 + offset} || '%')`,
params: [filters.search],
},
showStaked: {
active: !!filters.showStaked,
whereClause:
filters.showStaked == "Yes"
? "exists (select 1 from staked_nfts as a where s.collection_id = a.collection_id)"
: "not exists (select 1 from staked_nfts as a where s.collection_id = a.collection_id)",
},
};

const baseQuery = `SELECT * FROM "staking_programs" AS s INNER JOIN "staking_programs_metadata" AS m ON (s.collection_id = m.collection_id)`;

const joinClauseStatements: string[] = [];
const whereClauseStatements: string[] = [];
const params: any[] = [];
for (const filter of Object.values(filtersMap)) {
if (!filter.active) continue;

if (filter.joinClause) {
joinClauseStatements.push(
evalQueryClause(filter.joinClause, params.length)
);
}

if (filter.whereClause) {
whereClauseStatements.push(
evalQueryClause(filter.whereClause, params.length)
);
}

if (filter.params?.length) {
params.push(...filter.params);
}
}

const joinClause = joinClauseStatements.length
? joinClauseStatements.join(" ")
: "";
const whereClause = whereClauseStatements.length
? `WHERE ${whereClauseStatements.join(" AND")}`
: "";

const finalQuery = [baseQuery, joinClause, whereClause]
.filter((clause) => clause.length)
.join(" ");

return createPageableQuery(
`SELECT * FROM "staking_programs" AS s INNER JOIN "staking_programs_metadata" AS m
ON (s.collection_id = m.collection_id)`,
finalQuery,
sequelize,
{
limit,
offset,
limit: filters.limit,
offset: filters.offset,
},
[]
params
);
},
},
Expand Down
12 changes: 11 additions & 1 deletion packages/graphql/src/modules/nft-staking/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export default gql`
account_id: String
}

enum StakedEnum {
Yes
No
}

type StakedNFT {
# SQL + Blockchain Data
nft_id: ID
Expand All @@ -53,7 +58,12 @@ export default gql`
}

type Query {
nft_staking_projects(limit: Int, offset: Int, search: String): NFTPage!
nft_staking_projects(
limit: Int
offset: Int
search: String
showStaked: StakedEnum
): NFTPage!
staking(collection_id: ID!): NFTStaking
}
`;
2 changes: 2 additions & 0 deletions packages/graphql/src/types/nft-staking.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ID } from "./graphql-types";
import { StakedEnum } from "@near/apollo";
import { PaginationFilters } from "@/modules/tools/createPaginatedConnection";

export type NFTStaking = {
Expand All @@ -24,6 +25,7 @@ export type StakedNFT = {

export type NFTStakingFilters = {
search: string;
showStaked: StakedEnum;
};

export type PaginatedNFTStakingFilters = NFTStakingFilters & PaginationFilters;
2 changes: 1 addition & 1 deletion packages/web/src/components/shared/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function Header() {
const { accountId, toggleModal, signOut } = useWalletSelector();

return (
<div className="z-10 pt-[30px] absolute top-0 right-0 z-2 left-0 flex items-center justify-center ml-[120px]">
<div className="z-10 pt-[30px] absolute top-0 right-0 z-2 left-0 flex items-center justify-center md:ml-[120px]">
<AirdropModal
isOpen={showTokenModal}
onClose={() => setShowTokenModal(false)}
Expand Down
Loading