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

Open
wants to merge 23 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8e0117c
feat: migrate tradeInputSlice to higher-order-slice pattern
woodenfurniture Nov 10, 2024
f19057e
feat: move common input selectors into a selector factory
woodenfurniture Nov 10, 2024
7c03183
chore: add some code comments
woodenfurniture Nov 10, 2024
33a4641
feat: added limitOrderInputSlice
woodenfurniture Nov 10, 2024
2d77e62
feat: migrate the rest of the shared selectors
woodenfurniture Nov 11, 2024
3eafc9c
feat: wire in redux user slippage for limit orders
woodenfurniture Nov 11, 2024
5dedd59
feat: wire in redux sell asset for limit orders
woodenfurniture Nov 11, 2024
1f50150
feat: wire in redux buy asset for limit orders
woodenfurniture Nov 11, 2024
bb7474d
fix: use hardcoded cowswap for default limit order slippage
woodenfurniture Nov 11, 2024
3f25226
feat: migrate marketPriceBuyAsset to redux
woodenfurniture Nov 11, 2024
fc76235
feat: migrate limit order account IDs to redux
woodenfurniture Nov 11, 2024
3539519
feat: migrate limit order input amounts to redux
woodenfurniture Nov 11, 2024
f4597d9
chore: move selectCalculatedFees into into snapshot selectors
woodenfurniture Nov 11, 2024
ca39e07
chore: cleanup voting power selectors
woodenfurniture Nov 11, 2024
2e22e89
feat: migrate limit order useLimitOrderRecipientAddress to redux
woodenfurniture Nov 11, 2024
e30f46a
chore: cleanup slippage percentages in limit order input
woodenfurniture Nov 11, 2024
9e5f647
feat: migrate remaining limit order input handlers to redux
woodenfurniture Nov 11, 2024
4d87276
feat: introduced useActions hook for max cleanliness
woodenfurniture Nov 11, 2024
2e7b941
chore: unify naming of trade input actions and selectors
woodenfurniture Nov 11, 2024
ae28f8e
fix: free trades are free
woodenfurniture Nov 13, 2024
09c981d
fix: reset market rate when switching assets
woodenfurniture Nov 13, 2024
0e3e789
fix: import from wrong slice, prevent it from happening again
woodenfurniture Nov 13, 2024
ebc7b62
chore: useActions for the useLimitOrderRecipientAddress hook
woodenfurniture Nov 15, 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
15 changes: 12 additions & 3 deletions src/components/FeeExplainer/FeeExplainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ 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 { selectVotingPower } from 'state/apis/snapshot/selectors'
import {
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 +138,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 @@ -263,11 +270,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