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

Add simulator overlapping #1137

Merged
merged 69 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
c1709fe
add simulator overlapping
pingustar Mar 25, 2024
0d1059b
Merge branch 'main' into simulator/overlapping
pingustar Mar 25, 2024
f6750bf
add simulator overlapping
pingustar Mar 25, 2024
5f9a629
add simulator overlapping
pingustar Mar 25, 2024
0410524
add simulator overlapping
pingustar Mar 25, 2024
351fafd
add simulator overlapping
pingustar Mar 25, 2024
c1d756c
add simulator overlapping
pingustar Mar 25, 2024
c68e81f
[CI] Update Screenshots
pingustar Mar 25, 2024
9a9b482
fix chart rect on input change
pingustar Mar 26, 2024
2de7592
fix chart on drag end handlers
pingustar Mar 26, 2024
2eddcfb
[CI] Update Screenshots
pingustar Mar 26, 2024
f8e9968
fix overlapping budget calculations
pingustar Mar 26, 2024
26b5326
Merge remote-tracking branch 'origin/simulator/overlapping' into simu…
pingustar Mar 26, 2024
d54be72
[CI] Update Screenshots
pingustar Mar 26, 2024
6a8ee42
fix overlapping budget issues
pingustar Mar 26, 2024
0f7e07c
Merge remote-tracking branch 'origin/simulator/overlapping' into simu…
pingustar Mar 26, 2024
c026a45
remove screenshots
pingustar Mar 26, 2024
3bb2564
fix sim interface issue
pingustar Mar 26, 2024
805d727
simulator overlapping draggable rect
pingustar Mar 27, 2024
5ad04a5
simulator cleanup
pingustar Mar 27, 2024
714bbff
add router search parse update
pingustar Mar 27, 2024
f0d68d0
Merge remote-tracking branch 'origin/main' into simulator/overlapping
pingustar Mar 27, 2024
db64995
refactor simulator feature
pingustar Mar 27, 2024
b2293ac
simulate overlapping refactor
pingustar Mar 28, 2024
9151749
Merge remote-tracking branch 'origin/main' into simulator/overlapping
pingustar Apr 2, 2024
99ab6c6
fix overlapping sim result query param rounding
pingustar Apr 2, 2024
1a8c6ae
disable overlapping sim result date picker
pingustar Apr 2, 2024
36115cc
[CI] Update Screenshots
pingustar Apr 2, 2024
82907a8
add simulate link to strategy block
pingustar Apr 8, 2024
b1518eb
[CI] Update Screenshots
pingustar Apr 8, 2024
60066ff
Merge remote-tracking branch 'origin/main' into simulator/overlapping
pingustar Apr 8, 2024
eb9ae36
[CI] Update Screenshots
pingustar Apr 8, 2024
d778eb3
add overlapping budget title
pingustar Apr 8, 2024
abc0210
Merge remote-tracking branch 'origin/simulator/overlapping' into simu…
pingustar Apr 8, 2024
1262b25
hide budget error when user not connected
pingustar Apr 8, 2024
91807ed
[CI] Update Screenshots
pingustar Apr 8, 2024
3d4f921
fix icon color
pingustar Apr 8, 2024
c5056c0
Merge remote-tracking branch 'origin/simulator/overlapping' into simu…
pingustar Apr 8, 2024
f46fe60
cleanup
pingustar Apr 8, 2024
bb4455c
Merge remote-tracking branch 'origin/simulator/strategyLink' into sim…
pingustar Apr 8, 2024
7a45af6
[CI] Update Screenshots
pingustar Apr 8, 2024
aef87f0
add delete on withdraw all modal
pingustar Apr 10, 2024
eb7bf0b
Merge branch 'main' into withdrawAndDelete
pingustar Apr 10, 2024
ff38a13
add delete on withdraw all modal
pingustar Apr 10, 2024
b8539f7
Merge remote-tracking branch 'origin/withdrawAndDelete' into withdraw…
pingustar Apr 10, 2024
03842a0
Merge pull request #1164 from bancorprotocol/withdrawAndDelete
pingustar Apr 10, 2024
d6d61cb
Merge branch 'refs/heads/simulator/overlapping' into simulator/strate…
pingustar Apr 10, 2024
d6d110c
Merge pull request #1160 from bancorprotocol/simulator/strategyLink
pingustar Apr 10, 2024
f7f095f
hide simulate on strategy manage when disposable
pingustar Apr 10, 2024
8f82c02
change withdraw budget title
pingustar Apr 10, 2024
1f5605c
[CI] Update Screenshots
pingustar Apr 10, 2024
3200dc1
update text
pingustar Apr 11, 2024
4f27ebf
Merge remote-tracking branch 'origin/simulator/overlapping' into simu…
pingustar Apr 11, 2024
cbdc625
[CI] Update Screenshots
pingustar Apr 11, 2024
2fbea3f
overlapping cleanup
pingustar Apr 11, 2024
d0bedb2
Merge remote-tracking branch 'origin/simulator/overlapping' into simu…
pingustar Apr 11, 2024
563fb81
add overlapping out of scale indicator
pingustar Apr 12, 2024
c3c4dd4
Merge remote-tracking branch 'refs/remotes/origin/main' into simulato…
pingustar Apr 12, 2024
3a66d7b
fix activity search param parsing
pingustar Apr 15, 2024
5b5aa53
fix activity search param parsing
pingustar Apr 15, 2024
3ffb261
Update src/assets/icons/action.svg
pingustar Apr 15, 2024
30eb9fc
Update src/pages/simulator/result/index.tsx
pingustar Apr 15, 2024
f41441d
fix review feedback
pingustar Apr 15, 2024
7d4c2c5
Merge remote-tracking branch 'origin/simulator/overlapping' into simu…
pingustar Apr 15, 2024
ec98c73
Update src/pages/simulator/overlapping/index.tsx
pingustar Apr 15, 2024
d8b8ee9
fix review feedback
pingustar Apr 15, 2024
8920485
fix review feedback
pingustar Apr 15, 2024
9be6208
Merge remote-tracking branch 'refs/remotes/origin/main' into simulato…
pingustar Apr 15, 2024
a2e01be
[CI] Update Screenshots
pingustar Apr 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified e2e/screenshots/strategy/overlapping/Overlapping/create/form.jpg
4 changes: 2 additions & 2 deletions src/assets/icons/action.svg
8 changes: 4 additions & 4 deletions src/components/activity/ActivityFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ export const ActivityFilter: FC<ActivityFilterProps> = (props) => {
const updateParams = () => {
const selector = `input[form="${formId}"]`;
const inputs = document.querySelectorAll<HTMLInputElement>(selector);
const params: Record<string, string[]> = {};
const params: Record<string, string[] | string> = {};
for (const input of inputs) {
const name = input.name;
params[name] ||= [];
if (input.type === 'checkbox') {
if (input.checked) params[name].push(input.value);
params[name] ||= [];
if (input.checked) (params[name] as string[]).push(input.value);
} else {
params[name].push(input.value);
params[name] = input.value;
}
}
setSearchParams(params);
Expand Down
18 changes: 12 additions & 6 deletions src/components/common/datePicker/DateRangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ interface Props {
options?: Omit<CalendarProps, 'mode' | 'selected' | 'onSelect'>;
required?: boolean;
form?: string;
disabled?: boolean;
}

const displayRange = (start?: Date, end?: Date) => {
Expand All @@ -65,9 +66,12 @@ export const DateRangePicker = memo((props: Omit<Props, 'setIsOpen'>) => {
'hover:bg-background-800',
hasDates
? 'border-primary active:border-primary-light'
: 'border-background-800 hover:border-background-700 active:border-background-600'
: 'border-background-800 hover:border-background-700 active:border-background-600',
props.disabled &&
'cursor-not-allowed border-background-800 hover:border-background-800 hover:bg-transparent active:border-background-800'
)}
data-testid="date-picker-button"
disabled={props.disabled}
>
<CalendarIcon className="h-14 w-14 text-primary" />
<span
Expand All @@ -76,11 +80,13 @@ export const DateRangePicker = memo((props: Omit<Props, 'setIsOpen'>) => {
>
{displayRange(props.start, props.end)}
</span>
<ChevronIcon
className={cn('h-12 w-12 text-white/80 transition-transform', {
'rotate-180': isOpen,
})}
/>
{!props.disabled && (
<ChevronIcon
className={cn('h-12 w-12 text-white/80 transition-transform', {
'rotate-180': isOpen,
})}
/>
)}
</button>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ export const LimitRangeSection: FC<Props> = ({
ignoreMarketPriceWarning,
}) => {
const { isRange } = order;
const { marketPricePercentage, isOrderAboveOrBelowMarketPrice } =
useMarketIndication({
base,
quote,
order: { ...order, price: order.min },
buy,
});
const { isOrderAboveOrBelowMarketPrice } = useMarketIndication({
base,
quote,
order: { ...order, price: order.min },
buy,
});

const overlappingOrdersPricesMessage =
'Notice: your Buy and Sell orders overlap';
Expand Down Expand Up @@ -81,7 +80,6 @@ export const LimitRangeSection: FC<Props> = ({
quote={quote}
base={base}
buy={buy}
marketPricePercentages={marketPricePercentage}
ignoreMarketPriceWarning={ignoreMarketPriceWarning}
isOrdersReversed={isOrdersReversed}
warnings={getWarnings()}
Expand All @@ -98,7 +96,6 @@ export const LimitRangeSection: FC<Props> = ({
error={order.priceError}
setPriceError={setPriceError}
buy={buy}
marketPricePercentage={marketPricePercentage}
ignoreMarketPriceWarning={ignoreMarketPriceWarning}
isOrdersReversed={isOrdersReversed}
warnings={getWarnings()}
Expand Down
87 changes: 18 additions & 69 deletions src/components/simulator/input/SimInputChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,35 @@ import {
} from 'components/common/datePicker/DateRangePicker';
import { IconTitleText } from 'components/common/iconTitleText/IconTitleText';
import { datePickerDisabledDays } from 'components/simulator/result/SimResultChartHeader';
import { SimulatorInputDispatch } from 'hooks/useSimulatorInput';
import {
SimulatorInputOverlappingValues,
SimulatorOverlappingInputDispatch,
} from 'hooks/useSimulatorOverlappingInput';
import { StrategyInputValues } from 'hooks/useStrategyInput';
import {
ChartPrices,
D3ChartCandlesticks,
OnPriceUpdates,
} from 'components/simulator/input/d3Chart';
import { useCompareTokenPrice } from 'libs/queries/extApi/tokenPrice';
import { StrategyDirection } from 'libs/routing';
import { SafeDecimal } from 'libs/safedecimal';
import { Dispatch, SetStateAction, useCallback, useEffect } from 'react';
import { SimulatorType } from 'libs/routing/routes/sim';
import { useCallback } from 'react';
import { ReactComponent as IconPlus } from 'assets/icons/plus.svg';
import { CandlestickData, D3ChartSettingsProps, D3ChartWrapper } from 'libs/d3';
import { fromUnixUTC, toUnixUTC } from '../utils';
import { useStore } from 'store';
import { startOfDay, sub } from 'date-fns';

interface Props {
state: StrategyInputValues;
dispatch: SimulatorInputDispatch;
initBuyRange: boolean;
initSellRange: boolean;
setInitBuyRange: Dispatch<SetStateAction<boolean>>;
setInitSellRange: Dispatch<SetStateAction<boolean>>;
state: StrategyInputValues | SimulatorInputOverlappingValues;
dispatch: SimulatorOverlappingInputDispatch;
isLimit?: { buy: boolean; sell: boolean };
spread?: string;
bounds: ChartPrices;
data?: CandlestickData[];
isLoading: boolean;
isError: boolean;
simulationType: SimulatorType;
}

const chartSettings: D3ChartSettingsProps = {
Expand All @@ -49,71 +50,20 @@ const chartSettings: D3ChartSettingsProps = {
export const SimInputChart = ({
state,
dispatch,
initBuyRange,
initSellRange,
setInitBuyRange,
setInitSellRange,
isLimit,
spread,
bounds,
isLoading,
isError,
data,
simulationType,
}: Props) => {
const { debug } = useStore();
const marketPrice = useCompareTokenPrice(
state.baseToken?.address,
state.quoteToken?.address
);

const handleDefaultValues = useCallback(
(type: StrategyDirection) => {
const init = type === 'buy' ? initBuyRange : initSellRange;
const setInit = type === 'buy' ? setInitBuyRange : setInitSellRange;

if (!marketPrice || !init) return;
setInit(false);

if (!(!state[type].max && !state[type].min)) {
return;
}

const operation = type === 'buy' ? 'minus' : 'plus';

const multiplierMax = type === 'buy' ? 0.1 : 0.2;
const multiplierMin = type === 'buy' ? 0.2 : 0.1;

const max = new SafeDecimal(marketPrice)
[operation](marketPrice * multiplierMax)
.toFixed();

const min = new SafeDecimal(marketPrice)
[operation](marketPrice * multiplierMin)
.toFixed();

if (state[type].isRange) {
dispatch(`${type}Max`, max);
dispatch(`${type}Min`, min);
} else {
const value = type === 'buy' ? max : min;
dispatch(`${type}Max`, value);
dispatch(`${type}Min`, value);
}
},
[
dispatch,
initBuyRange,
initSellRange,
marketPrice,
setInitBuyRange,
setInitSellRange,
state,
]
);

useEffect(() => {
handleDefaultValues('buy');
handleDefaultValues('sell');
}, [handleDefaultValues]);

const prices = {
buy: {
min: state.buy.min,
Expand Down Expand Up @@ -155,7 +105,7 @@ export const SimInputChart = ({
);

return (
<div className="align-stretch sticky top-80 grid h-[calc(100vh-180px)] min-h-[500px] flex-1 grid-rows-[auto_1fr] justify-items-stretch rounded-12 bg-background-900 p-20">
<div className="align-stretch top-120 fixed right-20 grid h-[calc(100vh-220px)] min-h-[500px] w-[calc(100%-500px)] flex-1 grid-rows-[auto_1fr] justify-items-stretch rounded-12 bg-background-900 p-20">
pingustar marked this conversation as resolved.
Show resolved Hide resolved
<div className="mb-20 flex items-center justify-between">
<h2 className="mr-20 text-20 font-weight-500">Price Chart</h2>
<DateRangePicker
Expand Down Expand Up @@ -197,10 +147,9 @@ export const SimInputChart = ({
marketPrice={marketPrice}
bounds={bounds}
onDragEnd={onPriceUpdatesEnd}
isLimit={{
buy: !state.buy.isRange,
sell: !state.sell.isRange,
}}
isLimit={isLimit}
type={simulationType}
overlappingSpread={spread}
/>
)}
</D3ChartWrapper>
Expand Down
7 changes: 0 additions & 7 deletions src/components/simulator/input/SimInputOverlapping.tsx

This file was deleted.

50 changes: 28 additions & 22 deletions src/components/simulator/input/SimInputStrategyType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ import { cn } from 'utils/helpers';
import { SimulatorType } from 'libs/routing/routes/sim';
import { Link } from 'libs/routing';

interface Props {
strategyType: SimulatorType;
}

interface ItemProps {
label: SimulatorType;
svg: JSX.Element;
tooltipText: string;
}

export const SimInputStrategyType: FC<Props> = ({ strategyType }) => {
interface Props {
baseToken?: string;
quoteToken?: string;
}

export const SimInputStrategyType: FC<Props> = ({ baseToken, quoteToken }) => {
const items: ItemProps[] = [
{
label: 'recurring',
Expand Down Expand Up @@ -46,33 +47,38 @@ export const SimInputStrategyType: FC<Props> = ({ strategyType }) => {
role="tab"
id={'tab-' + label}
aria-controls={'panel-' + label}
aria-selected={strategyType === label}
key={label}
to="/simulate/$simulationType"
to={`/simulate/${label}`}
GrandSchtroumpf marked this conversation as resolved.
Show resolved Hide resolved
search={{ baseToken, quoteToken }}
className={cn(
'flex h-full w-full flex-row items-center justify-center gap-8 rounded-10 bg-black px-8 py-16 text-14 font-weight-500 outline-white/60',
'md:px-12',
'focus-visible:outline focus-visible:outline-1',
strategyType === label ? 'outline outline-1 outline-white' : ''
'focus-visible:outline focus-visible:outline-1'
)}
activeProps={{ className: 'outline outline-1 outline-white' }}
replace={true}
resetScroll={false}
params={{ simulationType: label }}
data-testid={`select-type-${label}`}
>
{svg}
<span
className={`capitalize ${
strategyType === label ? 'text-white' : 'text-white/40'
}`}
>
{label}
</span>

<Tooltip
element={<div>{tooltipText}</div>}
iconClassName="!h-12 !w-12 text-white/60"
/>
{({ isActive }) => {
return (
<>
{svg}
<span
className={`capitalize ${
isActive ? 'text-white' : 'text-white/40'
}`}
>
{label}
</span>
<Tooltip
element={<div>{tooltipText}</div>}
iconClassName="!h-12 !w-12 text-white/60"
/>
</>
);
}}
</Link>
))}
</article>
Expand Down
Loading
Loading