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

feat: actually make permit2 allowance/sign distinct steps #8509

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -211,21 +211,6 @@ export const ExpandedStepperSteps = ({ activeTradeQuote }: ExpandedStepperStepsP
</Tooltip>
</>
)
// Allowance granted, but still waiting for the actual Permit2 signature granting temp 5mn allowance to the contract
if (
firstHopPermit2.isRequired &&
hopExecutionState === HopExecutionState.AwaitingPermit2Eip712Sign
)
return (
<>
<Text translation='trade.permit2Eip712.title' />
<Tooltip label={translate('trade.permit2Eip712.tooltip', { swapperName })}>
<Box ml={1}>
<Icon as={FaInfoCircle} color='text.subtle' fontSize='0.8em' />
</Box>
</Tooltip>
</>
)

// Good ol' allowances
return (
Expand All @@ -252,11 +237,23 @@ export const ExpandedStepperSteps = ({ activeTradeQuote }: ExpandedStepperStepsP
firstHopPermit2.isRequired,
firstHopSellAccountId,
hopExecutionState,
swapperName,
tradeQuoteFirstHop,
translate,
])

const firstHopPermit2SignTitle = useMemo(() => {
return (
<Flex alignItems='center' justifyContent='space-between' flex={1}>
<Text translation='trade.permit2Eip712.title' />
<Tooltip label={translate('trade.permit2Eip712.tooltip', { swapperName })}>
<Box ml={1}>
<Icon as={FaInfoCircle} color='text.subtle' fontSize='0.8em' />
</Box>
</Tooltip>
</Flex>
)
}, [swapperName, translate])

const firstHopActionTitle = useMemo(() => {
return (
<Flex alignItems='center' justifyContent='space-between' flex={1} gap={2}>
Expand Down Expand Up @@ -455,6 +452,16 @@ export const ExpandedStepperSteps = ({ activeTradeQuote }: ExpandedStepperStepsP
stepIndicatorVariant='innerSteps'
/>
) : null}
{tradeSteps[StepperStep.FirstHopPermit2Sign] ? (
<StepperStepComponent
title={firstHopPermit2SignTitle}
stepIndicator={stepIndicator}
stepProps={stepProps}
useSpacer={false}
isError={isError && currentTradeStep === StepperStep.FirstHopApproval}
stepIndicatorVariant='innerSteps'
/>
) : null}
<StepperStepComponent
title={firstHopActionTitle}
stepIndicator={stepIndicator}
Expand Down
16 changes: 9 additions & 7 deletions src/components/MultiHopTrade/components/TradeConfirm/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type StepperStepParams = {

export enum StepperStep {
FirstHopReset = 'firstHopReset',
FirstHopPermit2Sign = 'firstHopPermit2Sign',
FirstHopApproval = 'firstHopApproval',
FirstHopSwap = 'firstHopSwap',
LastHopReset = 'lastHopReset',
Expand All @@ -83,9 +84,8 @@ export const getStepperSteps = (params: StepperStepParams): Record<StepperStep,
firstHopAllowanceReset.isRequired === true || firstHopAllowanceReset.txHash !== undefined,
[StepperStep.FirstHopApproval]:
firstHopAllowanceApproval.isInitiallyRequired === true ||
firstHopPermit2.isRequired === true ||
firstHopAllowanceApproval.txHash !== undefined ||
firstHopPermit2.permit2Signature !== undefined,
firstHopAllowanceApproval.txHash !== undefined,
[StepperStep.FirstHopPermit2Sign]: firstHopPermit2.isRequired === true,
[StepperStep.FirstHopSwap]: true,
[StepperStep.LastHopReset]:
isMultiHopTrade === true &&
Expand All @@ -106,10 +106,11 @@ export const countStepperSteps = (params: StepperStepParams): number => {
}

const isInApprovalState = (state: HopExecutionState): boolean => {
return [
HopExecutionState.AwaitingAllowanceApproval,
HopExecutionState.AwaitingPermit2Eip712Sign,
].includes(state)
return [HopExecutionState.AwaitingAllowanceApproval].includes(state)
}

const isInPermit2SignState = (state: HopExecutionState): boolean => {
return [HopExecutionState.AwaitingPermit2Eip712Sign].includes(state)
Copy link
Member

@woodenfurniture woodenfurniture Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick]

Suggested change
return [HopExecutionState.AwaitingAllowanceApproval].includes(state)
}
const isInPermit2SignState = (state: HopExecutionState): boolean => {
return [HopExecutionState.AwaitingPermit2Eip712Sign].includes(state)
return state === HopExecutionState.AwaitingAllowanceApproval
}
const isInPermit2SignState = (state: HopExecutionState): boolean => {
return state = HopExecutionState.AwaitingPermit2Eip712Sign

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧠

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

export const getCurrentStepperStep = (
Expand All @@ -123,6 +124,7 @@ export const getCurrentStepperStep = (
if (hopExecutionState === HopExecutionState.AwaitingAllowanceReset)
return StepperStep.FirstHopReset
if (isInApprovalState(hopExecutionState)) return StepperStep.FirstHopApproval
if (isInPermit2SignState(hopExecutionState)) return StepperStep.FirstHopPermit2Sign
if (hopExecutionState === HopExecutionState.AwaitingSwap) return StepperStep.FirstHopSwap
} else if (currentHopIndex === 1) {
if (hopExecutionState === HopExecutionState.AwaitingAllowanceReset)
Expand Down