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

fix: surplus modal flickering #3124

Merged
merged 1 commit into from
Sep 8, 2023
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
18 changes: 11 additions & 7 deletions apps/cowswap-frontend/src/common/hooks/useGetSurplusFiatValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Order } from 'legacy/state/orders/actions'

import { useUsdAmount } from 'modules/usdAmount'

import { useSafeMemo } from 'common/hooks/useSafeMemo'
import { getExecutedSummaryData } from 'utils/getExecutedSummaryData'
import { ParsedOrder } from 'utils/orderUtils/parseOrder'

Expand Down Expand Up @@ -39,13 +40,16 @@ export function useGetSurplusData(order: Order | ParsedOrder | undefined): Outpu

const showSurplus = shouldShowSurplus(surplusFiatValue, surplusAmount)

return {
surplusFiatValue,
showFiatValue,
surplusToken,
surplusAmount,
showSurplus,
}
return useSafeMemo(
() => ({
surplusFiatValue,
showFiatValue,
surplusToken,
surplusAmount,
showSurplus,
}),
[surplusFiatValue, showFiatValue, surplusToken, surplusAmount, showSurplus]
Copy link
Contributor

Choose a reason for hiding this comment

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

How this is solving the issue?

I mean, this is just memorizing the result.
if it was true the theory that this is because showSurplus is true, then false, then true again (because of the USD), how is meoizing helping?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

🤷

)
}

function shouldShowSurplus(
Expand Down
Loading