Skip to content

Commit

Permalink
feat: support not pmm pool
Browse files Browse the repository at this point in the history
  • Loading branch information
junjieit committed Dec 6, 2024
1 parent 067156d commit 8a785d5
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 30 deletions.
1 change: 1 addition & 0 deletions packages/dodoex-widgets/src/components/Widget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export interface WidgetProps
name: string;
logoUrl?: string;
};
notSupportPMM?: boolean;
supportAMMV2?: boolean;
supportAMMV3?: boolean;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,8 @@ export default function AddLiquidityList({
setOperatePool: (operate: Partial<PoolOperateProps> | null) => void;
}) {
const theme = useTheme();
const { onlyChainId, supportAMMV2, supportAMMV3 } = useUserOptions();
const { onlyChainId, supportAMMV2, supportAMMV3, notSupportPMM } =
useUserOptions();
const { minDevice, isMobile } = useWidgetDevice();
const queryClient = useQueryClient();

Expand All @@ -719,8 +720,7 @@ export default function AddLiquidityList({
handleChangeFilterAddress,
} = usePoolListFilterTokenAndPool();

const filterTypes = ['CLASSICAL', 'DVM', 'DSP', 'GSP'];
// const filterTypes = [];
const filterTypes = notSupportPMM ? [] : ['CLASSICAL', 'DVM', 'DSP', 'GSP'];
if (supportAMMV2) {
filterTypes.push('AMMV2');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,8 @@ export default function MyLiquidity({
const theme = useTheme();
const { minDevice, isMobile } = useWidgetDevice();
const queryClient = useQueryClient();
const { onlyChainId, supportAMMV2, supportAMMV3 } = useUserOptions();
const { onlyChainId, supportAMMV2, supportAMMV3, notSupportPMM } =
useUserOptions();
const [onlyV3, setOnlyV3] = React.useState(false);

const {
Expand All @@ -1148,17 +1149,27 @@ export default function MyLiquidity({
handleChangeFilterAddress,
} = usePoolListFilterTokenAndPool();

let filterTypes: PoolType[] = notSupportPMM
? []
: ['CLASSICAL', 'DVM', 'DSP', 'GSP'];
if (supportAMMV2) {
filterTypes.push('AMMV2');
}
if (supportAMMV3) {
if (onlyV3) {
filterTypes = ['AMMV3'];
} else {
filterTypes.push('AMMV3');
}
}

const defaultQueryFilter = {
currentPage: 1,
pageSize: 1000,
user: account,
filterState: {
viewOnlyOwn: true,
filterTypes: supportAMMV3
? onlyV3
? ['AMMV3']
: ['CLASSICAL', 'DVM', 'DSP', 'GSP', 'AMMV2']
: undefined,
filterTypes,
},
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Box, BoxProps, ButtonBase, useTheme } from '@dodoex/components';
import { t } from '@lingui/macro';
import { useUserOptions } from '../../../../components/UserOptionsProvider';

export interface OnlyV3ToggleProps {
onlyV3: boolean;
Expand All @@ -9,6 +10,7 @@ export interface OnlyV3ToggleProps {

export const OnlyV3Toggle = ({ onlyV3, setOnlyV3, sx }: OnlyV3ToggleProps) => {
const theme = useTheme();
const { notSupportPMM } = useUserOptions();

return (
<Box
Expand Down Expand Up @@ -67,7 +69,7 @@ export const OnlyV3Toggle = ({ onlyV3, setOnlyV3, sx }: OnlyV3ToggleProps) => {
}),
}}
>
{t`V2 & PMM`}
{notSupportPMM ? 'V2' : t`V2 & PMM`}
</Box>
</Box>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,23 @@ export function usePoolListTabs({
}) {
const { i18n } = useLingui();
const [poolTab, setPoolTab] = React.useState(PoolTab.addLiquidity);
const { supportAMMV2, supportAMMV3 } = useUserOptions();
const tabs = React.useMemo(
() => [
const { supportAMMV2, supportAMMV3, notSupportPMM } = useUserOptions();
const tabs = React.useMemo(() => {
const result = [
{ key: PoolTab.addLiquidity, value: t`Add Liquidity` },
{
key: PoolTab.myLiquidity,
value: t`My Liquidity`,
},
{
];
if (!notSupportPMM) {
result.push({
key: PoolTab.myCreated,
value: supportAMMV2 || supportAMMV3 ? t`My Pools (PMM)` : t`My Pools`,
},
],
[i18n._, supportAMMV2, supportAMMV3],
);
});
}
return result;
}, [i18n._, supportAMMV2, supportAMMV3, notSupportPMM]);

const isSetPoolTabCache = React.useRef(false);
React.useEffect(() => {
Expand Down
39 changes: 27 additions & 12 deletions packages/dodoex-widgets/src/widgets/PoolWidget/PoolList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default function PoolList({
const theme = useTheme();
const { isMobile } = useWidgetDevice();
const noDocumentLink = useUserOptions((state) => state.noDocumentLink);
const { supportAMMV2, supportAMMV3 } = useUserOptions();
const { supportAMMV2, supportAMMV3, notSupportPMM } = useUserOptions();
const scrollParentRef = React.useRef<HTMLDivElement>(null);
const { account } = useWeb3React();
const { poolTab, tabs, handleChangePoolTab } = usePoolListTabs({
Expand All @@ -120,6 +120,19 @@ export default function PoolList({
const [operatePool, setOperatePool] =
React.useState<Partial<PoolOperateProps> | null>(null);

const poolTypeSupportObject = {
[PageType.CreatePool]: !notSupportPMM,
[PageType.createPoolAMMV2]: !!supportAMMV2,
[PageType.createPoolAMMV3]: !!supportAMMV3,
};
const activePoolTypes = Object.entries(poolTypeSupportObject).filter(
([_, value]) => value === true,
);
const singleActiveCreatePoolType =
activePoolTypes.length === 1
? (activePoolTypes[0][0] as PageType)
: undefined;

return (
<WidgetContainer
sx={{
Expand Down Expand Up @@ -188,7 +201,7 @@ export default function PoolList({
}
}
/>
{supportAMMV2 || supportAMMV3 ? (
{!singleActiveCreatePoolType ? (
<Tooltip
arrow={false}
leaveDelay={300}
Expand All @@ -198,15 +211,17 @@ export default function PoolList({
}}
title={
<Box>
<CreateItem
onClick={() => {
useRouterStore.getState().push({
type: PageType.CreatePool,
});
}}
title={<Trans>PMM Pool</Trans>}
desc={<Trans>Description of this type of pool</Trans>}
/>
{!notSupportPMM && (
<CreateItem
onClick={() => {
useRouterStore.getState().push({
type: PageType.CreatePool,
});
}}
title={<Trans>PMM Pool</Trans>}
desc={<Trans>Description of this type of pool</Trans>}
/>
)}
{supportAMMV2 && (
<CreateItem
onClick={() => {
Expand Down Expand Up @@ -264,7 +279,7 @@ export default function PoolList({
fullWidth={isMobile}
onClick={() => {
useRouterStore.getState().push({
type: PageType.CreatePool,
type: singleActiveCreatePoolType,
});
}}
sx={{
Expand Down

0 comments on commit 8a785d5

Please sign in to comment.