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

SOV-3408: MM Maintenance state Integration #699

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export const PoolsTable: FC = () => {
),
[],
);
const generateExpandedContent = useCallback(
(pool: AmmLiquidityPool) => <PoolsStatistics pool={pool} />,
[],
);

return (
<div className="bg-gray-90 py-4 px-4 rounded w-full mt-8">
Expand All @@ -39,10 +43,9 @@ export const PoolsTable: FC = () => {
loadingData={t(translations.common.tables.loading)}
dataAttribute="amm-pool-table"
expandedClassNames="border border-gray-70 border-t-0"
expandedContent={(pool: AmmLiquidityPool) => (
<PoolsStatistics pool={pool} />
)}
expandedContent={generateExpandedContent}
rowTitle={generateRowTitle}
preventExpandOnClickClass="prevent-row-click"
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import React, { FC, useCallback, useState } from 'react';
import React, { FC, useCallback, useMemo, useState } from 'react';

import { t } from 'i18next';

import { ButtonStyle, ButtonSize, Button } from '@sovryn/ui';
import {
ButtonStyle,
ButtonSize,
Button,
Tooltip,
TooltipTrigger,
} from '@sovryn/ui';
import { Decimal } from '@sovryn/utils';

import { useAccount } from '../../../../../../../hooks/useAccount';
import { useMaintenance } from '../../../../../../../hooks/useMaintenance';
import { translations } from '../../../../../../../locales/i18n';
import { useCheckPoolMaintenance } from '../../../../hooks/useCheckPoolMaintenance';
import { useGetUserInfo } from '../../../../hooks/useGetUserInfo';
import { AmmLiquidityPool } from '../../../../utils/AmmLiquidityPool';
import { AdjustAndDepositModal } from '../../../AdjustAndDepositModal/AdjustAndDepositModal';
Expand All @@ -17,20 +25,35 @@ type PoolsTableActionProps = {

export const PoolsTableAction: FC<PoolsTableActionProps> = ({ pool }) => {
const { account } = useAccount();

const { checkMaintenance, States } = useMaintenance();
const poolLocked = useCheckPoolMaintenance(pool);

const { balanceA: poolBalance } = useGetUserInfo(pool);

const [isModalOpen, setIsModalOpen] = useState(false);
const [isInitialDeposit, setIsInitialDeposit] = useState(true);

const actionLocked = useMemo(
() => checkMaintenance(States.D2_MARKET_MAKING_FULL) || poolLocked,
[States.D2_MARKET_MAKING_FULL, checkMaintenance, poolLocked],
);

const handleDepositClick = useCallback(() => {
if (actionLocked) {
return;
}
setIsInitialDeposit(true);
setIsModalOpen(true);
}, []);
}, [actionLocked]);

const handleAdjustClick = useCallback(() => {
if (actionLocked) {
return;
}
setIsInitialDeposit(false);
setIsModalOpen(true);
}, []);
}, [actionLocked]);

const handleClose = useCallback(() => {
setIsInitialDeposit(true);
Expand All @@ -39,27 +62,38 @@ export const PoolsTableAction: FC<PoolsTableActionProps> = ({ pool }) => {

return (
<div className="flex items-center justify-center lg:justify-end">
{!account || poolBalance.lte(Decimal.ZERO) ? (
<Button
style={ButtonStyle.primary}
size={ButtonSize.small}
text={t(translations.common.deposit)}
dataAttribute="pools-table-deposit-button"
className="w-full lg:w-auto prevent-row-click"
disabled={!account}
onClick={handleDepositClick}
/>
) : (
<Button
style={ButtonStyle.secondary}
size={ButtonSize.small}
text={t(translations.common.adjust)}
dataAttribute="pools-table-adjust-button"
className="w-full lg:w-auto prevent-row-click"
disabled={!account}
onClick={handleAdjustClick}
/>
)}
<Tooltip
trigger={TooltipTrigger.click}
content={<>{t(translations.maintenanceMode.featureDisabled)}</>}
disabled={!actionLocked}
children={
<div>
{!account || poolBalance.lte(Decimal.ZERO) ? (
<Button
style={ButtonStyle.primary}
size={ButtonSize.small}
text={t(translations.common.deposit)}
dataAttribute="pools-table-deposit-button"
className="w-full lg:w-auto prevent-row-click"
disabledStyle={actionLocked}
disabled={!account}
onClick={handleDepositClick}
/>
) : (
<Button
style={ButtonStyle.secondary}
size={ButtonSize.small}
text={t(translations.common.adjust)}
dataAttribute="pools-table-adjust-button"
className="w-full lg:w-auto prevent-row-click"
disabledStyle={actionLocked}
disabled={!account}
onClick={handleAdjustClick}
/>
)}
</div>
}
/>

<AdjustAndDepositModal
isOpen={isModalOpen}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { useMemo } from 'react';

import { SupportedTokens } from '@sovryn/contracts';

import { useMaintenance } from '../../../../hooks/useMaintenance';
import { AmmLiquidityPool } from '../utils/AmmLiquidityPool';

export const useCheckPoolMaintenance = (pool: AmmLiquidityPool) => {
const { States, checkMaintenance } = useMaintenance();

return useMemo(() => {
switch (pool.assetA) {
case SupportedTokens.dllr:
return checkMaintenance(States.D2_MARKET_MAKING_DLLR);
case SupportedTokens.fish:
return checkMaintenance(States.D2_MARKET_MAKING_FISH);
case SupportedTokens.moc:
return checkMaintenance(States.D2_MARKET_MAKING_MOC);
case SupportedTokens.mynt:
return checkMaintenance(States.D2_MARKET_MAKING_MYNT);
case SupportedTokens.rif:
return checkMaintenance(States.D2_MARKET_MAKING_RIF);
case SupportedTokens.sov:
return checkMaintenance(States.D2_MARKET_MAKING_SOV);
default:
return false;
}
}, [
States.D2_MARKET_MAKING_DLLR,
States.D2_MARKET_MAKING_FISH,
States.D2_MARKET_MAKING_MOC,
States.D2_MARKET_MAKING_MYNT,
States.D2_MARKET_MAKING_RIF,
States.D2_MARKET_MAKING_SOV,
checkMaintenance,
pool.assetA,
]);
};
8 changes: 8 additions & 0 deletions apps/frontend/src/hooks/useMaintenance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ enum States {
D2_BORROW_BPRO_EXTEND = 'd2BorrowBPROxExtend',
D2_BORROW_BPRO_ADD_COLLATERAL = 'd2BorrowBPROxAddCollateral',
D2_BORROW_BPRO_WITHDRAW_COLLATERAL = 'd2BorrowBPROxWithdrawCollateral',

D2_MARKET_MAKING_FULL = 'marketMakingFull',
D2_MARKET_MAKING_DLLR = 'marketMakingDLLR',
D2_MARKET_MAKING_SOV = 'marketMakingSOV',
D2_MARKET_MAKING_FISH = 'marketMakingFISH',
D2_MARKET_MAKING_MOC = 'marketMakingMOC',
D2_MARKET_MAKING_RIF = 'marketMakingRIF',
D2_MARKET_MAKING_MYNT = 'marketMakingMYNT',
}

type MaintenanceResult = {
Expand Down
6 changes: 4 additions & 2 deletions packages/ui/src/1_atoms/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface IButtonProps {
size?: ButtonSize;
style?: ButtonStyle;
disabled?: boolean;
disabledStyle?: boolean;
loading?: boolean;
className?: string;
dataAttribute?: string;
Expand All @@ -40,6 +41,7 @@ export const Button = forwardRef<
style = ButtonStyle.primary,
type = ButtonType.button,
disabled,
disabledStyle,
loading,
className,
dataAttribute,
Expand All @@ -54,10 +56,10 @@ export const Button = forwardRef<
styles[size],
styles[style],
styles[type],
disabled && styles.disabled,
(disabled || disabledStyle) && styles.disabled,
className,
),
[loading, size, style, type, disabled, className],
[loading, size, style, type, disabled, disabledStyle, className],
);

const onClickHandler = useMemo(
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4616,10 +4616,10 @@
joi "^17.6.0"
rxjs "7.5.6"

"@sovryn/[email protected].3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@sovryn/onboard-injected/-/onboard-injected-1.0.3.tgz#57446a8cda069f4acbebfff53c39de5dcd411187"
integrity sha512-JEssDH4cdMTCAlErNWjrcZe71u6ZBd6HdftgI2SBur6AL1HMFQ8PhgfS/N968zektAX8LoTOd9HYbBMTjn2sLQ==
"@sovryn/[email protected].4":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@sovryn/onboard-injected/-/onboard-injected-1.0.4.tgz#9e373c53a367293b9457519af08f9f2def18fb43"
integrity sha512-aJ5/aP+UM3uaDoNt8ZQusnP/RU7rlLNPj1+DaBvmWjPke30Rq7nnvQEkWxl5+j36MEt2J2wH+AD6+lkH0Uh1zw==
dependencies:
"@sovryn/onboard-common" "1.0.0"
ethers "^5.7.0"
Expand Down