Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use satisfies over assertUnreachable #7627

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 1 addition & 3 deletions packages/swapper/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { assertUnreachable } from '@shapeshiftoss/utils'

import { arbitrumBridgeSwapper } from './swappers/ArbitrumBridgeSwapper/ArbitrumBridgeSwapper'
import { arbitrumBridgeApi } from './swappers/ArbitrumBridgeSwapper/endpoints'
import { ARBITRUM_BRIDGE_SUPPORTED_CHAIN_IDS } from './swappers/ArbitrumBridgeSwapper/utils/constants'
Expand Down Expand Up @@ -116,6 +114,6 @@ export const getDefaultSlippageDecimalPercentageForSwapper = (
case SwapperName.ArbitrumBridge:
return DEFAULT_ARBITRUM_BRIDGE_SLIPPAGE_DECIMAL_PERCENTAGE
default:
assertUnreachable(swapperName)
return swapperName satisfies never
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { ChainId } from '@shapeshiftoss/caip'
import { ethAssetId, ethChainId, fromAssetId } from '@shapeshiftoss/caip'
import type { EvmChainAdapter, EvmChainId } from '@shapeshiftoss/chain-adapters'
import { type Asset, KnownChainIds } from '@shapeshiftoss/types'
import { assertUnreachable, bn } from '@shapeshiftoss/utils'
import { bn } from '@shapeshiftoss/utils'
import { getFees } from '@shapeshiftoss/utils/dist/evm'
import type { ethers as ethersV5 } from 'ethers5'
import { BigNumber } from 'ethers5'
Expand Down Expand Up @@ -189,6 +189,6 @@ export const fetchArbitrumBridgeSwap = async ({
return { request, networkFeeCryptoBaseUnit, allowanceContract: '0x0' }
}
default:
assertUnreachable(bridgeType)
return bridgeType satisfies never
}
}
4 changes: 2 additions & 2 deletions packages/swapper/src/swappers/ThorchainSwapper/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { cosmosAssetId, fromAssetId, fromChainId, thorchainAssetId } from '@shap
import { cosmossdk as cosmossdkChainAdapter } from '@shapeshiftoss/chain-adapters'
import type { BTCSignTx } from '@shapeshiftoss/hdwallet-core'
import { cosmossdk, TxStatus } from '@shapeshiftoss/unchained-client'
import { assertUnreachable, BigNumber, bn, bnOrZero } from '@shapeshiftoss/utils'
import { BigNumber, bn, bnOrZero } from '@shapeshiftoss/utils'
import { getFees } from '@shapeshiftoss/utils/dist/evm'
import { type Result } from '@sniptt/monads/build'
import assert from 'assert'
Expand Down Expand Up @@ -198,7 +198,7 @@ export const thorchainApi: SwapperApi = {
case TradeType.LongTailToLongTail:
throw Error(`Unsupported trade type: ${TradeType}`)
default:
assertUnreachable(tradeType)
return tradeType satisfies never
}
},

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertUnreachable, bn } from '@shapeshiftoss/utils'
import { bn } from '@shapeshiftoss/utils'
import type { Result } from '@sniptt/monads'
import { Err } from '@sniptt/monads'

Expand Down Expand Up @@ -127,6 +127,6 @@ export const getThorTradeQuote = async (
case TradeType.LongTailToLongTail:
return Err(makeSwapErrorRight({ message: 'Not implemented yet' }))
default:
assertUnreachable(tradeType)
return tradeType satisfies never
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { StandardTx } from '@shapeshiftoss/unchained-client'
import { assertUnreachable } from '@shapeshiftoss/utils'
import axios from 'axios'

import type { SwapperConfig } from '../../../types'
Expand Down Expand Up @@ -45,7 +44,7 @@ export const checkOutboundTxConfirmations = async (
case ThorchainChain.BSC:
throw Error(`${latestOutTx.chain} not supported`)
default:
assertUnreachable(latestOutTx.chain)
return latestOutTx.chain satisfies never
}
})()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { AssetId } from '@shapeshiftoss/caip'
import { CHAIN_NAMESPACE, fromAssetId } from '@shapeshiftoss/caip'
import { bn, bnOrZero } from '@shapeshiftoss/chain-adapters'
import {
assertUnreachable,
baseUnitToPrecision,
convertDecimalPercentageToBasisPoints,
convertPrecision,
Expand Down Expand Up @@ -503,6 +502,6 @@ export const getL1quote = async (
}

default:
assertUnreachable(chainNamespace)
return chainNamespace satisfies never
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { TxStatus } from '@shapeshiftoss/unchained-client'
import { assertUnreachable } from '@shapeshiftoss/utils'
import prettyMilliseconds from 'pretty-ms'

import type { ThorNodeStatusResponseSuccess } from '../types'
Expand Down Expand Up @@ -104,7 +103,7 @@ export const getLatestThorTxStatusMessage = (
}
}
default:
assertUnreachable(key)
return key satisfies never
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { ChainId } from '@shapeshiftoss/caip'
import { fromAssetId } from '@shapeshiftoss/caip'
import type { Asset } from '@shapeshiftoss/types'
import { KnownChainIds } from '@shapeshiftoss/types'
import { assertUnreachable } from '@shapeshiftoss/utils'

import type { ZrxSupportedChainId } from '../../types'
import { zrxSupportedChainIds } from '../../types'
Expand All @@ -24,7 +23,7 @@ export const baseUrlFromChainId = (chainId: ZrxSupportedChainId): string => {
case KnownChainIds.BaseMainnet:
return 'https://0x.shapeshift.com/base/'
default:
assertUnreachable(chainId)
return chainId satisfies never
}
}

Expand Down
3 changes: 0 additions & 3 deletions packages/utils/src/assertUnreachable.ts

This file was deleted.

6 changes: 1 addition & 5 deletions packages/utils/src/chainIdToFeeAssetId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import {
} from '@shapeshiftoss/caip'
import { KnownChainIds } from '@shapeshiftoss/types'

import { assertUnreachable } from './assertUnreachable'

export const chainIdToFeeAssetId = (_chainId: ChainId): AssetId => {
const chainId = _chainId as KnownChainIds
switch (chainId) {
Expand Down Expand Up @@ -54,8 +52,6 @@ export const chainIdToFeeAssetId = (_chainId: ChainId): AssetId => {
case KnownChainIds.ThorchainMainnet:
return thorchainAssetId
default:
assertUnreachable(chainId)
return chainId satisfies never
}

throw Error(`Unsupported chainId: ${chainId}`)
}
1 change: 0 additions & 1 deletion packages/utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { isNull, isUndefined } from 'lodash'

export * from './makeAsset/makeAsset'
export * from './assertUnreachable'
export * from './sha256'
export * from './chainIdToFeeAsset'
export * from './chainIdToFeeAssetId'
Expand Down
6 changes: 1 addition & 5 deletions scripts/generateTradableThorAssetMap/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ const ChainToChainIdMap: Map<ThorchainChain, ChainId> = new Map([
[ThorchainChain.BSC, bscChainId],
])

function assertUnreachable(x: never): never {
throw Error(`unhandled case: ${x}`)
}

export const getFeeAssetFromThorchainChain = (chain: ThorchainChain): AssetId | undefined => {
switch (chain) {
case ThorchainChain.BTC:
Expand All @@ -83,7 +79,7 @@ export const getFeeAssetFromThorchainChain = (chain: ThorchainChain): AssetId |
case ThorchainChain.BSC:
return bscAssetId
default:
assertUnreachable(chain)
return chain satisfies never
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { ChainId } from '@shapeshiftoss/caip'
import { useCallback, useEffect, useMemo, useState } from 'react'
import { useLedgerOpenApp } from 'hooks/useLedgerOpenApp/useLedgerOpenApp'
import { useWallet } from 'hooks/useWallet/useWallet'
import { assertUnreachable } from 'lib/utils'

import { DrawerWrapper } from './components/DrawerWrapper'
import { ImportAccounts } from './components/ImportAccounts'
Expand Down Expand Up @@ -42,7 +41,7 @@ export const ManageAccountsDrawer = ({
handleClose()
break
default:
assertUnreachable(step)
return step satisfies never
}
}, [wallet, step, handleClose])

Expand Down Expand Up @@ -86,7 +85,7 @@ export const ManageAccountsDrawer = ({
if (!selectedChainId) return null
return <ImportAccounts chainId={selectedChainId} onClose={handleClose} />
default:
assertUnreachable(step)
return step satisfies never
}
}, [step, handleSelectChainId, handleClose, selectedChainId])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { SlippageIcon } from 'components/Icons/Slippage'
import { RawText } from 'components/Text'
import { useLocaleFormatter } from 'hooks/useLocaleFormatter/useLocaleFormatter'
import { fromBaseUnit } from 'lib/math'
import { assertUnreachable } from 'lib/utils'
import {
selectHopExecutionMetadata,
selectHopNetworkFeeUserCurrencyPrecision,
Expand Down Expand Up @@ -154,7 +153,7 @@ export const Hop = ({
case HopExecutionState.Complete:
return Infinity
default:
assertUnreachable(hopExecutionState)
return hopExecutionState satisfies never
}
}, [hopExecutionState, hopIndex])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useMemo } from 'react'
import { FaThumbsUp } from 'react-icons/fa'
import { FaRotateRight } from 'react-icons/fa6'
import { CircularProgress } from 'components/CircularProgress/CircularProgress'
import { assertUnreachable } from 'lib/utils'
import { HopExecutionState, TransactionExecutionState } from 'state/slices/tradeQuoteSlice/types'

export const StatusIcon = ({
Expand Down Expand Up @@ -37,7 +36,7 @@ export const StatusIcon = ({
case TransactionExecutionState.AwaitingConfirmation:
return <Circle size={8}>{defaultIcon}</Circle>
default:
assertUnreachable(txStatus)
return txStatus satisfies never
}
}

Expand Down Expand Up @@ -71,7 +70,7 @@ export const ApprovalStatusIcon = ({
case HopExecutionState.Complete:
return TransactionExecutionState.Complete
default:
assertUnreachable(hopExecutionState)
return hopExecutionState satisfies never
}
}, [hopExecutionState, approvalTxState, isAllowanceResetStep])
return <StatusIcon txStatus={txStatus} defaultIcon={defaultIcon} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { useErrorHandler } from 'hooks/useErrorToast/useErrorToast'
import { useWallet } from 'hooks/useWallet/useWallet'
import { MixPanelEvent } from 'lib/mixpanel/types'
import { TradeExecution } from 'lib/tradeExecution'
import { assertUnreachable } from 'lib/utils'
import { assertGetCosmosSdkChainAdapter } from 'lib/utils/cosmosSdk'
import { assertGetEvmChainAdapter, signAndBroadcast } from 'lib/utils/evm'
import { assertGetUtxoChainAdapter } from 'lib/utils/utxo'
Expand Down Expand Up @@ -353,7 +352,7 @@ export const useTradeExecution = (
return
}
default:
assertUnreachable(stepSellAssetChainNamespace)
return stepSellAssetChainNamespace satisfies never
}
})
}, [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { KnownChainIds } from '@shapeshiftoss/types'
import { assertUnreachable } from 'lib/utils'

export const getChainShortName = (chainId: KnownChainIds) => {
switch (chainId) {
Expand Down Expand Up @@ -34,7 +33,7 @@ export const getChainShortName = (chainId: KnownChainIds) => {
case KnownChainIds.LitecoinMainnet:
return 'LTC'
default: {
assertUnreachable(chainId)
return chainId satisfies never
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { useMemo } from 'react'
import { useTranslate } from 'react-polyglot'
import { ClaimStatus } from 'components/ClaimRow/types'
import { getEthersV5Provider } from 'lib/ethersProviderSingleton'
import { assertUnreachable } from 'lib/utils'
import { selectAssetById } from 'state/slices/selectors'
import type { Tx } from 'state/slices/txHistorySlice/txHistorySlice'
import { useAppSelector } from 'state/store'
Expand Down Expand Up @@ -93,7 +92,7 @@ export const useArbitrumClaimsByStatus = (txs: Tx[]) => {
case ChildToParentMessageStatus.UNCONFIRMED:
return ClaimStatus.Pending
default:
assertUnreachable(status)
return status satisfies never
}
})()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { AvatarProps } from '@chakra-ui/react'
import { SwapperName } from '@shapeshiftoss/swapper'
import { useMemo } from 'react'
import { LazyLoadAvatar } from 'components/LazyLoadAvatar'
import { assertUnreachable } from 'lib/utils'

import ZrxIcon from './0x-icon.png'
import OneInchIcon from './1inch-icon.png'
Expand Down Expand Up @@ -38,7 +37,7 @@ export const SwapperIcon = ({
case SwapperName.Test:
return ''
default:
assertUnreachable(swapperName)
return swapperName satisfies never
}
}, [swapperName])

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { CardHeader, Flex, Heading, useMediaQuery } from '@chakra-ui/react'
import { DEFAULT_GET_TRADE_QUOTE_POLLING_INTERVAL, swappers } from '@shapeshiftoss/swapper'
import { assertUnreachable } from '@shapeshiftoss/utils'
import { useCallback, useMemo, useState } from 'react'
import { useTranslate } from 'react-polyglot'
import { useFeatureFlag } from 'hooks/useFeatureFlag/useFeatureFlag'
Expand Down Expand Up @@ -83,7 +82,7 @@ export const TradeInputHeader = ({
case TradeInputTab.Claim:
return null
default:
assertUnreachable(selectedTab)
return selectedTab satisfies never
}
})()
}, [selectedTab, isLoading, isCompact])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { TradeQuoteError as SwapperTradeQuoteError } from '@shapeshiftoss/swapper'
import type { InterpolationOptions } from 'node-polyglot'
import { assertUnreachable } from 'lib/utils'
import type { ErrorWithMeta } from 'state/apis/swapper/types'
import { type TradeQuoteError, TradeQuoteValidationError } from 'state/apis/swapper/types'

Expand Down Expand Up @@ -52,7 +51,7 @@ export const getQuoteErrorTranslation = (
case TradeQuoteValidationError.QuoteSellAmountInvalid:
return 'trade.errors.quoteError'
default:
assertUnreachable(error)
return error satisfies never
}
})()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { InterpolationOptions } from 'node-polyglot'
import { assertUnreachable } from 'lib/utils'
import type { ErrorWithMeta } from 'state/apis/swapper/types'
import { TradeQuoteRequestError } from 'state/apis/swapper/types'

Expand All @@ -22,7 +21,7 @@ export const getQuoteRequestErrorTranslation = (
case TradeQuoteRequestError.NoReceiveAddress:
return 'trade.errors.noReceiveAddress'
default:
assertUnreachable(error)
return error satisfies never
}
})()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type { GetTradeQuoteInput } from '@shapeshiftoss/swapper'
import type { Asset, UtxoAccountType } from '@shapeshiftoss/types'
import type { TradeQuoteInputCommonArgs } from 'components/MultiHopTrade/types'
import { toBaseUnit } from 'lib/math'
import { assertUnreachable } from 'lib/utils'
import { assertGetCosmosSdkChainAdapter } from 'lib/utils/cosmosSdk'
import { assertGetEvmChainAdapter } from 'lib/utils/evm'
import { assertGetUtxoChainAdapter } from 'lib/utils/utxo'
Expand Down Expand Up @@ -120,6 +119,6 @@ export const getTradeQuoteInput = async ({
}
}
default:
assertUnreachable(chainNamespace)
return chainNamespace satisfies never
}
}
3 changes: 1 addition & 2 deletions src/hooks/queries/useApprovalFees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { AssetId } from '@shapeshiftoss/caip'
import { fromAssetId } from '@shapeshiftoss/caip'
import { MAX_ALLOWANCE } from '@shapeshiftoss/swapper/src/swappers/utils/constants'
import { useMemo } from 'react'
import { assertUnreachable } from 'lib/utils'
import { getApproveContractData } from 'lib/utils/evm'

import { useEvmFees } from './useEvmFees'
Expand Down Expand Up @@ -87,6 +86,6 @@ export const getApprovalAmountCryptoBaseUnit = (
case AllowanceType.Reset:
return '0'
default:
assertUnreachable(allowanceType)
return allowanceType satisfies never
}
}
Loading
Loading