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: migrate limit orders to utilize redux for state management #8112

Merged
merged 24 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5267ad2
feat: migrate tradeInputSlice to higher-order-slice pattern
woodenfurniture Nov 10, 2024
9bcc5fa
feat: move common input selectors into a selector factory
woodenfurniture Nov 10, 2024
0b7ab89
chore: add some code comments
woodenfurniture Nov 10, 2024
3410546
feat: added limitOrderInputSlice
woodenfurniture Nov 10, 2024
c1b83cb
feat: migrate the rest of the shared selectors
woodenfurniture Nov 11, 2024
366b962
feat: wire in redux user slippage for limit orders
woodenfurniture Nov 11, 2024
93129e4
feat: wire in redux sell asset for limit orders
woodenfurniture Nov 11, 2024
d001163
feat: wire in redux buy asset for limit orders
woodenfurniture Nov 11, 2024
d7adf9e
fix: use hardcoded cowswap for default limit order slippage
woodenfurniture Nov 11, 2024
e87502c
feat: migrate marketPriceBuyAsset to redux
woodenfurniture Nov 11, 2024
622f3ac
feat: migrate limit order account IDs to redux
woodenfurniture Nov 11, 2024
698c736
feat: migrate limit order input amounts to redux
woodenfurniture Nov 11, 2024
36a73da
chore: move selectCalculatedFees into into snapshot selectors
woodenfurniture Nov 11, 2024
b18e390
chore: cleanup voting power selectors
woodenfurniture Nov 11, 2024
0b86ac0
feat: migrate limit order useLimitOrderRecipientAddress to redux
woodenfurniture Nov 11, 2024
1610174
chore: cleanup slippage percentages in limit order input
woodenfurniture Nov 11, 2024
5758a2e
feat: migrate remaining limit order input handlers to redux
woodenfurniture Nov 11, 2024
149680b
feat: introduced useActions hook for max cleanliness
woodenfurniture Nov 11, 2024
7794dbe
chore: unify naming of trade input actions and selectors
woodenfurniture Nov 11, 2024
bbf33a8
fix: free trades are free
woodenfurniture Nov 13, 2024
33869b8
fix: reset market rate when switching assets
woodenfurniture Nov 13, 2024
53a642f
fix: import from wrong slice, prevent it from happening again
woodenfurniture Nov 13, 2024
cecdcee
chore: useActions for the useLimitOrderRecipientAddress hook
woodenfurniture Nov 15, 2024
fb8e778
chore: actioned gome review feedback
woodenfurniture Nov 20, 2024
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
16 changes: 13 additions & 3 deletions src/components/FeeExplainer/FeeExplainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ import { calculateFees } from 'lib/fees/model'
import { FEE_CURVE_PARAMETERS, FEE_MODEL_TO_FEATURE_NAME } from 'lib/fees/parameters'
import type { ParameterModel } from 'lib/fees/parameters/types'
import { isSome } from 'lib/utils'
import { selectIsSnapshotApiQueriesPending, selectVotingPower } from 'state/apis/snapshot/selectors'
import {
selectIsSnapshotApiQueriesPending,
selectIsSnapshotApiQueriesRejected,
selectVotingPower,
} from 'state/apis/snapshot/selectors'
import { useAppSelector } from 'state/store'

import { CHART_TRADE_SIZE_MAX_USD } from './common'
Expand Down Expand Up @@ -135,28 +139,32 @@ const FeeChart: React.FC<FeeChartProps> = ({ foxHolding, tradeSize, feeModel })
return handleDebounce.cancel
}, [foxHolding])

const isSnapshotApiQueriesRejected = useAppSelector(selectIsSnapshotApiQueriesRejected)

const data = useMemo(() => {
return tradeSizeData
.map(trade => {
const feeBps = calculateFees({
tradeAmountUsd: bn(trade),
foxHeld: bn(debouncedFoxHolding),
feeModel,
isSnapshotApiQueriesRejected,
}).feeBpsFloat.toNumber()
return { x: trade, y: feeBps }
})
.filter(isSome)
}, [debouncedFoxHolding, feeModel])
}, [debouncedFoxHolding, feeModel, isSnapshotApiQueriesRejected])

const currentPoint = useMemo(() => {
const feeBps = calculateFees({
tradeAmountUsd: bn(tradeSize),
foxHeld: bn(debouncedFoxHolding),
feeModel,
isSnapshotApiQueriesRejected,
}).feeBpsFloat.toNumber()

return [{ x: tradeSize, y: feeBps }]
}, [tradeSize, debouncedFoxHolding, feeModel])
}, [tradeSize, debouncedFoxHolding, feeModel, isSnapshotApiQueriesRejected])

const tickLabelProps = useCallback(
() => ({ fill: textColor, fontSize: 12, fontWeight: 'medium' }),
Expand Down Expand Up @@ -253,11 +261,13 @@ type FeeOutputProps = {
}

export const FeeOutput: React.FC<FeeOutputProps> = ({ tradeSizeUSD, foxHolding, feeModel }) => {
const isSnapshotApiQueriesRejected = useAppSelector(selectIsSnapshotApiQueriesRejected)
const { feeUsd, feeBps, foxDiscountPercent, feeUsdBeforeDiscount, feeBpsBeforeDiscount } =
calculateFees({
tradeAmountUsd: bn(tradeSizeUSD),
foxHeld: bn(foxHolding),
feeModel,
isSnapshotApiQueriesRejected,
})

const basedOnFeeTranslation: TextPropTypes['translation'] = useMemo(
Expand Down
2 changes: 1 addition & 1 deletion src/components/FeeModal/FeeBreakdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { RawText } from 'components/Text'
import { BigNumber } from 'lib/bignumber/bignumber'
import { FEE_MODEL_TO_FEATURE_NAME } from 'lib/fees/parameters'
import type { ParameterModel } from 'lib/fees/parameters/types'
import { selectCalculatedFees } from 'state/slices/tradeQuoteSlice/selectors'
import { selectCalculatedFees } from 'state/apis/snapshot/selectors'
import { useAppSelector } from 'state/store'

const divider = <Divider />
Expand Down
Loading
Loading