Skip to content

Commit

Permalink
chore: TS check (#7851)
Browse files Browse the repository at this point in the history
<!--
Before opening a pull request, please read the [contributing
guidelines](https://github.com/pancakeswap/pancake-frontend/blob/develop/CONTRIBUTING.md)
first
-->

<!--
copilot:all
-->
### <samp>🤖 Generated by Copilot at 42803aa</samp>

### Summary
🚧🔧🐛

<!--
1. 🚧 - This emoji represents the addition of a new workflow file that
checks for Typescript errors, which is a work in progress or maintenance
task.
2. 🔧 - This emoji represents the addition of a new configuration file
that enables strict null checks, which is a tooling or configuration
change.
3. 🐛 - This emoji represents the potential fixing of bugs or errors that
might be revealed by the Typescript check, which is a bug fix or
improvement.
-->
This pull request adds a new workflow to check for Typescript errors in
pull requests using strict null checks. It also adds a new
`tsconfig.check.json` file to configure the Typescript check.

> _`tsCheck.yml` runs_
> _on pull requests, finds errors_
> _with strict null checks_

### Walkthrough
* Add a workflow to check for Typescript errors in pull requests
([link](https://github.com/pancakeswap/pancake-frontend/pull/7851/files?diff=unified&w=0#diff-a347e684ced3a07c48e7e03c55692f1bd69af4c094a7fb599b9a1f8d41a37bb7R1-R56))
* Add a file to enable strict null checks for the Typescript check
([link](https://github.com/pancakeswap/pancake-frontend/pull/7851/files?diff=unified&w=0#diff-059feef48863d175ba6adf7839dd3da4ddb9d7de4a7b0d285bca7b3ee904e4c3R1-R6))
  • Loading branch information
chefjackson authored Sep 15, 2023
1 parent 92f9b2b commit d25b6ae
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lintPrTitle.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Lint PR Title'
name: Lint PR Title

on:
pull_request_target:
Expand Down
78 changes: 78 additions & 0 deletions .github/workflows/tsCheck.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]

- 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/[email protected]
with:
include: '["\\.ts$"]'

- name: Detecting files changed
id: files
uses: umani/[email protected]
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/[email protected]
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
10 changes: 0 additions & 10 deletions .lintstaged.eslintrc

This file was deleted.

2 changes: 1 addition & 1 deletion .lintstagedrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"**/*.{js,jsx,ts,tsx}": [
"eslint -c .lintstaged.eslintrc",
"eslint",
"prettier --write"
],
"**/*.json": [
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/__tests__/translations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(whitelist)

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/AccessRisk/AccessRiskTooltips.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const AccessRiskTooltips: React.FC<AccessRiskTooltipsProps> = ({
)
}

if (hasResult && riskLevel >= TOKEN_RISK.VERY_LOW && tokenAddress) {
if (hasResult && riskLevel && riskLevel >= TOKEN_RISK.VERY_LOW && tokenAddress) {
return (
<>
<Text my="8px">{riskLevelDescription}</Text>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/AddToWallet/AddToWalletButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface AddToWalletButtonProps {
tokenAddress: string
tokenSymbol: string
tokenDecimals: number
tokenLogo: string
tokenLogo?: string
textOptions?: AddToWalletTextOptions
marginTextBetweenLogo?: string
}
Expand Down
8 changes: 4 additions & 4 deletions apps/web/src/components/CurrencyInputPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<SwapUI.CurrencyInputPanel
id={id}
Expand Down Expand Up @@ -233,15 +233,15 @@ const CurrencyInputPanel = memo(function CurrencyInputPanel({
</Flex>
{account && !hideBalanceComp && (
<Text
onClick={!disabled && onMax}
onClick={!disabled ? onMax : undefined}
color="textSubtle"
fontSize="12px"
ellipsis
title={!hideBalance && !!currency ? t('Balance: %balance%', { balance: balance ?? t('Loading') }) : ' -'}
style={{ display: 'inline', cursor: 'pointer' }}
>
{!hideBalance && !!currency
? balance?.replace('.', '')?.length > 12
? (balance?.replace('.', '')?.length || 0) > 12
? balance
: t('Balance: %balance%', { balance: balance ?? t('Loading') })
: ' -'}
Expand All @@ -258,7 +258,7 @@ const CurrencyInputPanel = memo(function CurrencyInputPanel({
<Loading width="14px" height="14px" />
) : showUSDPrice && Number.isFinite(amountInDollar) ? (
<Text fontSize="12px" color="textSubtle" ellipsis>
{`~${formatNumber(amountInDollar)} USD`}
{`~${amountInDollar ? formatNumber(amountInDollar) : 0} USD`}
</Text>
) : (
<Box height="18px" />
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/SearchModal/CurrencySearchModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -81,7 +81,7 @@ export default function CurrencySearchModal({
const handleCurrencySelect = useCallback(
(currency: Currency) => {
onDismiss?.()
onCurrencySelect(currency)
onCurrencySelect?.(currency)
},
[onDismiss, onCurrencySelect],
)
Expand Down
21 changes: 11 additions & 10 deletions apps/web/src/hooks/useBUSDPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -21,16 +22,16 @@ const DEFAULT_CONFIG: UseStablecoinPriceConfig = {
}

export function useStablecoinPrice(
currency?: Currency,
currency?: Currency | null,
config: UseStablecoinPriceConfig = DEFAULT_CONFIG,
): Price<Currency, Currency> | undefined {
const { chainId: currentChainId } = useActiveChainId()
const chainId = currency?.chainId
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)

Expand Down Expand Up @@ -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',
})
Expand Down Expand Up @@ -102,11 +103,11 @@ export function useStablecoinPrice(
}

if (trade) {
const { inputAmount, outputAmount } = trade
const { inputAmount, outputAmount } = trade as unknown as SmartRouterTrade<TradeType>

// if price impact is too high, don't show price
if (hideIfPriceImpactTooHigh) {
const { priceImpactWithoutFee } = computeTradePriceBreakdown(trade)
const { priceImpactWithoutFee } = computeTradePriceBreakdown(trade as unknown as SmartRouterTrade<TradeType>)

if (!priceImpactWithoutFee || warningSeverity(priceImpactWithoutFee) > 2) {
return undefined
Expand Down Expand Up @@ -141,8 +142,8 @@ export function useStablecoinPrice(
export default function useBUSDPrice(currency?: Currency): Price<Currency, Currency> | 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(
() => [
Expand Down Expand Up @@ -228,7 +229,7 @@ export default function useBUSDPrice(currency?: Currency): Price<Currency, Curre
}

export const useStablecoinPriceAmount = (
currency?: Currency,
currency?: Currency | null,
amount?: number,
config?: UseStablecoinPriceConfig,
): number | undefined => {
Expand Down
5 changes: 0 additions & 5 deletions tsconfig.strictNullChecks.json

This file was deleted.

0 comments on commit d25b6ae

Please sign in to comment.