Skip to content

Commit

Permalink
Don't disable CTA on budget changes in edit price disposable/recurring
Browse files Browse the repository at this point in the history
  • Loading branch information
GrandSchtroumpf committed Jun 24, 2024
1 parent a788d8e commit 0b7aae3
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/components/strategies/common/BudgetDistribution.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export const BudgetDescription: FC<DescriptionProps> = (props) => {
);
}
return (
<p className="warning-message animate-scaleUp text-12 flex items-start gap-8 text-white/60">
<p className="budget-message animate-scaleUp text-12 flex items-start gap-8 text-white/60">
<span className="bg-buy/10 text-buy rounded-full p-4">
<IconDeposit className="h-12 w-12" />
</span>
Expand Down Expand Up @@ -181,7 +181,7 @@ export const BudgetDescription: FC<DescriptionProps> = (props) => {
);
}
return (
<p className="warning-message animate-scaleUp text-12 flex items-start gap-8 text-white/60">
<p className="budget-message animate-scaleUp text-12 flex items-start gap-8 text-white/60">
<span className="bg-sell/10 text-sell rounded-full p-4">
<IconWithdraw className="h-12 w-12" />
</span>
Expand Down
9 changes: 6 additions & 3 deletions src/components/strategies/common/form.module.css
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
.form:invalid button[type="submit"],
.form:has(:global(.error-message)) button[type="submit"],
.form:has(:global(.loading-message)) button[type="submit"],
.form:has(:global(.warning-message)):has(.approve-warnings input:not(:checked)) button[type="submit"] {
.form:has(:global(.warning-message)):has(.approve-warnings input:not(:checked)) button[type="submit"],
.form.overlapping:has(:global(.budget-message)):has(.approve-warnings input:not(:checked)) button[type="submit"] {
opacity: 0.4;
cursor: not-allowed;
}

.form:invalid button[type="submit"]:hover,
.form:has(:global(.error-message)) button[type="submit"]:hover {
.form:has(:global(.error-message)) button[type="submit"]:hover,
.form.overlapping:has(:global(.budget-message)) button[type="submit"]:hover {
border: none;
}

.form:has(:global(.error-message)) .approve-warnings,
.form:not(:has(:global(.warning-message))) .approve-warnings {
.form:not(.overlapping):not(:has(:global(.warning-message))) .approve-warnings,
.form.overlapping:not(:has(:global(.warning-message))):not(:has(:global(.budget-message))) .approve-warnings {
display: none;
}

6 changes: 1 addition & 5 deletions src/components/strategies/edit/EditPriceFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,8 @@ export const EditStrategyPriceField: FC<Props> = ({
const setPrice = (price: string) => setOrder({ min: price, max: price });
const setMin = (min: string) => setOrder({ min });
const setMax = (max: string) => setOrder({ max });
const setBudget = (budget: string) => {
console.log('set budget', { buy });
setOrder({ budget });
};
const setBudget = (budget: string) => setOrder({ budget });
const setAction = (action: 'deposit' | 'withdraw') => {
console.log('set action', { action, buy });
setOrder({ action, budget: undefined });
};
const setSettings = (settings: StrategySettings) => {
Expand Down
9 changes: 7 additions & 2 deletions src/components/strategies/edit/EditStrategyForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ export const EditStrategyForm: FC<Props> = (props) => {
if (!!form.querySelector('.loading-message')) return true;
if (!!form.querySelector('.error-message')) return true;
const warnings = form.querySelector('.warning-message');
if (!warnings) return false;
const budgets = form.querySelector('.budget-message');
const needApproval =
!!warnings || (!!budgets && strategyType === 'overlapping');
if (!needApproval) return false;
return !form.querySelector<HTMLInputElement>('#approve-warnings')?.checked;
};

Expand Down Expand Up @@ -199,7 +202,9 @@ export const EditStrategyForm: FC<Props> = (props) => {
<form
onSubmit={submit}
onReset={() => history.back()}
className={cn('flex flex-col gap-20 md:w-[440px]', style.form)}
className={cn('flex flex-col gap-20 md:w-[440px]', style.form, {
[style.overlapping]: strategyType === 'overlapping',
})}
data-testid="edit-form"
>
<EditPriceNav editType={editType} />
Expand Down
2 changes: 0 additions & 2 deletions src/components/strategies/overlapping/OverlappingAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ export const OverlappingAction: FC<Props> = (props) => {
return '';
})();

console.log({ anchor, action });

return (
<details open={opened.current} onToggle={onToggle}>
<summary
Expand Down
2 changes: 1 addition & 1 deletion src/pages/strategies/edit/budget/overlapping.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export const EditBudgetOverlappingPage = () => {

const hasChanged = (() => {
if (search.marketPrice) return true;
if (search.budget) return true;
if (!isZero(search.budget)) return true;
return false;
})();

Expand Down
1 change: 1 addition & 0 deletions src/pages/strategies/edit/prices/disposable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const EditStrategyDisposablePage = () => {
if (orders.buy.max !== roundSearchParam(order0.endRate)) return true;
if (orders.sell.min !== roundSearchParam(order1.startRate)) return true;
if (orders.sell.max !== roundSearchParam(order1.endRate)) return true;
if (!isZero(search.budget)) return true;
return false;
})();

Expand Down
2 changes: 1 addition & 1 deletion src/pages/strategies/edit/prices/overlapping.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export const EditStrategyOverlappingPage = () => {
if (search.min !== roundSearchParam(order0.startRate)) return true;
if (search.max !== roundSearchParam(order1.endRate)) return true;
if (search.spread !== getRoundedSpread(strategy).toString()) return true;
if (search.budget) return true;
if (!isZero(search.budget)) return true;
return false;
})();

Expand Down
7 changes: 6 additions & 1 deletion src/pages/strategies/edit/prices/recurring.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { EditStrategyPriceField } from 'components/strategies/edit/EditPriceFiel
import { StrategySettings } from 'libs/routing';
import { useMarketPrice } from 'hooks/useMarketPrice';
import { EditStrategyForm } from 'components/strategies/edit/EditStrategyForm';
import { outSideMarketWarning } from 'components/strategies/common/utils';
import {
isZero,
outSideMarketWarning,
} from 'components/strategies/common/utils';
import { useSetRecurringOrder } from 'components/strategies/common/useSetOrder';
import {
checkIfOrdersOverlap,
Expand Down Expand Up @@ -85,8 +88,10 @@ export const EditStrategyRecurringPage = () => {
const { order0, order1 } = strategy;
if (search.buyMin !== roundSearchParam(order0.startRate)) return true;
if (search.buyMax !== roundSearchParam(order0.endRate)) return true;
if (!isZero(search.buyBudget)) return true;
if (search.sellMin !== roundSearchParam(order1.startRate)) return true;
if (search.sellMax !== roundSearchParam(order1.endRate)) return true;
if (!isZero(search.sellBudget)) return true;
return false;
})();

Expand Down

0 comments on commit 0b7aae3

Please sign in to comment.