Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon committed Aug 1, 2022
1 parent 3d78c72 commit b2f7fe9
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 212 deletions.
59 changes: 55 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,18 +1,69 @@
{
"env": {
"commonjs": true
"es2020": true,
"node": true,
"webextensions": true,
"worker": true,
"serviceworker": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"sourceType": "module"
},
"plugins": [
"@typescript-eslint",
"prettier"
],
"ignorePatterns": [
"dist/*"
],
"rules": {
"no-constant-condition": "off",
"no-var": "error",
"semi": "error",
"indent": "error",
"no-multi-spaces": "error",
"space-in-parens": "error",
"no-multiple-empty-lines": "error",
"prefer-const": "error",
"no-use-before-define": "error"
"prefer-const": [
"error",
{
"destructuring": "all",
"ignoreReadBeforeAssign": false
}
],
"camelcase": "error",
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"caughtErrorsIgnorePattern": "^_"
}
],
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-this-alias": [
"error",
{
"allowedNames": [
"self"
]
}
]
}
}
16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@
"scripts": {
"build": "tsc",
"build:docs": "typedoc",
"lint": "eslint"
"lint": "npx eslint ."
},
"author": "",
"license": "GPL-3.0",
"engines": {
"node": ">=14"
},
"type": "module",
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.24.0",
"eslint": "^7.26.0",
"eslint-config-prettier": "^8.3.0",
"typedoc": "^0.23.9",
"@typescript-eslint/eslint-plugin": "^5.31.0",
"@typescript-eslint/parser": "^5.31.0",
"eslint": "^8.21.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"typedoc": "^0.23.10",
"typedoc-plugin-missing-exports": "^0.23.0",
"typescript": "^4.2.4"
},
Expand Down
14 changes: 6 additions & 8 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export type ProviderEvents<Addr = Address> = {
/**
* Called when inpage provider connects to the extension
*/
connected: {};
connected: Record<string, never>;

/**
* Called when inpage provider disconnects from extension
Expand Down Expand Up @@ -111,7 +111,7 @@ export type ProviderEvents<Addr = Address> = {
/**
* Called when the user logs out of the extension
*/
loggedOut: {};
loggedOut: Record<string, never>;
}

/**
Expand Down Expand Up @@ -149,7 +149,7 @@ export type ProviderApi<Addr = Address> = {
* ---
* Required permissions: none
*/
disconnect: {};
disconnect: Record<string, never>;

/**
* Subscribes to contract updates.
Expand Down Expand Up @@ -193,7 +193,7 @@ export type ProviderApi<Addr = Address> = {
* ---
* Required permissions: none
*/
unsubscribeAll: {};
unsubscribeAll: Record<string, never>;

/**
* Returns provider api state
Expand Down Expand Up @@ -1320,8 +1320,7 @@ export type ProviderMethod = keyof ProviderApi;
* @category Provider Api
*/
export type ProviderApiRequestParams<T extends ProviderMethod, Addr = Address> =
ProviderApi<Addr>[T] extends { input: infer I } ? I
: ProviderApi<Addr>[T] extends {} ? undefined : never;
ProviderApi<Addr>[T] extends { input: infer I } ? I : undefined;

/**
* @category Provider Api
Expand All @@ -1332,8 +1331,7 @@ export type RawProviderApiRequestParams<T extends ProviderMethod> = ProviderApiR
* @category Provider Api
*/
export type ProviderApiResponse<T extends ProviderMethod, Addr = Address> =
ProviderApi<Addr>[T] extends { output: infer O } ? O
: ProviderApi<Addr>[T] extends {} ? undefined : never;
ProviderApi<Addr>[T] extends { output: infer O } ? O : undefined;

/**
* @category Provider Api
Expand Down
28 changes: 14 additions & 14 deletions src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class Contract<Abi> {

try {
// Parent transaction from wallet
let parentTransaction: { transaction: Transaction, possibleMessages: Message[] } | undefined;
let parentTransaction: { transaction: Transaction, possibleMessages: Message[] } | undefined = undefined;

// Child transaction promise
let resolveChildTransactionPromise: ((transaction: Transaction) => void) | undefined;
Expand Down Expand Up @@ -188,11 +188,11 @@ export class Contract<Abi> {

async sendExternal(args: SendExternalParams): Promise<{ transaction: Transaction, output?: any }> {
await this.provider.ensureInitialized();
let method = args.withoutSignature === true
const method = args.withoutSignature === true
? this.provider.rawApi.sendUnsignedExternalMessage
: this.provider.rawApi.sendExternalMessage;

let { transaction, output } = await method({
const { transaction, output } = await method({
publicKey: args.publicKey,
recipient: this.address.toString(),
stateInit: args.stateInit,
Expand All @@ -212,7 +212,7 @@ export class Contract<Abi> {

async call(args: CallParams = {}): Promise<any> {
await this.provider.ensureInitialized();
let { output, code } = await this.provider.rawApi.runLocal({
const { output, code } = await this.provider.rawApi.runLocal({
address: this.address.toString(),
cachedState: args.cachedState,
responsible: args.responsible,
Expand All @@ -232,7 +232,7 @@ export class Contract<Abi> {

async encodeInternal(): Promise<string> {
await this.provider.ensureInitialized();
let { boc } = await this.provider.rawApi.encodeInternalInput({
const { boc } = await this.provider.rawApi.encodeInternalInput({
abi: this.abi,
method: this.method,
params: this.params,
Expand All @@ -242,20 +242,20 @@ export class Contract<Abi> {
}

this._methods = new Proxy({}, {
get: <K extends AbiFunctionName<Abi>>(_object: {}, method: K) => {
const rawAbi = (this._functions as any)[method];
get: <K extends AbiFunctionName<Abi>>(_object: Record<string, unknown>, method: K) => {
const rawAbi = this._functions[method];
return (params: AbiFunctionInputs<Abi, K>) => new ContractMethodImpl(
this._provider, rawAbi, this._abi, this._address, method, params,
);
},
}) as unknown as ContractMethods<Abi>;
}

public get methods() {
public get methods(): ContractMethods<Abi> {
return this._methods;
}

public get address() {
public get address(): Address {
return this._address;
}

Expand Down Expand Up @@ -306,7 +306,7 @@ export class Contract<Abi> {
public async getPastEvents(args: GetPastEventParams<Abi>): Promise<EventsBatch<Abi>> {
const { range, filter, limit } = args;

let result: DecodedEventWithTransaction<Abi, AbiEventName<Abi>>[] = [];
const result: DecodedEventWithTransaction<Abi, AbiEventName<Abi>>[] = [];
let currentContinuation = args?.continuation;

outer: while (true) {
Expand Down Expand Up @@ -383,7 +383,7 @@ export class Contract<Abi> {
return undefined;
}

let { method, input, output } = result;
const { method, input, output } = result;

const rawAbi = this._functions[method];

Expand Down Expand Up @@ -435,7 +435,7 @@ export class Contract<Abi> {
return undefined;
}

let { method, input } = result;
const { method, input } = result;

const rawAbi = this._functions[method];

Expand All @@ -460,7 +460,7 @@ export class Contract<Abi> {
return undefined;
}

let { method, output } = result;
const { method, output } = result;

const rawAbi = this._functions[method];

Expand All @@ -485,7 +485,7 @@ export class Contract<Abi> {
return undefined;
}

let { event, data } = result;
const { event, data } = result;

const rawAbi = this._events[event];

Expand Down
Loading

0 comments on commit b2f7fe9

Please sign in to comment.