Skip to content

Commit

Permalink
feat: add StyledPriceImpactText and integrate PriceProtectionSelector
Browse files Browse the repository at this point in the history
  • Loading branch information
oxbyte-monterrosa committed Jul 26, 2024
1 parent 568aa16 commit 1c48996
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/lib/src/components/Components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Slider,
Switch,
TimeSelector,
PriceImpactSelector,
TokenName,
TokenPriceCompare,
Tooltip,
Expand Down Expand Up @@ -345,6 +346,13 @@ export function TradeIntervalSelector({ placeholder }: { placeholder?: string })
return <TimeSelector placeholder={placeholder} onChange={setFillDelay} value={fillDelay} />;
}

export const PriceProtectionSelector = ({ placeholder, icon }: { placeholder?: string; icon?: any }) => {
const setPriceImpact = useTwapStore((store) => store.setPriceImpact);
const priceImpact = useTwapStore((store) => store.getPriceImpact)();

return <PriceImpactSelector placeholder={placeholder} onChange={setPriceImpact} value={priceImpact} icon={icon} />;
};

interface TokenSelectProps extends TWAPTokenSelectProps {
Component?: FC<TWAPTokenSelectProps>;
isOpen: boolean;
Expand Down
1 change: 1 addition & 0 deletions packages/lib/src/components/base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export { default as Label } from "./Label";
export { default as SmallLabel } from "./SmallLabel";
export * from "./Switch";
export { default as TimeSelector } from "./TimeSelector";
export { default as PriceImpactSelector } from "./PriceImpactSelector";
export { default as TokenLogo } from "./TokenLogo";
export { default as TokenName } from "./TokenName";
export { default as Layout } from "./Layout";
Expand Down
6 changes: 6 additions & 0 deletions packages/lib/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const getInitialState = (queryParamsEnabled?: boolean): State => {
waitingForOrdersUpdate: false,
srcUsd: undefined,
dstUsd: undefined,

priceImpact: 0,
};
};
const initialState = getInitialState();
Expand Down Expand Up @@ -115,6 +117,10 @@ export const useTwapStore = create(
setQueryParam(QUERY_PARAMS.TRADE_INTERVAL, !fillDelay.amount ? undefined : fillDelay.amount?.toString());
set({ customFillDelay: fillDelay });
},
setPriceImpact: (priceImpact: number) => {},
getPriceImpact: () => {
return get().priceImpact;
},
getFillDelayText: (translations: Translations) => fillDelayText((get() as any).getFillDelayUiMillis(), translations),
getFillDelayUiMillis: () => get().customFillDelay.amount! * get().customFillDelay.resolution,
getMinimumDelayMinutes: () => (get().lib?.estimatedDelayBetweenChunksMillis() || 0) / 1000 / 60,
Expand Down
6 changes: 6 additions & 0 deletions packages/lib/src/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ export const StyledText = styled(Typography)({
fontSize: "inherit",
});

export const StyledPriceImpactText = styled(Typography)({
fontFamily: "inherit",
fontSize: 16,
fontWeight: 600,
});

export const StyledColumnFlex = styled(Box)(({ gap = 10 }: { gap?: number }) => ({
display: "flex",
flexDirection: "column",
Expand Down

0 comments on commit 1c48996

Please sign in to comment.