Skip to content

Commit

Permalink
chore: setup eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
Meemaw committed Dec 15, 2021
1 parent 75f1061 commit 6d76c93
Show file tree
Hide file tree
Showing 15 changed files with 845 additions and 200 deletions.
57 changes: 57 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const restrictedGlobals = require("confusing-browser-globals");

module.exports = {
env: {
browser: true,
node: true,
},
root: true,
reportUnusedDisableDirectives: true,
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint", "import", "jest", "prettier"],
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"plugin:prettier/recommended",
],
rules: {
"no-restricted-globals": ["error"].concat(restrictedGlobals),
curly: ["error"],
"@typescript-eslint/no-unused-vars": [
"error",
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
],
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-var-requires": "off",
"import/order": [
"error",
{
groups: ["builtin", "external", "internal"],
"newlines-between": "never",
alphabetize: {
order: "asc",
caseInsensitive: true,
},
},
],
"import/no-unused-modules": [1, { unusedExports: true }],
"no-control-regex": "off",

"object-shorthand": ["error", "always"],
},
settings: {
"import/resolver": {
node: {
extensions: [".js", ".ts", ".tsx", ".json"],
},
typescript: {
alwaysTryTypes: true,
project: "src",
},
},
},
};
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
src/api.ts
lib
14 changes: 13 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"docs": "npm run docsHtml",
"docsHtml": "./node_modules/.bin/typedoc --target ES5 --exclude src/abi --excludePrivate --out ./docs --ignoreCompilerErrors --mode file",
"docsMarkdown": "./node_modules/.bin/typedoc --theme markdown --target ES5 --exclude src/abi --excludePrivate --out ./docs_markdown --ignoreCompilerErrors --mode file",
"lint:check": "concurrently \"yarn check-types\" \"yarn prettier:check\"",
"eslint:check": "eslint . --max-warnings 0 --ext .js,.ts",
"lint:check": "concurrently \"yarn check-types\" \"yarn prettier:check\" \"yarn eslint:check\"",
"prepare": "husky install",
"test": "./node_modules/.bin/mocha test/**/*.ts --require ts-node/register --timeout 15000",
"prettier:check": "prettier --check .",
Expand All @@ -49,8 +50,16 @@
"@types/node": "^9.3.0",
"@types/node-fetch": "2.5.5",
"@types/query-string": "^6.1.0",
"@typescript-eslint/eslint-plugin": "^5.7.0",
"@typescript-eslint/parser": "^5.7.0",
"chai": "^4.1.2",
"concurrently": "6.4.0",
"confusing-browser-globals": "^1.0.11",
"eslint": "^8.4.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jest": "^25.3.0",
"eslint-plugin-prettier": "^4.0.0",
"husky": "7.0.4",
"lint-staged": "12.1.2",
"mocha": "^5.2.0",
Expand Down Expand Up @@ -83,6 +92,9 @@
],
"**/*.{ts,tsx,js,jsx,html,md,mdx,yml,json}": [
"prettier --write"
],
"**/*.{ts,tsx,js,jsx}": [
"eslint --cache --fix"
]
}
}
39 changes: 20 additions & 19 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import 'isomorphic-unfetch'
import * as QueryString from 'query-string'
import {
API_BASE_MAINNET,
API_BASE_RINKEBY,
API_PATH,
ORDERBOOK_PATH,
ORDERBOOK_VERSION,
SITE_HOST_MAINNET,
SITE_HOST_RINKEBY
} from './constants'
import {
Network,
OpenSeaAPIConfig,
Expand All @@ -21,15 +30,7 @@ import {
orderFromJSON,
tokenFromJSON
} from './utils/utils'
import {
API_BASE_MAINNET,
API_BASE_RINKEBY,
API_PATH,
ORDERBOOK_PATH,
ORDERBOOK_VERSION,
SITE_HOST_MAINNET,
SITE_HOST_RINKEBY
} from './constants'



export class OpenSeaAPI {
Expand Down Expand Up @@ -111,10 +112,10 @@ export class OpenSeaAPI {
email: string
): Promise<boolean> {

const json = await this.post(`${API_PATH}/asset/${tokenAddress}/${tokenId}/whitelist/`, {
const json = await this.post<{success:boolean}>(`${API_PATH}/asset/${tokenAddress}/${tokenId}/whitelist/`, {
email
})

return !!json.success
}

Expand Down Expand Up @@ -221,14 +222,14 @@ export class OpenSeaAPI {
page = 1
): Promise<{assets: OpenSeaAsset[]; estimatedCount: number}> {

const json = await this.get(`${API_PATH}/assets/`, {
const json = await this.get<{estimated_count: number; assets:unknown[]}>(`${API_PATH}/assets/`, {
limit: this.pageSize,
offset: (page - 1) * this.pageSize,
...query
})

return {
assets: json.assets.map((j: any) => assetFromJSON(j)),
assets: json.assets.map((j) => assetFromJSON(j)),
estimatedCount: json.estimated_count
}
}
Expand All @@ -248,7 +249,7 @@ export class OpenSeaAPI {

let json
try {
json = await this.get(`${API_PATH}/tokens/`, {
json = await this.get<unknown[]>(`${API_PATH}/tokens/`, {
...query,
limit: this.pageSize,
offset: (page - 1) * this.pageSize
Expand All @@ -260,7 +261,7 @@ export class OpenSeaAPI {
}

return {
tokens: json.map((t: any) => tokenFromJSON(t))
tokens: json.map((t) => tokenFromJSON(t))
}
}

Expand Down Expand Up @@ -288,14 +289,14 @@ export class OpenSeaAPI {
page = 1
): Promise<{bundles: OpenSeaAssetBundle[]; estimatedCount: number}> {

const json = await this.get(`${API_PATH}/bundles/`, {
const json = await this.get<{estimated_count: number; bundles: unknown[]}>(`${API_PATH}/bundles/`, {
...query,
limit: this.pageSize,
offset: (page - 1) * this.pageSize
})

return {
bundles: json.bundles.map((j: any) => assetBundleFromJSON(j)),
bundles: json.bundles.map((j) => assetBundleFromJSON(j)),
estimatedCount: json.estimated_count
}
}
Expand All @@ -305,7 +306,7 @@ export class OpenSeaAPI {
* @param apiPath Path to URL endpoint under API
* @param query Data to send. Will be stringified using QueryString
*/
public async get(apiPath: string, query: object = {}): Promise<any> {
public async get<T>(apiPath: string, query: object = {}): Promise<T> {

const qs = QueryString.stringify(query)
const url = `${apiPath}?${qs}`
Expand All @@ -321,7 +322,7 @@ export class OpenSeaAPI {
* @param opts RequestInit opts, similar to Fetch API. If it contains
* a body, it won't be stringified.
*/
public async post(apiPath: string, body?: object, opts: RequestInit = {}): Promise<any> {
public async post<T>(apiPath: string, body?: object, opts: RequestInit = {}): Promise<T> {

const fetchOpts = {
method: 'POST',
Expand Down
8 changes: 1 addition & 7 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@ export const NULL_BLOCK_HASH =
"0x0000000000000000000000000000000000000000000000000000000000000000";
export const OPENSEA_FEE_RECIPIENT =
"0x5b3256965e7c3cf26e11fcaf296dfc8807c01073";
export const DEP_INFURA_KEY = "e8695bce67944848aa95459fac052f8e";
export const INVERSE_BASIS_POINT = 10000;
export const MAX_UINT_256 = WyvernProtocol.MAX_UINT_256;
export const WYVERN_EXCHANGE_ADDRESS_MAINNET =
"0x7be8076f4ea4a4ad08075c2508e481d6c946d12b";
export const WYVERN_EXCHANGE_ADDRESS_RINKEBY =
"0x5206e78b21ce315ce284fb24cf05e0585a93b1d9";
export const ENJIN_COIN_ADDRESS = "0xf629cbd94d3791c9250152bd8dfbdf380e2a3b9c";
export const MANA_ADDRESS = "0x0f5d2fb29fb7d3cfee444a200298f468908cc942";
export const ENJIN_ADDRESS = "0xfaaFDc07907ff5120a76b34b731b278c38d6043C";
Expand Down Expand Up @@ -58,8 +53,7 @@ export const DEFAULT_MAX_BOUNTY = DEFAULT_SELLER_FEE_BASIS_POINTS;
export const MIN_EXPIRATION_SECONDS = 10;
export const ORDER_MATCHING_LATENCY_SECONDS = 60 * 60 * 24 * 7;
export const SELL_ORDER_BATCH_SIZE = 3;
export const ORDERBOOK_VERSION: number = 1;
export const API_VERSION: number = 1;
export const ORDERBOOK_VERSION = 1 as number;
export const API_BASE_MAINNET = "https://api.opensea.io";
export const API_BASE_RINKEBY = "https://testnets-api.opensea.io";
export const SITE_HOST_MAINNET = "https://opensea.io";
Expand Down
22 changes: 2 additions & 20 deletions src/contracts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { PartialReadonlyContractAbi } from "./types";
import { EventAbi } from "web3";
import { AnnotatedFunctionABI } from "wyvern-js/lib/types";
import type { AnnotatedFunctionABI } from "wyvern-js/lib/types";
import type { PartialReadonlyContractAbi } from "./types";

export const getMethod = (
abi: PartialReadonlyContractAbi,
Expand All @@ -15,23 +14,6 @@ export const getMethod = (
return methodAbi as AnnotatedFunctionABI;
};

export const event = (
abi: PartialReadonlyContractAbi,
name: string
): EventAbi => {
const eventAbi = abi.find((x) => x.type == "event" && x.name == name);
if (!eventAbi) {
throw new Error(`ABI ${name} not found`);
}
// Have to cast since there's a bug in
// web3 types on the 'type' field
return eventAbi as EventAbi;
};

export const DECENTRALAND_AUCTION_CONFIG = {
"1": "0xf87e31492faf9a91b02ee0deaad50d51d56d5d4d",
};

export { ERC20 } from "./abi/ERC20";
export { ERC721 } from "./abi/ERC721v3";
export { ERC1155 } from "./abi/ERC1155";
Expand Down
2 changes: 1 addition & 1 deletion src/debugging.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { WyvernProtocol } from "wyvern-js";
import { NULL_ADDRESS } from "./constants";
import { Order } from "./types";
import type { Order } from "./types";

export const MAX_ERROR_LENGTH = 120;

Expand Down
8 changes: 5 additions & 3 deletions src/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/no-unused-modules */
// NO IMPORTS HERE
// Should be top-level

Expand All @@ -8,17 +9,18 @@ declare module "web3-provider-engine/subproviders/rpc";

/* tslint:enable */
declare module "*.json" {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const json: any;
/* tslint:disable */
export default json;
/* tslint:enable */
}

declare module "ethereumjs-abi" {
const soliditySHA3: (argTypes: string[], args: any[]) => Buffer;
const soliditySHA3: (argTypes: string[], args: unknown[]) => Buffer;
const methodID: (name: string, types: string[]) => Buffer;
const rawEncode: (argTypes: string[], args: any[]) => Buffer;
const encodeSingle: (type: string, arg: any) => Buffer;
const rawEncode: (argTypes: string[], args: unknown[]) => Buffer;
const encodeSingle: (type: string, arg: unknown) => Buffer;
const elementaryName: (name: string) => string;
const isDynamic: (type: string) => boolean;
}
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { OpenSeaPort } from "./seaport";
/* eslint-disable import/no-unused-modules */
import { OpenSeaAPI } from "./api";
import { OpenSeaPort } from "./seaport";
import { Network, EventData, EventType } from "./types";
export { orderToJSON, orderFromJSON, WyvernProtocol } from "./utils/utils";
export {
Expand Down Expand Up @@ -30,9 +31,8 @@ export {
OpenSeaAPI,
// Useful for serializing and deserializing orders:
// Types to help initialize SDK and listen to events.
// Can also be imported using e.g.
// import { EventType } from 'opensea-js/lib/types'
EventData,
EventType,
Network,
};

export type { EventData };
Loading

0 comments on commit 6d76c93

Please sign in to comment.