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: handle holistic trade failure status in inner steps #8492

Merged
merged 2 commits into from
Jan 7, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
selectActiveQuoteErrors,
selectHopExecutionMetadata,
} from 'state/slices/tradeQuoteSlice/selectors'
import { TransactionExecutionState } from 'state/slices/tradeQuoteSlice/types'
import { useAppSelector, useSelectorWithArgs } from 'state/store'

import { StepperStep as StepperStepComponent } from '../MultiHopTradeConfirm/components/StepperStep'
Expand Down Expand Up @@ -136,17 +137,41 @@ export const ExpandedStepperSteps = ({ activeTradeQuote }: ExpandedStepperStepsP
swap: lastHopSwap,
} = useSelectorWithArgs(selectHopExecutionMetadata, lastHopExecutionMetadataFilter)

const transactionExecutionStateError = useMemo(() => {
return [
firstHopAllowanceApproval.state,
lastHopAllowanceApproval.state,
firstHopPermit2.state,
lastHopPermit2.state,
firstHopSwap.state,
lastHopSwap.state,
firstHopAllowanceReset.state,
lastHopAllowanceReset.state,
].includes(TransactionExecutionState.Failed)
}, [
firstHopAllowanceApproval.state,
firstHopAllowanceReset.state,
firstHopPermit2.state,
firstHopSwap.state,
lastHopAllowanceApproval.state,
lastHopAllowanceReset.state,
lastHopPermit2.state,
lastHopSwap.state,
])

const { currentTradeStepIndex: currentStep } = useStepperSteps()

const stepIndicator = useMemo(
() => (
<StepStatus
complete={completedStepIndicator}
incomplete={undefined}
active={activeQuoteError ? erroredStepIndicator : undefined}
active={
activeQuoteError || transactionExecutionStateError ? erroredStepIndicator : undefined
}
/>
),
[activeQuoteError],
[activeQuoteError, transactionExecutionStateError],
)

const firstHopAllowanceResetTitle = useMemo(() => {
Expand Down Expand Up @@ -338,6 +363,7 @@ export const ExpandedStepperSteps = ({ activeTradeQuote }: ExpandedStepperStepsP
])

const { tradeSteps, currentTradeStep } = useStepperSteps()
const isError = activeQuoteError || transactionExecutionStateError

return (
<Stepper variant='innerSteps' orientation='vertical' index={currentStep} gap={0}>
Expand All @@ -347,7 +373,7 @@ export const ExpandedStepperSteps = ({ activeTradeQuote }: ExpandedStepperStepsP
stepIndicator={stepIndicator}
stepProps={stepProps}
useSpacer={false}
isError={activeQuoteError && currentTradeStep === StepperStep.FirstHopReset}
isError={isError && currentTradeStep === StepperStep.FirstHopReset}
stepIndicatorVariant='innerSteps'
/>
) : null}
Expand All @@ -357,7 +383,7 @@ export const ExpandedStepperSteps = ({ activeTradeQuote }: ExpandedStepperStepsP
stepIndicator={stepIndicator}
stepProps={stepProps}
useSpacer={false}
isError={activeQuoteError && currentTradeStep === StepperStep.FirstHopApproval}
isError={isError && currentTradeStep === StepperStep.FirstHopApproval}
stepIndicatorVariant='innerSteps'
/>
) : null}
Expand All @@ -366,7 +392,7 @@ export const ExpandedStepperSteps = ({ activeTradeQuote }: ExpandedStepperStepsP
stepIndicator={stepIndicator}
stepProps={stepProps}
useSpacer={false}
isError={activeQuoteError && currentTradeStep === StepperStep.FirstHopSwap}
isError={isError && currentTradeStep === StepperStep.FirstHopSwap}
stepIndicatorVariant='innerSteps'
/>
{tradeSteps[StepperStep.LastHopReset] ? (
Expand All @@ -375,7 +401,7 @@ export const ExpandedStepperSteps = ({ activeTradeQuote }: ExpandedStepperStepsP
stepIndicator={stepIndicator}
stepProps={stepProps}
useSpacer={false}
isError={activeQuoteError && currentTradeStep === StepperStep.LastHopReset}
isError={isError && currentTradeStep === StepperStep.LastHopReset}
stepIndicatorVariant='innerSteps'
/>
) : null}
Expand All @@ -385,7 +411,7 @@ export const ExpandedStepperSteps = ({ activeTradeQuote }: ExpandedStepperStepsP
stepIndicator={stepIndicator}
stepProps={stepProps}
useSpacer={false}
isError={activeQuoteError && currentTradeStep === StepperStep.LastHopApproval}
isError={isError && currentTradeStep === StepperStep.LastHopApproval}
stepIndicatorVariant='innerSteps'
/>
) : null}
Expand All @@ -395,7 +421,7 @@ export const ExpandedStepperSteps = ({ activeTradeQuote }: ExpandedStepperStepsP
stepIndicator={stepIndicator}
stepProps={stepProps}
useSpacer={false}
isError={activeQuoteError && currentTradeStep === StepperStep.LastHopSwap}
isError={isError && currentTradeStep === StepperStep.LastHopSwap}
stepIndicatorVariant='innerSteps'
/>
) : null}
Expand Down