diff --git a/.github/workflows/lintPrTitle.yml b/.github/workflows/lintPrTitle.yml index 813caeb978baf..c87d2c1dc2aff 100644 --- a/.github/workflows/lintPrTitle.yml +++ b/.github/workflows/lintPrTitle.yml @@ -1,4 +1,4 @@ -name: 'Lint PR Title' +name: Lint PR Title on: pull_request_target: diff --git a/.github/workflows/tsCheck.yml b/.github/workflows/tsCheck.yml new file mode 100644 index 0000000000000..dc6093f438c84 --- /dev/null +++ b/.github/workflows/tsCheck.yml @@ -0,0 +1,78 @@ +name: Check TS Errors + +on: + pull_request: + +jobs: + ts-check: + name: Typescript Error Check + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Set up pnpm + uses: pnpm/action-setup@v2.2.4 + + - name: Set up node@18 + uses: actions/setup-node@v3 + with: + cache: 'pnpm' + node-version: 18 + + - name: Get pnpm store directory + id: pnpm-cache + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT + + - uses: actions/cache@v3 + name: Setup pnpm cache + with: + path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + + - name: Install dependencies + run: pnpm i --ignore-scripts + + - name: Build package + run: pnpm build:packages + + - name: Get diff lines + id: diff + uses: Equip-Collaboration/diff-line-numbers@v1.0.0 + with: + include: '["\\.ts$"]' + + - name: Detecting files changed + id: files + uses: umani/changed-files@v4.0.1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + pattern: '^.*\.ts$' + + - name: List files changed (you can remove this step, for monitoring only) + run: | + echo 'Changed: ${{ steps.files.outputs.changed }}' + echo 'Files modified: ${{steps.files.outputs.files_updated}}' + echo 'Files added: ${{steps.files.outputs.files_created}}' + echo 'Files removed: ${{steps.files.outputs.files_deleted}}' + + - name: Check typescript errors + uses: chefjackson/action-check-typescript@v1.0.6 + if: steps.files.outputs.changed == 'true' + env: + NODE_OPTIONS: '--max_old_space_size=4096' + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + use-check: true + check-fail-mode: errors_in_pr + files-changed: ${{steps.files.outputs.files_updated}} + files-added: ${{steps.files.outputs.files_created}} + files-deleted: ${{steps.files.outputs.files_deleted}} + line-numbers: ${{steps.diff.outputs.lineNumbers}} + output-behaviour: both + comment-behaviour: edit + ts-config-path: ./apps/web/tsconfig.check.json diff --git a/.lintstaged.eslintrc b/.lintstaged.eslintrc deleted file mode 100644 index 7346892acaa09..0000000000000 --- a/.lintstaged.eslintrc +++ /dev/null @@ -1,10 +0,0 @@ -{ - "parserOptions": { - "project": "./tsconfig.strictNullChecks.json" - }, - "plugins": ["strict-null-checks"], - "extends": ["./.eslintrc"], - "rules": { - "strict-null-checks/all": "error" - } -} diff --git a/.lintstagedrc b/.lintstagedrc index 7548b8f1871ca..f5a7026d94e91 100644 --- a/.lintstagedrc +++ b/.lintstagedrc @@ -1,6 +1,6 @@ { "**/*.{js,jsx,ts,tsx}": [ - "eslint -c .lintstaged.eslintrc", + "eslint", "prettier --write" ], "**/*.json": [ diff --git a/apps/web/src/__tests__/translations.test.ts b/apps/web/src/__tests__/translations.test.ts index a166136c9e15f..02c1b119eed09 100644 --- a/apps/web/src/__tests__/translations.test.ts +++ b/apps/web/src/__tests__/translations.test.ts @@ -88,7 +88,7 @@ describe('Check translations available', () => { throughDirectory('../../packages/uikit/src') throughDirectory('../../packages/ui-wallets/src') throughDirectory('../../packages/widgets-internal') - let match: RegExpExecArray | null = null + let match: RegExpExecArray | string | null = null const extractedKeys = new Set(whitelist) diff --git a/apps/web/src/components/AccessRisk/AccessRiskTooltips.tsx b/apps/web/src/components/AccessRisk/AccessRiskTooltips.tsx index f996d04d9a2d3..dbee163e06f9d 100644 --- a/apps/web/src/components/AccessRisk/AccessRiskTooltips.tsx +++ b/apps/web/src/components/AccessRisk/AccessRiskTooltips.tsx @@ -39,7 +39,7 @@ const AccessRiskTooltips: React.FC = ({ ) } - if (hasResult && riskLevel >= TOKEN_RISK.VERY_LOW && tokenAddress) { + if (hasResult && riskLevel && riskLevel >= TOKEN_RISK.VERY_LOW && tokenAddress) { return ( <> {riskLevelDescription} diff --git a/apps/web/src/components/AddToWallet/AddToWalletButton.tsx b/apps/web/src/components/AddToWallet/AddToWalletButton.tsx index c2620674428b0..e85c411633693 100644 --- a/apps/web/src/components/AddToWallet/AddToWalletButton.tsx +++ b/apps/web/src/components/AddToWallet/AddToWalletButton.tsx @@ -23,7 +23,7 @@ export interface AddToWalletButtonProps { tokenAddress: string tokenSymbol: string tokenDecimals: number - tokenLogo: string + tokenLogo?: string textOptions?: AddToWalletTextOptions marginTextBetweenLogo?: string } diff --git a/apps/web/src/components/CurrencyInputPanel/index.tsx b/apps/web/src/components/CurrencyInputPanel/index.tsx index aed081945fea7..abd1bf1efc409 100644 --- a/apps/web/src/components/CurrencyInputPanel/index.tsx +++ b/apps/web/src/components/CurrencyInputPanel/index.tsx @@ -161,7 +161,7 @@ const CurrencyInputPanel = memo(function CurrencyInputPanel({ const isAtPercentMax = (maxAmount && value === maxAmount.toExact()) || (lpPercent && lpPercent === '100') - const balance = !hideBalance && !!currency && formatAmount(selectedCurrencyBalance, 6) + const balance = !hideBalance && !!currency ? formatAmount(selectedCurrencyBalance, 6) : undefined return ( {account && !hideBalanceComp && ( {!hideBalance && !!currency - ? balance?.replace('.', '')?.length > 12 + ? (balance?.replace('.', '')?.length || 0) > 12 ? balance : t('Balance: %balance%', { balance: balance ?? t('Loading') }) : ' -'} @@ -258,7 +258,7 @@ const CurrencyInputPanel = memo(function CurrencyInputPanel({ ) : showUSDPrice && Number.isFinite(amountInDollar) ? ( - {`~${formatNumber(amountInDollar)} USD`} + {`~${amountInDollar ? formatNumber(amountInDollar) : 0} USD`} ) : ( diff --git a/apps/web/src/components/SearchModal/CurrencySearchModal.tsx b/apps/web/src/components/SearchModal/CurrencySearchModal.tsx index 57ad6d8fdea9b..e37bbdea976d9 100644 --- a/apps/web/src/components/SearchModal/CurrencySearchModal.tsx +++ b/apps/web/src/components/SearchModal/CurrencySearchModal.tsx @@ -54,7 +54,7 @@ const StyledModalBody = styled(ModalBody)` export interface CurrencySearchModalProps extends InjectedModalProps { selectedCurrency?: Currency | null - onCurrencySelect: (currency: Currency) => void + onCurrencySelect?: (currency: Currency) => void otherSelectedCurrency?: Currency | null showCommonBases?: boolean commonBasesType?: string @@ -81,7 +81,7 @@ export default function CurrencySearchModal({ const handleCurrencySelect = useCallback( (currency: Currency) => { onDismiss?.() - onCurrencySelect(currency) + onCurrencySelect?.(currency) }, [onDismiss, onCurrencySelect], ) diff --git a/apps/web/src/hooks/useBUSDPrice.ts b/apps/web/src/hooks/useBUSDPrice.ts index ecde263370c73..acc53da5a08cc 100644 --- a/apps/web/src/hooks/useBUSDPrice.ts +++ b/apps/web/src/hooks/useBUSDPrice.ts @@ -5,6 +5,7 @@ import useSWRImmutable from 'swr/immutable' import { multiplyPriceByAmount } from 'utils/prices' import { useCakePrice } from 'hooks/useCakePrice' import { getFullDecimalMultiplier } from '@pancakeswap/utils/getFullDecimalMultiplier' +import { SmartRouterTrade } from '@pancakeswap/smart-router/evm' import { computeTradePriceBreakdown } from 'views/Swap/V3Swap/utils/exchange' import { warningSeverity } from 'utils/exchange' import { PairState, useV2Pairs } from './usePairs' @@ -21,7 +22,7 @@ const DEFAULT_CONFIG: UseStablecoinPriceConfig = { } export function useStablecoinPrice( - currency?: Currency, + currency?: Currency | null, config: UseStablecoinPriceConfig = DEFAULT_CONFIG, ): Price | undefined { const { chainId: currentChainId } = useActiveChainId() @@ -29,8 +30,8 @@ export function useStablecoinPrice( const { enabled, hideIfPriceImpactTooHigh } = { ...DEFAULT_CONFIG, ...config } const cakePrice = useCakePrice() - const stableCoin = chainId in ChainId ? STABLE_COIN[chainId as ChainId] : undefined - const isCake = currency && CAKE[chainId] && currency.wrapped.equals(CAKE[chainId]) + const stableCoin = chainId && chainId in ChainId ? STABLE_COIN[chainId as ChainId] : undefined + const isCake = chainId && currency && CAKE[chainId] && currency.wrapped.equals(CAKE[chainId]) const isStableCoin = currency && stableCoin && currency.wrapped.equals(stableCoin) @@ -62,11 +63,11 @@ export function useStablecoinPrice( const { trade } = useBestAMMTrade({ amount: amountOut, - currency, + currency: currency ?? undefined, baseCurrency: stableCoin, tradeType: TradeType.EXACT_OUTPUT, maxSplits: 0, - enabled: enableLlama ? !isLoading && !priceFromLlama : shouldEnabled, + enabled: Boolean(enableLlama ? !isLoading && !priceFromLlama : shouldEnabled), autoRevalidate: false, type: 'api', }) @@ -102,11 +103,11 @@ export function useStablecoinPrice( } if (trade) { - const { inputAmount, outputAmount } = trade + const { inputAmount, outputAmount } = trade as unknown as SmartRouterTrade // if price impact is too high, don't show price if (hideIfPriceImpactTooHigh) { - const { priceImpactWithoutFee } = computeTradePriceBreakdown(trade) + const { priceImpactWithoutFee } = computeTradePriceBreakdown(trade as unknown as SmartRouterTrade) if (!priceImpactWithoutFee || warningSeverity(priceImpactWithoutFee) > 2) { return undefined @@ -141,8 +142,8 @@ export function useStablecoinPrice( export default function useBUSDPrice(currency?: Currency): Price | undefined { const { chainId } = useActiveChainId() const wrapped = currency?.wrapped - const wnative = WNATIVE[chainId] - const stable = BUSD[chainId] || USDC[chainId] + const wnative = chainId ? WNATIVE[chainId] : undefined + const stable = chainId ? BUSD[chainId] || USDC[chainId] : undefined const tokenPairs: [Currency | undefined, Currency | undefined][] = useMemo( () => [ @@ -228,7 +229,7 @@ export default function useBUSDPrice(currency?: Currency): Price { diff --git a/tsconfig.strictNullChecks.json b/tsconfig.strictNullChecks.json deleted file mode 100644 index 9647394afeb20..0000000000000 --- a/tsconfig.strictNullChecks.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "compilerOptions": { - "strictNullChecks": true - } -}