diff --git a/babel.config.js b/babel.config.js new file mode 100644 index 000000000..f0db10d56 --- /dev/null +++ b/babel.config.js @@ -0,0 +1,32 @@ +const isDevelopment = + process.env.NODE_ENV === 'test' || // jest + process.env.NODE_ENV === 'development' // cosmos + +module.exports = { + compact: false, + presets: [ + '@babel/preset-env', + [ + '@babel/preset-react', + { + development: isDevelopment, + // Ship with 'classic' runtime for compatibility with React >=17, otherwise ESM module resolution differs + // between versions (see https://github.com/facebook/react/issues/20235); develop with 'automatic' runtime for + // ease of development, so that React does not need to be top-level imported everywhere. + runtime: isDevelopment ? 'automatic' : 'classic', + }, + ], + ['@babel/preset-typescript', { isTSX: true, allExtensions: true }], + ], + plugins: [ + '@babel/plugin-transform-runtime', + 'macros', + [ + 'module-resolver', + { + root: ['src'], + extensions: ['.js', '.jsx', '.ts', '.tsx'], + }, + ], + ], +} diff --git a/babel.config.json b/babel.config.json deleted file mode 100644 index ca5dae272..000000000 --- a/babel.config.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "compact": false, - "presets": [ - "@babel/preset-env", - ["@babel/preset-react", { "runtime": "automatic" }], - ["@babel/preset-typescript", { "isTSX": true, "allExtensions": true }] - ], - "plugins": [ - "@babel/plugin-transform-runtime", - "macros", - [ - "module-resolver", - { - "root": ["src"], - "extensions": [".js", ".jsx", ".ts", ".tsx"] - } - ] - ] -} diff --git a/package.json b/package.json index 86b918e46..d55891d41 100644 --- a/package.json +++ b/package.json @@ -98,9 +98,9 @@ }, "peerDependencies": { "@babel/runtime": "^7.17.0", - "react": "^17.0.1", - "react-dom": "^17.0.1", - "react-redux": "^7.2.2", + "react": ">=17.0.1", + "react-dom": ">=17.0.1", + "react-redux": ">=7.2.2", "redux": "^4.1.2" }, "optionalDependencies": { @@ -120,9 +120,9 @@ "@nomiclabs/hardhat-ethers": "^2.0.6", "@rollup/plugin-babel": "^5.3.0", "@rollup/plugin-commonjs": "^21.0.1", + "@rollup/plugin-inject": "^4.0.4", "@rollup/plugin-json": "^4.1.0", "@rollup/plugin-node-resolve": "^13.1.3", - "@rollup/plugin-replace": "^3.0.1", "@rollup/plugin-url": "^6.1.0", "@semantic-release/changelog": "^6.0.1", "@semantic-release/git": "^10.0.1", diff --git a/rollup.config.js b/rollup.config.js index ed6202a07..2c209c263 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -6,9 +6,9 @@ /* eslint-disable @typescript-eslint/no-var-requires */ const { babel } = require('@rollup/plugin-babel') const commonjs = require('@rollup/plugin-commonjs') +const inject = require('@rollup/plugin-inject') const json = require('@rollup/plugin-json') const { nodeResolve: resolve } = require('@rollup/plugin-node-resolve') -const replace = require('@rollup/plugin-replace') const { default: dts } = require('rollup-plugin-dts') const url = require('@rollup/plugin-url') const svgr = require('@svgr/rollup') @@ -35,7 +35,10 @@ const EXTENSIONS = ['.js', '.jsx', '.ts', '.tsx'] */ const transpile = { input: 'src/index.tsx', - external: isEthers, + external: (source) => { + // @ethersproject/* modules are provided by ethers + return source.startsWith('@ethersproject/') + }, plugins: [ // Dependency resolution externals({ @@ -50,14 +53,9 @@ const transpile = { resolve({ extensions: EXTENSIONS }), // resolves third-party modules within node_modules/ // Source code transformation - replace({ - // esm requires fully-specified paths: - 'react/jsx-runtime': 'react/jsx-runtime.js', - preventAssignment: true, - }), json(), // imports json as ES6; doing so enables module resolution url({ include: ['**/*.png', '**/*.svg'], limit: Infinity }), // imports assets as data URIs - svgr(), // imports svgs as React components + svgr({ jsxRuntime: 'automatic' }), // imports svgs as React components (without re-importing React) sass({ output: 'dist/fonts.css', verbose: false }), // generates fonts.css commonjs(), // transforms cjs dependencies into tree-shakeable ES modules @@ -65,8 +63,15 @@ const transpile = { babelHelpers: 'runtime', extensions: EXTENSIONS, }), + inject({ React: 'react' }), // imports React (on the top-level, un-renamed), for the classic runtime ], - onwarn: squelchTypeWarnings, // this pipeline is only for transpilation + onwarn: (warning, warn) => { + // This pipeline is for transpilation - checking is done through tsc. + if (warning.code === 'UNUSED_EXTERNAL_IMPORT') return + + warn(warning) + console.log(warning.loc, '\n') + }, } const esm = { @@ -130,13 +135,3 @@ const config = [esm, cjs, types, locales] config.config = { ...esm, output: { ...esm.output, sourcemap: true } } config.assets = assets module.exports = config - -function isEthers(source) { - // @ethersproject/* modules are provided by ethers - return source.startsWith('@ethersproject/') -} - -function squelchTypeWarnings(warning, warn) { - if (warning.code === 'UNUSED_EXTERNAL_IMPORT') return - warn(warning) -} diff --git a/src/components/Swap/Settings/MaxSlippageSelect.tsx b/src/components/Swap/Settings/MaxSlippageSelect.tsx index 68401faa1..1037d5e07 100644 --- a/src/components/Swap/Settings/MaxSlippageSelect.tsx +++ b/src/components/Swap/Settings/MaxSlippageSelect.tsx @@ -15,14 +15,6 @@ import { DecimalInput, inputCss } from '../../Input' import Row from '../../Row' import { Label, optionCss } from './components' -const tooltip = ( - Your transaction will revert if the price changes unfavorably by more than this percentage. -) -const highSlippage = High slippage increases the risk of price movement -const invalidSlippage = Please enter a valid slippage % - -const placeholder = '0.10' - const Button = styled(TextButton)<{ selected: boolean }>` ${({ selected }) => optionCss(selected)} ` @@ -63,12 +55,12 @@ const Warning = memo(function Warning({ state, showTooltip }: { state?: 'warning switch (state) { case 'error': icon = XOctagon - content = invalidSlippage + content = Please enter a valid slippage % show = true break case 'warning': icon = AlertTriangle - content = highSlippage + content = High slippage increases the risk of price movement break } return ( @@ -120,7 +112,12 @@ export default function MaxSlippageSelect() { return ( -