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(uirefresh): component refresh - trade box [2/2] #1214

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
20 changes: 18 additions & 2 deletions src/components/ToggleGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type ElementProps<MenuItemValue extends string> = {
onValueChange: (value: MenuItemValue) => void;
onInteraction?: () => void;
ensureSelected?: boolean;
disabled?: boolean;
};

type StyleProps = {
Expand All @@ -39,6 +40,7 @@ export const ToggleGroup = forwardRefFn(
items,
value,
ensureSelected = true,
disabled = false,
onValueChange,
onInteraction,

Expand Down Expand Up @@ -69,7 +71,7 @@ export const ToggleGroup = forwardRefFn(
<$ToggleButton
size={size ?? (isTablet ? ButtonSize.Small : ButtonSize.XSmall)}
shape={shape}
disabled={item.disabled}
disabled={item.disabled ?? disabled}
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this be || ?

$withSeparators={withSeparators}
{...buttonProps}
>
Expand All @@ -96,6 +98,7 @@ export const ToggleGroup = forwardRefFn(
overflow={overflow}
tw="row gap-[0.33em]"
$withSeparators={withSeparators}
disabled={disabled}
>
{slotBefore}
{withSeparators ? (
Expand All @@ -117,6 +120,7 @@ const $Root = styled(Root)<{
${({ $withSeparators }) =>
$withSeparators &&
css`
--separator-padding: 0.5rem;
align-self: stretch;
`}
${({ overflow }) =>
Expand All @@ -136,10 +140,21 @@ const $Label = styled.div`
`;

const $WithSeparators = styled(WithSeparators)`
--separatorHeight-padding: 0.5rem;
--separatorHeight-padding: var(--separator-padding);
`;

const $ToggleButton = styled(ToggleButton)<{ $withSeparators: boolean }>`
&[data-disabled] {
> * {
cursor: not-allowed;
}
}
&:not([data-disabled]) {
> * {
cursor: pointer;
}
}
${({ $withSeparators }) =>
$withSeparators &&
css`
Expand All @@ -150,5 +165,6 @@ const $ToggleButton = styled(ToggleButton)<{ $withSeparators: boolean }>`
--button-padding: 0 0.25rem;
width: min-content;
max-width: max-content;
`}
`;
1 change: 1 addition & 0 deletions src/constants/trade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export const CLEARED_SIZE_INPUTS = {
amountInput: '',
usdAmountInput: '',
leverageInput: '',
targetLeverageInput: '',
balancePercentInput: '',
};

Expand Down
7 changes: 6 additions & 1 deletion src/lib/abacus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ class AbacusStateManager {

clearTradeInputSizeValues = () => {
const state = this.store?.getState();
const { needsLeverage } = (state && getInputTradeOptions(state)) ?? {};
const { needsLeverage, needsTargetLeverage } = (state && getInputTradeOptions(state)) ?? {};
const { uiRefresh } = testFlags;
this.setTradeValue({ value: null, field: TradeInputField.size });
this.setTradeValue({ value: null, field: TradeInputField.usdcSize });
this.setTradeValue({ value: null, field: TradeInputField.balancePercent });
Expand All @@ -199,6 +200,10 @@ class AbacusStateManager {
this.setTradeValue({ value: null, field: TradeInputField.leverage });
}

if (uiRefresh && needsTargetLeverage) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just clear them all the time? I worry about edge cases where target leverage is entered but then needsTargetLeverage becomes false before this clear function is called and we just leave it there forever.

Copy link
Contributor Author

@moo-onthelawn moo-onthelawn Oct 25, 2024

Choose a reason for hiding this comment

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

hm yeah I was just following the existing patterns which always seem to check but I don't seem to see any issue with removing it 🤔

this.setTradeValue({ value: null, field: TradeInputField.targetLeverage });
}

this.store?.dispatch(setTradeFormInputs(CLEARED_SIZE_INPUTS));
};

Expand Down
8 changes: 4 additions & 4 deletions src/pages/trade/TradeTableSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ export const TradeTableSettings = ({
value: MarketTypeFilter.AllMarkets,
label: stringGetter({ key: STRING_KEYS.ALL }),
},
{
value: MarketTypeFilter.Isolated,
label: stringGetter({ key: STRING_KEYS.ISOLATED }),
},
{
value: MarketTypeFilter.Cross,
label: stringGetter({ key: STRING_KEYS.CROSS }),
},
{
value: MarketTypeFilter.Isolated,
label: stringGetter({ key: STRING_KEYS.ISOLATED }),
},
]}
value={marketTypeFilter}
onValueChange={(newMarketTypeFilter: string) => {
Expand Down
18 changes: 14 additions & 4 deletions src/views/TradeBoxOrderView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback } from 'react';

import styled from 'styled-components';
import styled, { css } from 'styled-components';

import { TradeInputField } from '@/constants/abacus';
import { OnboardingState } from '@/constants/account';
Expand All @@ -14,6 +14,7 @@ import { getOnboardingState } from '@/state/accountSelectors';
import { useAppSelector } from '@/state/appTypes';

import abacusStateManager from '@/lib/abacus';
import { testFlags } from '@/lib/testFlags';

import { TradeSideTabs } from './TradeSideTabs';
import { TradeForm } from './forms/TradeForm';
Expand All @@ -33,11 +34,13 @@ export const TradeBoxOrderView = () => {
const onboardingState = useAppSelector(getOnboardingState);
const allowChangingOrderType = onboardingState === OnboardingState.AccountConnected;

const { uiRefresh } = testFlags;

return (
<TradeSideTabs
sharedContent={
<div tw="flex min-h-full flex-col">
<$MarginAndLeverageButtons openInTradeBox />
<$MarginAndLeverageButtons openInTradeBox $uiRefreshEnabled={uiRefresh} />
<$OrderTypeTabs
value={selectedTradeType}
items={tradeTypeItems}
Expand All @@ -60,8 +63,15 @@ const $Container = styled.div`
${layoutMixins.scrollArea}
`;

const $MarginAndLeverageButtons = styled(MarginAndLeverageButtons)`
padding: 0.75rem 1rem;
const $MarginAndLeverageButtons = styled(MarginAndLeverageButtons)<{ $uiRefreshEnabled: boolean }>`
${({ $uiRefreshEnabled }) =>
$uiRefreshEnabled
? css`
padding: 0 1rem;
`
: css`
padding: 0.75rem 1rem;
`};
box-shadow: inset 0 calc(-1 * var(--border-width)) var(--border-color);
`;

Expand Down
18 changes: 12 additions & 6 deletions src/views/forms/TradeForm/MarginAndLeverageButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { layoutMixins } from '@/styles/layoutMixins';
import { MarginModeSelector } from '@/views/forms/TradeForm/MarginModeSelector';
import { TargetLeverageButton } from '@/views/forms/TradeForm/TargetLeverageButton';

import { testFlags } from '@/lib/testFlags';

type ElementProps = {
openInTradeBox: boolean;
};
Expand All @@ -16,12 +18,16 @@ type StyleProps = {
export const MarginAndLeverageButtons = ({
openInTradeBox,
className,
}: ElementProps & StyleProps) => (
<$MarginAndLeverageButtons className={className}>
<MarginModeSelector openInTradeBox={openInTradeBox} />
<TargetLeverageButton />
</$MarginAndLeverageButtons>
);
}: ElementProps & StyleProps) => {
const { uiRefresh } = testFlags;

return (
<$MarginAndLeverageButtons className={className}>
<MarginModeSelector openInTradeBox={openInTradeBox} />
{!uiRefresh && <TargetLeverageButton />}
</$MarginAndLeverageButtons>
);
};

const $MarginAndLeverageButtons = styled.div`
display: flex;
Expand Down
Loading
Loading