Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
dist
coverage
*.test.ts

73 changes: 73 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "jest"],
"overrides": [
{
"files": ["*.ts"],
"extends": ["@metamask/eslint-config-typescript"]
},
{
"files": ["*.d.ts"],
"parserOptions": {
"sourceType": "script"
}
},
{
"files": ["*.js"],
"parserOptions": {
"sourceType": "script"
},
"extends": ["@metamask/eslint-config-nodejs"]
},
{
"files": ["*.test.ts", "*.test.js"],
"extends": ["@metamask/eslint-config-jest"]
},
{
"files": ["src/SwapsController.ts"],
"rules": {
"accessor-pairs": "off",
"consistent-return": "off",
"no-async-promise-executor": "off",
"@typescript-eslint/prefer-optional-chain": "off",
"no-restricted-syntax": "off",
"import/no-named-as-default": "off",
}
},
{
"files": ["src/SwapsController.test.ts"],
"rules": {
"no-new": "off"
}
},
{
"files": ["src/swapsInterfaces.ts"],
"rules": {
"@typescript-eslint/naming-convention": "off"
}
},
{
"files": ["src/swapsUtil.ts"],
"rules": {
"consistent-return": "off",
"no-negated-condition": "off",
"@typescript-eslint/naming-convention": "off"
}
},
{
"files": ["src/swapsUtil.test.ts"],
"rules": {
"jest/require-to-throw-message": "off",
"@typescript-eslint/naming-convention": "off",
"no-restricted-globals": "off"
}
}
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:jest/recommended",
"@metamask/eslint-config"
]
}
78 changes: 0 additions & 78 deletions .eslintrc.js

This file was deleted.

6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"quoteProps": "as-needed",
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all"
}
8 changes: 0 additions & 8 deletions .prettierrc.js

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"abort-controller": "^3.0.0",
"async-mutex": "^0.4.1",
"bignumber.js": "^9.0.1",
"bn.js": "^5.2.1",
"human-standard-token-abi": "^2.0.0",
"web3": "^4.2.2"
},
Expand Down
5 changes: 4 additions & 1 deletion src/SwapsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type { Hex } from '@metamask/utils';
import { Mutex } from 'async-mutex';
import { BigNumber } from 'bignumber.js';
import abiERC20 from 'human-standard-token-abi';
import { Web3 } from 'web3';
import * as web3 from 'web3';

import type {
APIAggregatorMetadata,
Expand Down Expand Up @@ -58,6 +58,9 @@ import {
shouldEnableDirectWrapping,
} from './swapsUtil';

// hack to fix web3 import issue after transpiling
const Web3 = web3.Web3 === undefined ? web3.default : web3.Web3;

// Functions to determine type of the return value from GasFeeController

/**
Expand Down
5 changes: 3 additions & 2 deletions src/swapsUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { Transaction } from '@metamask/transaction-controller';
import type { Hex } from '@metamask/utils';
import { add0x } from '@metamask/utils';
import { BigNumber } from 'bignumber.js';
import { BN } from 'bn.js';

import {
ALLOWED_CONTRACT_ADDRESSES,
Expand Down Expand Up @@ -283,8 +284,8 @@ export async function fetchTradesInfo(
to: quote.trade.to,
from: quote.trade.from,
data: quote.trade.data,
amount: BNToHex(new BigNumber(quote.trade.value)),
gas: BNToHex(quote.maxGas || new BigNumber(MAX_GAS_LIMIT)),
amount: BNToHex(new BN(quote.trade.value)),
gas: BNToHex(new BN(quote.maxGas) || new BN(MAX_GAS_LIMIT)),
});

return {
Expand Down
9 changes: 5 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
{
"compilerOptions": {
"allowJs": true,
"declaration": true,
"declarationDir": "dist",
"inlineSources": true,
"esModuleInterop": true,
"lib": ["DOM", "ES2020"],
"forceConsistentCasingInFileNames": true,
"module": "CommonJS",
"moduleResolution": "Node",
"noUnusedLocals": true,
"noUnusedParameters": true,
"outDir": "dist",
"rootDir": "./src",
"sourceMap": true,
"strict": true,
"target": "ES2017"
"target": "ES2020"
},
"include": ["src/**/*.ts", "src/**/*.test.ts"]
"include": ["src/**/*.ts"],
"exclude": ["src/**/*.test.ts", "node_modules"]
}
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2330,9 +2330,9 @@ ecc-jsbn@~0.1.1:
safer-buffer "^2.1.0"

electron-to-chromium@^1.4.668:
version "1.4.737"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.737.tgz#3a774a58e04980741f65d440f5fdf57af18b6dde"
integrity sha512-QvLTxaLHKdy5YxvixAw/FfHq2eWLUL9KvsPjp0aHK1gI5d3EDuDgITkvj0nFO2c6zUY3ZqVAJQiBYyQP9tQpfw==
version "1.4.738"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.738.tgz#9a7fca98abaee61e20c9c25013d5ce60bb533436"
integrity sha512-lwKft2CLFztD+vEIpesrOtCrko/TFnEJlHFdRhazU7Y/jx5qc4cqsocfVrBg4So4gGe9lvxnbLIoev47WMpg+A==

elliptic@^6.5.2, elliptic@^6.5.4:
version "6.5.5"
Expand Down Expand Up @@ -5402,9 +5402,9 @@ proc-log@^3.0.0:
integrity sha512-++Vn7NS4Xf9NacaU9Xq3URUuqZETPsf8L4j5/ckhaRYsfPeRyzGw+iDjFhV/Jr3uNmTvvddEJFWh5R1gRgUH8A==

proc-log@^4.0.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/proc-log/-/proc-log-4.1.0.tgz#ab6c1552b454e9e467cb58119179e4557d109b34"
integrity sha512-dmQ2iPw2nJMi9/4dpaG1wd0m1GE+K5kW7RGbjy5hoEEGnhPIzsm+klBO5RGGdcoYbWsNtU2KSNAdEldts+icLg==
version "4.2.0"
resolved "https://registry.yarnpkg.com/proc-log/-/proc-log-4.2.0.tgz#b6f461e4026e75fdfe228b265e9f7a00779d7034"
integrity sha512-g8+OnU/L2v+wyiVK+D5fA34J7EH8jZ8DDlvwhRCMxmMj7UCBvxiO1mGeN+36JXIKF4zevU4kRBd8lVgG9vLelA==

process-nextick-args@~2.0.0:
version "2.0.1"
Expand Down