Skip to content

Commit

Permalink
refactor: use isSupportedPermitInfo in a few places
Browse files Browse the repository at this point in the history
  • Loading branch information
alfetopito committed Nov 13, 2023
1 parent cb80e7d commit d8ee7d3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react'

import { PermitHookData } from '@cowprotocol/permit-utils'
import { isSupportedPermitInfo, PermitHookData } from '@cowprotocol/permit-utils'

import { useDerivedTradeState } from 'modules/trade'

Expand Down Expand Up @@ -44,7 +44,7 @@ function useGeneratePermitHookParams(): GeneratePermitHookParams | undefined {
const permitInfo = usePermitInfo(inputCurrency, tradeType)

return useSafeMemo(() => {
if (!inputCurrency || !('address' in inputCurrency) || !permitInfo || permitInfo.type === 'unsupported')
if (!inputCurrency || !('address' in inputCurrency) || !permitInfo || !isSupportedPermitInfo(permitInfo))
return undefined

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { useAtomValue, useSetAtom } from 'jotai'
import { useCallback } from 'react'

import { GP_VAULT_RELAYER } from '@cowprotocol/common-const'
import { generatePermitHook, getPermitUtilsInstance, PermitHookData } from '@cowprotocol/permit-utils'
import {
generatePermitHook,
getPermitUtilsInstance,
isSupportedPermitInfo,
PermitHookData,
} from '@cowprotocol/permit-utils'
import { useWalletInfo } from '@cowprotocol/wallet'
import { useWeb3React } from '@web3-react/core'

Expand Down Expand Up @@ -38,7 +43,7 @@ export function useGeneratePermitHook(): GeneratePermitHook {
async (params: GeneratePermitHookParams): Promise<PermitHookData | undefined> => {
const { inputToken, account, permitInfo } = params

if (!provider || permitInfo.type === 'unsupported') {
if (!provider || !isSupportedPermitInfo(permitInfo)) {
return
}

Expand Down
3 changes: 2 additions & 1 deletion libs/permit-utils/src/lib/generatePermitHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DEFAULT_PERMIT_GAS_LIMIT, DEFAULT_PERMIT_VALUE, PERMIT_SIGNER } from '.
import { PermitHookData, PermitHookParams } from '../types'
import { buildDaiLikePermitCallData, buildEip2162PermitCallData } from '../utils/buildPermitCallData'
import { getPermitDeadline } from '../utils/getPermitDeadline'
import { isSupportedPermitInfo } from '../utils/isSupportedPermitInfo'

const REQUESTS_CACHE: { [permitKey: string]: Promise<PermitHookData> } = {}

Expand Down Expand Up @@ -40,7 +41,7 @@ async function generatePermitHookRaw(params: PermitHookParams): Promise<PermitHo
// TODO: remove the need for `name` from input token. Should come from permitInfo instead
const tokenName = permitInfo.name || inputToken.name

if (permitInfo.type === 'unsupported') {
if (!isSupportedPermitInfo(permitInfo)) {
throw new Error(`Trying to generate permit hook for unsupported token: ${tokenAddress}`)
}

Expand Down

0 comments on commit d8ee7d3

Please sign in to comment.