Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
moshmage committed Aug 1, 2024
1 parent b1fedea commit f1b90bc
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 15 deletions.
8 changes: 5 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"parser": "@typescript-eslint/parser",
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"rules": {

"indent-legacy": ["error", 2, {
"FunctionDeclaration": {
"parameters": "first"
Expand All @@ -18,7 +17,9 @@
"camelcase": 0,
"no-underscore-dangle": 0,
"class-methods-use-this": 1,
"no-unused-vars": 1,
"no-unused-vars": 0,
"@typescript-eslint/no-unused-vars": ["warn", { "varsIgnorePattern": "^_" }],
"@typescript-eslint/no-non-null-assertion": 0,
"complexity": ["error", 4],
"max-len": [
"error",
Expand All @@ -37,7 +38,8 @@
"function-call-argument-newline": [
"error",
"consistent"
]
],
"@typescript-eslint/no-explicit-any": 0
},
"env": {
"browser": true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"test": "npm run mocha-mug -- 'test/**/*.spec.{ts,tsx}' --pretty",
"test-ci": "npm run hardhat:start >/dev/null & npm run test",
"eslint": "eslint --ignore-path .eslintignore --ext .ts ./src",
"lint": "npm run eslint -- --quiet",
"lint": "npm run eslint",
"lint-fix": "npm run eslint -- --quiet --fix",
"dk-transpile": "dlt -j dk-config.json"
},
Expand Down
5 changes: 3 additions & 2 deletions src/base/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class Model<Abi extends ContractAbi> {
auto: true,
debug: this.web3Connection.options.debug,
...contractOptions,
} as any;
} as never;

if (this.web3Connection.started)
this.loadAbi(); // no need to call .start() be cause .start calls web3connection.start first
Expand Down Expand Up @@ -110,6 +110,7 @@ export class Model<Abi extends ContractAbi> {
* Return a property value from the contract
* @see <method.call()>
*/
// eslint-disable-next-line class-methods-use-this
async callTx<ForceOutput>(method: PayableMethodObject|NonPayableMethodObject) {
return method.call<ForceOutput>();
}
Expand All @@ -118,7 +119,7 @@ export class Model<Abi extends ContractAbi> {
* Interact with, or change a value of, a property on the contract
*/
async sendTx<Outputs = unknown>(method: PayableMethodObject|NonPayableMethodObject,
value?: any): Promise<TransactionReceipt<Outputs>> {
value?: never): Promise<TransactionReceipt<Outputs>> {
if (this.connection.Account)
return this.contract.sendSignedTx(this.connection.Account,
method.encodeABI(),
Expand Down
4 changes: 3 additions & 1 deletion src/base/web3-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export class Web3Connection {
this.options.restartModelOnDeploy = true;

const providerConnected = provider &&
typeof provider !== "string" && provider.hasOwnProperty('connected') && (provider as any).connected;
typeof provider !== "string"
&& provider.hasOwnProperty('connected')
&& (provider as unknown as {connected: boolean}).connected;

if (autoStart || providerConnected)
this.start();
Expand Down
6 changes: 3 additions & 3 deletions src/interfaces/web3-connection-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface Web3ConnectionOptions {
/**
* Pass a custom provider instead
*/
web3CustomProvider?: SupportedProviders<never>;
web3CustomProvider?: SupportedProviders;

/**
* Skip the assignment of `window.web3 = Web3`
Expand All @@ -41,13 +41,13 @@ export interface Web3ConnectionOptions {
debug?: boolean;



/* eslint-disable @typescript-eslint/no-unused-vars */
// eslint-disable-next-line max-len
customTransactionHandler?: <ResolveType = unknown, EventMap extends Web3EventMap = never>(event: Web3PromiEvent<ResolveType, EventMap>,
resolve: (data: never) => void,
reject: (e: unknown) => void,
debug?: boolean) => void;

/* eslint-enable @typescript-eslint/no-unused-vars */
/**
* If true, web3Connection will call `.start()` on construction
* @default true
Expand Down
2 changes: 1 addition & 1 deletion src/utils/models/transaction-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {TransactionReceipt} from "web3-types";
import {type Web3PromiEvent} from "web3-core";


type ResolveReject = (value?: any | unknown) => void;
type ResolveReject = (_value?: any | unknown) => void;

export function transactionHandler(transaction: Web3PromiEvent<TransactionReceipt, Record<string, unknown>>,
resolve: ResolveReject,
Expand Down
10 changes: 6 additions & 4 deletions src/utils/numbers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import BigNumber from 'bignumber.js';

const shiftByFixed = (value: string|number|BigNumber, shiftBy: number, rounding: number|null = null) =>
new BigNumber(value).shiftedBy(shiftBy).toFixed(rounding ? 0 : null as any, rounding as any)
const shiftByFixed = (value: string|number|BigNumber, shiftBy: number,
rounding: BigNumber.RoundingMode|undefined = undefined) =>
new BigNumber(value).shiftedBy(shiftBy).toFixed(rounding ? 0 : 5, rounding)

/**
* convert a simple number into a big number representation, usually used to convert
Expand All @@ -11,7 +12,8 @@ const shiftByFixed = (value: string|number|BigNumber, shiftBy: number, rounding:
* @param {number} rounding
* @return {string}
*/
export function toSmartContractDecimals(value: string|number, decimals = 18, rounding:number|null = null) {
export function toSmartContractDecimals(value: string|number, decimals = 18,
rounding:BigNumber.RoundingMode|undefined = undefined) {
return shiftByFixed(value, +decimals, rounding);
}

Expand All @@ -24,7 +26,7 @@ export function toSmartContractDecimals(value: string|number, decimals = 18, rou
*/
export function fromSmartContractDecimals(value: string | number | BigNumber | bigint,
decimals = 18,
rounding: number | null = null) {
rounding: BigNumber.RoundingMode|undefined = undefined) {
return shiftByFixed(value.toString(), -(+decimals), rounding);
}

Expand Down

0 comments on commit f1b90bc

Please sign in to comment.