diff --git a/apps/cowswap-frontend/src/modules/permit/hooks/useGeneratePermitHook.ts b/apps/cowswap-frontend/src/modules/permit/hooks/useGeneratePermitHook.ts index 86d6b6bf65..68c215c0af 100644 --- a/apps/cowswap-frontend/src/modules/permit/hooks/useGeneratePermitHook.ts +++ b/apps/cowswap-frontend/src/modules/permit/hooks/useGeneratePermitHook.ts @@ -19,7 +19,7 @@ import { GeneratePermitHook, GeneratePermitHookParams } from '../types' /** * Hook that returns callback to generate permit hook data */ -export function useGeneratePermitHook(): GeneratePermitHook { +export function useGeneratePermitHook(isPartialApprove?: boolean): GeneratePermitHook { const { chainId } = useWalletInfo() const storePermit = useSetAtom(storePermitCacheAtom) const getCachedPermit = useGetCachedPermit() @@ -36,7 +36,7 @@ export function useGeneratePermitHook(): GeneratePermitHook { return useCallback( async (params: GeneratePermitHookParams): Promise => { - const { inputToken, account, permitInfo, customSpender } = params + const { inputToken, account, permitInfo, customSpender, amount } = params if (!provider || !isSupportedPermitInfo(permitInfo)) { return @@ -66,12 +66,13 @@ export function useGeneratePermitHook(): GeneratePermitHook { eip2162Utils, account, nonce, + amount: isPartialApprove ? amount : undefined, }) hookData && storePermit({ ...permitParams, hookData, spender }) return hookData }, - [provider, chainId, getCachedPermit, storePermit], + [provider, chainId, getCachedPermit, storePermit, isPartialApprove], ) } diff --git a/apps/cowswap-frontend/src/modules/permit/types.ts b/apps/cowswap-frontend/src/modules/permit/types.ts index c1b9cd215d..edac228646 100644 --- a/apps/cowswap-frontend/src/modules/permit/types.ts +++ b/apps/cowswap-frontend/src/modules/permit/types.ts @@ -14,7 +14,7 @@ export type AddPermitTokenParams = { permitInfo: PermitInfo } -export type GeneratePermitHookParams = Pick & { +export type GeneratePermitHookParams = Pick & { customSpender?: string } diff --git a/apps/cowswap-frontend/src/modules/permit/utils/handlePermit.ts b/apps/cowswap-frontend/src/modules/permit/utils/handlePermit.ts index 1a13cb033c..1be97e5ee9 100644 --- a/apps/cowswap-frontend/src/modules/permit/utils/handlePermit.ts +++ b/apps/cowswap-frontend/src/modules/permit/utils/handlePermit.ts @@ -22,7 +22,7 @@ import { HandlePermitParams } from '../types' * Returns the updated appData */ export async function handlePermit(params: HandlePermitParams): Promise { - const { permitInfo, inputToken, account, appData, typedHooks, generatePermitHook } = params + const { permitInfo, inputToken, account, appData, typedHooks, generatePermitHook, amount } = params if (isSupportedPermitInfo(permitInfo) && !getIsNativeToken(inputToken)) { // permitInfo will only be set if there's NOT enough allowance @@ -31,6 +31,7 @@ export async function handlePermit(params: HandlePermitParams): Promise { if (!swapFlowContext) return diff --git a/apps/cowswap-frontend/src/modules/swap/hooks/useSwapButtonContext.ts b/apps/cowswap-frontend/src/modules/swap/hooks/useSwapButtonContext.ts index 5195998bff..19906be3f4 100644 --- a/apps/cowswap-frontend/src/modules/swap/hooks/useSwapButtonContext.ts +++ b/apps/cowswap-frontend/src/modules/swap/hooks/useSwapButtonContext.ts @@ -14,6 +14,7 @@ import { Currency, CurrencyAmount } from '@uniswap/sdk-core' import { useToggleWalletModal } from 'legacy/state/application/hooks' import { useGetQuoteAndStatus, useIsBestQuoteLoading } from 'legacy/state/price/hooks' import { Field } from 'legacy/state/types' +import { usePartialApprove } from 'legacy/state/user/hooks' import { useCurrencyAmountBalanceCombined } from 'modules/combinedBalances' import { useInjectedWidgetParams } from 'modules/injectedWidget' @@ -38,8 +39,6 @@ import { useSafeMemo } from 'common/hooks/useSafeMemo' import { useHandleSwapOrEthFlow } from './useHandleSwapOrEthFlow' import { useDerivedSwapInfo, useSwapActionHandlers } from './useSwapState' -import { usePartialApprove } from '../../../legacy/state/user/hooks' - export interface SwapButtonInput { feeWarningAccepted: boolean impactWarningAccepted: boolean diff --git a/apps/cowswap-frontend/src/modules/tradeFlow/hooks/useTradeFlowContext.ts b/apps/cowswap-frontend/src/modules/tradeFlow/hooks/useTradeFlowContext.ts index fafa6e7594..841a471258 100644 --- a/apps/cowswap-frontend/src/modules/tradeFlow/hooks/useTradeFlowContext.ts +++ b/apps/cowswap-frontend/src/modules/tradeFlow/hooks/useTradeFlowContext.ts @@ -28,9 +28,10 @@ import { TradeFlowContext } from '../types/TradeFlowContext' export interface TradeFlowParams { deadline: number + isPartialApprove?: boolean } -export function useTradeFlowContext({ deadline }: TradeFlowParams): TradeFlowContext | null { +export function useTradeFlowContext({ deadline, isPartialApprove }: TradeFlowParams): TradeFlowContext | null { const { chainId, account } = useWalletInfo() const provider = useWalletProvider() const { allowsOffchainSigning } = useWalletDetails() @@ -49,7 +50,7 @@ export function useTradeFlowContext({ deadline }: TradeFlowParams): TradeFlowCon const networkFee = receiveAmountInfo?.costs.networkFee.amountInSellCurrency const permitInfo = usePermitInfo(sellCurrency, tradeType) - const generatePermitHook = useGeneratePermitHook() + const generatePermitHook = useGeneratePermitHook(isPartialApprove) const getCachedPermit = useGetCachedPermit() const closeModals = useCloseModals() const dispatch = useDispatch() diff --git a/apps/cowswap-frontend/src/modules/tradeFlow/services/swapFlow/index.ts b/apps/cowswap-frontend/src/modules/tradeFlow/services/swapFlow/index.ts index d26e22b9d4..1a8589d56c 100644 --- a/apps/cowswap-frontend/src/modules/tradeFlow/services/swapFlow/index.ts +++ b/apps/cowswap-frontend/src/modules/tradeFlow/services/swapFlow/index.ts @@ -59,6 +59,7 @@ export async function swapFlow( inputToken: inputCurrency, permitInfo, generatePermitHook, + amount: BigInt(inputAmount.quotient.toString()), }) if (callDataContainsPermitSigner(orderParams.appData.fullAppData)) { diff --git a/libs/permit-utils/src/lib/generatePermitHook.ts b/libs/permit-utils/src/lib/generatePermitHook.ts index e9f2e32675..f121a67d83 100644 --- a/libs/permit-utils/src/lib/generatePermitHook.ts +++ b/libs/permit-utils/src/lib/generatePermitHook.ts @@ -37,7 +37,17 @@ export async function generatePermitHook(params: PermitHookParams): Promise { - const { inputToken, spender, chainId, permitInfo, provider, account, eip2162Utils, nonce: preFetchedNonce } = params + const { + inputToken, + spender, + chainId, + permitInfo, + provider, + account, + eip2162Utils, + nonce: preFetchedNonce, + amount, + } = params const tokenAddress = inputToken.address // TODO: remove the need for `name` from input token. Should come from permitInfo instead @@ -58,7 +68,7 @@ async function generatePermitHookRaw(params: PermitHookParams): Promise