Skip to content

Commit

Permalink
fix prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
josemarinas committed Oct 26, 2023
1 parent 4222eea commit 9a9ffe2
Show file tree
Hide file tree
Showing 8 changed files with 291 additions and 317 deletions.
32 changes: 16 additions & 16 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
root: true

extends:
- "eslint:recommended"
- "plugin:@typescript-eslint/eslint-recommended"
- "plugin:@typescript-eslint/recommended"
- "prettier"
- 'eslint:recommended'
- 'plugin:@typescript-eslint/eslint-recommended'
- 'plugin:@typescript-eslint/recommended'
- 'prettier'

plugins:
- "@typescript-eslint"
- '@typescript-eslint'

rules:
"@typescript-eslint/no-floating-promises":
'@typescript-eslint/no-floating-promises':
- error
- ignoreIIFE: true
ignoreVoid: true
"@typescript-eslint/no-inferrable-types": "off"
"@typescript-eslint/no-explicit-any": "off"
"@typescript-eslint/no-unused-vars":
'@typescript-eslint/no-inferrable-types': 'off'
'@typescript-eslint/no-explicit-any': 'off'
'@typescript-eslint/no-unused-vars':
- error
- argsIgnorePattern: "_"
varsIgnorePattern: "_"
- argsIgnorePattern: '_'
varsIgnorePattern: '_'

ignorePatterns:
- "*.log"
- "*.env"
- ".env"
- ".DS_Store"
- '*.log'
- '*.env'
- '.env'
- '.DS_Store'
- .pnp.*
- "node_modules"
- 'node_modules'
6 changes: 3 additions & 3 deletions js-client/examples/02-extended-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ title: Extended client
Use the ClientCore class to create an extended client. Now you can add your custom functions and properties to the client.
*/
import { ClientCore } from "../src";
import { MyContext } from "./01-extended-context";
import { ClientCore } from '../src';
import { MyContext } from './01-extended-context';

// define a custom client that extends the ClientCore class
class MyClient extends ClientCore {
Expand All @@ -20,7 +20,7 @@ class MyClient extends ClientCore {
}

public customFunction() {
return "hello world";
return 'hello world';
}

public async customFunction2() {
Expand Down
58 changes: 29 additions & 29 deletions js-client/src/context-core.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import { GRAPHQL_NODES, IPFS_NODES, LIVE_CONTRACTS } from "./constants";
import { GRAPHQL_NODES, IPFS_NODES, LIVE_CONTRACTS } from './constants';
import {
InvalidAddressError,
InvalidGasEstimationFactorError,
UnsupportedNetworkError,
UnsupportedProtocolError,
} from "./errors";
import { DeployedAddressesArray } from "./internal";
} from './errors';
import { DeployedAddressesArray } from './internal';
import {
ContextParams,
ContextState,
OverriddenState,
SupportedNetwork,
SupportedNetworksArray,
SupportedVersion,
} from "./types";
import { getNetwork } from "./utils";
import { Client as IpfsClient } from "@aragon/sdk-ipfs";
import { Signer } from "@ethersproject/abstract-signer";
import { isAddress } from "@ethersproject/address";
import { JsonRpcProvider, Network, Networkish } from "@ethersproject/providers";
import { GraphQLClient } from "graphql-request";
} from './types';
import { getNetwork } from './utils';
import { Client as IpfsClient } from '@aragon/sdk-ipfs';
import { Signer } from '@ethersproject/abstract-signer';
import { isAddress } from '@ethersproject/address';
import { JsonRpcProvider, Network, Networkish } from '@ethersproject/providers';
import { GraphQLClient } from 'graphql-request';

const DEFAULT_GAS_FEE_ESTIMATION_FACTOR = 0.625;
const supportedProtocols = ["https:"];
if (typeof process !== "undefined" && process?.env?.TESTING) {
supportedProtocols.push("http:");
const supportedProtocols = ['https:'];
if (typeof process !== 'undefined' && process?.env?.TESTING) {
supportedProtocols.push('http:');
}

export abstract class ContextCore {
Expand Down Expand Up @@ -53,15 +53,15 @@ export abstract class ContextCore {
*/
constructor(params?: Partial<ContextParams>) {
// set network to mainnet, overrided by the value of params
const mergedParams = Object.assign({ network: "mainnet" }, params);
const mergedParams = Object.assign({ network: 'mainnet' }, params);
this.set(mergedParams);
}

set(contextParams: Partial<ContextParams>) {
if (contextParams.network) {
this.state.network = ContextCore.resolveNetwork(
contextParams.network,
contextParams.ensRegistryAddress,
contextParams.ensRegistryAddress
);
// once the network is resolved set default values
this.setNetworkDefaults();
Expand All @@ -76,12 +76,12 @@ export abstract class ContextCore {
) {
this.state.web3Providers = ContextCore.resolveWeb3Providers(
contextParams.web3Providers,
this.state.network,
this.state.network
);
}
if (contextParams.graphqlNodes?.length) {
this.state.graphql = ContextCore.resolveGraphql(
contextParams.graphqlNodes,
contextParams.graphqlNodes
);
this.overriden.graphqlNodes = true;
}
Expand All @@ -92,15 +92,15 @@ export abstract class ContextCore {
// Set all the available addresses
for (const address of DeployedAddressesArray) {
if (contextParams[address]) {
this.state[address] = contextParams[address] ?? "";
this.state[address] = contextParams[address] ?? '';
this.overriden[address] = true;
}
}

if (contextParams.gasFeeEstimationFactor) {
this.state.gasFeeEstimationFactor = ContextCore
.resolveGasFeeEstimationFactor(
contextParams.gasFeeEstimationFactor,
this.state.gasFeeEstimationFactor =
ContextCore.resolveGasFeeEstimationFactor(
contextParams.gasFeeEstimationFactor
);
this.overriden.gasFeeEstimationFactor = true;
}
Expand All @@ -118,7 +118,7 @@ export abstract class ContextCore {

if (!this.overriden.graphqlNodes) {
this.state.graphql = ContextCore.resolveGraphql(
GRAPHQL_NODES[networkName],
GRAPHQL_NODES[networkName]
);
}

Expand All @@ -131,7 +131,7 @@ export abstract class ContextCore {
let defaultAddress =
LIVE_CONTRACTS[SupportedVersion.LATEST][networkName][address];
// custom check for ensRegistryAddress
if (address === "ensRegistryAddress" && !defaultAddress) {
if (address === 'ensRegistryAddress' && !defaultAddress) {
defaultAddress = this.network.ensAddress;
}
if (defaultAddress) {
Expand Down Expand Up @@ -343,7 +343,7 @@ export abstract class ContextCore {
// INTERNAL HELPERS
private static resolveNetwork(
networkish: Networkish,
ensRegistryAddress?: string,
ensRegistryAddress?: string
): Network {
const network = getNetwork(networkish);
const networkName = network.name as SupportedNetwork;
Expand Down Expand Up @@ -372,11 +372,11 @@ export abstract class ContextCore {

private static resolveWeb3Providers(
endpoints: string | JsonRpcProvider | (string | JsonRpcProvider)[],
network: Network,
network: Network
): JsonRpcProvider[] {
if (Array.isArray(endpoints)) {
return endpoints.map((item) => {
if (typeof item === "string") {
if (typeof item === 'string') {
const url = new URL(item);
if (!supportedProtocols.includes(url.protocol)) {
throw new UnsupportedProtocolError(url.protocol);
Expand All @@ -385,7 +385,7 @@ export abstract class ContextCore {
}
return item;
});
} else if (typeof endpoints === "string") {
} else if (typeof endpoints === 'string') {
const url = new URL(endpoints);
if (!supportedProtocols.includes(url.protocol)) {
throw new UnsupportedProtocolError(url.protocol);
Expand All @@ -400,7 +400,7 @@ export abstract class ContextCore {
configs: {
url: string;
headers?: Record<string, string>;
}[],
}[]
): IpfsClient[] {
const clients: IpfsClient[] = [];
configs.forEach((config) => {
Expand All @@ -426,7 +426,7 @@ export abstract class ContextCore {
}

private static resolveGasFeeEstimationFactor(
gasFeeEstimationFactor: number,
gasFeeEstimationFactor: number
): number {
if (gasFeeEstimationFactor < 0 || gasFeeEstimationFactor > 1) {
throw new InvalidGasEstimationFactorError();
Expand Down
24 changes: 12 additions & 12 deletions js-client/src/multiuri.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IPFS_CID_REGEX } from "./constants";
import { EmptyMultiUriError } from "./errors";
import { IPFS_CID_REGEX } from './constants';
import { EmptyMultiUriError } from './errors';

/**
* Parses a multi URI and returns the IPFS or HTTP URI.
Expand All @@ -12,16 +12,16 @@ export class MultiUri {

constructor(multiUri: string) {
if (!multiUri) throw new EmptyMultiUriError();
this.items = multiUri.split(",");
this.items = multiUri.split(',');
}

get ipfsCid() {
for (let item of this.items) {
if (IPFS_CID_REGEX.test(item)) return item;
else if (item.startsWith("ipfs://")) {
else if (item.startsWith('ipfs://')) {
item = item.substring(7);
}
const idx = item.indexOf("/");
const idx = item.indexOf('/');
const cid = idx < 0 ? item : item.substring(0, idx);

if (!IPFS_CID_REGEX.test(cid)) continue;
Expand All @@ -31,22 +31,22 @@ export class MultiUri {
}
get ipfs() {
for (let item of this.items) {
if (IPFS_CID_REGEX.test(item)) return { cid: item, path: "" };
else if (item.startsWith("ipfs://")) {
if (IPFS_CID_REGEX.test(item)) return { cid: item, path: '' };
else if (item.startsWith('ipfs://')) {
item = item.substring(7);
}
const pathIdx = item.indexOf("/");
const pathIdx = item.indexOf('/');

let cid = item;
if (pathIdx < 0) {
if (!IPFS_CID_REGEX.test(cid)) continue;
return { cid, path: "" };
return { cid, path: '' };
}
cid = item.substring(0, pathIdx);
if (!IPFS_CID_REGEX.test(cid)) continue;

let searchIdx = item.indexOf("?");
if (searchIdx < 0) searchIdx = item.indexOf("#");
let searchIdx = item.indexOf('?');
if (searchIdx < 0) searchIdx = item.indexOf('#');

if (searchIdx < 0) {
return {
Expand All @@ -64,7 +64,7 @@ export class MultiUri {
}
get http() {
return this.items.filter(
(item) => item.startsWith("http://") || item.startsWith("https://"),
(item) => item.startsWith('http://') || item.startsWith('https://')
);
}
}
Loading

0 comments on commit 9a9ffe2

Please sign in to comment.