Skip to content

Commit

Permalink
Merge pull request #313 from mstable/fix/meta-harvester-withdraw-token
Browse files Browse the repository at this point in the history
fix: Remove USDC from withdraw tokens for Meta Harvester
  • Loading branch information
dimlbc authored Jan 21, 2025
2 parents 746da80 + 250e58f commit 8db3ed3
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { MULTI_ASSET_TOKEN } from '@dhedge/core-ui-kit/const';
import { useTradingPanelModal } from '@dhedge/core-ui-kit/hooks/state';
import { TokenIconRevamp } from '@frontend/shared-ui';
import { Stack, Typography } from '@mui/material';
Expand All @@ -10,6 +11,8 @@ const formatter = new Intl.NumberFormat('en-US', {

export const TradingModalSummary: FC = () => {
const [{ action, receiveToken, sendToken }] = useTradingPanelModal();
const isMultiAssetReceiveToken =
receiveToken?.symbol === MULTI_ASSET_TOKEN.symbol;

if (action === 'approve' && sendToken) {
return (
Expand Down Expand Up @@ -43,19 +46,21 @@ export const TradingModalSummary: FC = () => {
<Typography variant="value4">{sendToken.symbol}</Typography>
</Stack>
</Stack>
<Stack direction="row" alignItems="center">
<Typography variant="body2">Receive:</Typography>
<Stack ml="auto" direction="row" alignItems="center">
<Typography variant="value4">
{formatter.format(+receiveToken.value)}
</Typography>
<TokenIconRevamp
sx={{ height: 22, width: 22, mx: 0.5 }}
symbols={[receiveToken.symbol]}
/>
<Typography variant="value4">{receiveToken.symbol}</Typography>
{!isMultiAssetReceiveToken && (
<Stack direction="row" alignItems="center">
<Typography variant="body2">Receive:</Typography>(
<Stack ml="auto" direction="row" alignItems="center">
<Typography variant="value4">
{formatter.format(+receiveToken.value)}
</Typography>
<TokenIconRevamp
sx={{ height: 22, width: 22, mx: 0.5 }}
symbols={[receiveToken.symbol]}
/>
<Typography variant="value4">{receiveToken.symbol}</Typography>
</Stack>
</Stack>
</Stack>
)}
</Stack>
);
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { forwardRef, useEffect, useState } from 'react';

import { MULTI_ASSET_TOKEN } from '@dhedge/core-ui-kit/const';
import { useLogAnalyticsEvent } from '@frontend/shared-providers';
import { PercentageButton, TokenIconRevamp } from '@frontend/shared-ui';
import { removeInsignificantTrailingZeros } from '@frontend/shared-utils';
Expand Down Expand Up @@ -57,6 +58,8 @@ const useTradingInput = ({
}: TradingInputProps) => {
const logEvent = useLogAnalyticsEvent();
const [percentage, setPercentage] = useState(0);
const isMultiAssetToken = token.symbol === MULTI_ASSET_TOKEN.symbol;
const tokenSymbol = isMultiAssetToken ? 'All Assets' : token.symbol;

const handleChange = (evt: ChangeEvent<HTMLInputElement>) => {
if (evt.target.validity.valid) {
Expand Down Expand Up @@ -104,6 +107,8 @@ const useTradingInput = ({
disabled && token.value && token.value !== '0'
? new BigNumber(token.value).toFixed(6)
: token.value,
isMultiAssetToken,
tokenSymbol,
};
};

Expand All @@ -128,6 +133,8 @@ export const TradingInput = forwardRef<HTMLInputElement, TradingInputProps>(
handlePercentageChange,
percentage,
inputTokenValue,
isMultiAssetToken,
tokenSymbol,
} = useTradingInput(props);

return (
Expand All @@ -145,7 +152,7 @@ export const TradingInput = forwardRef<HTMLInputElement, TradingInputProps>(
height={48}
sx={{ pt: '4px', pb: '5px' }}
/>
) : (
) : isMultiAssetToken ? null : (
<InputBase
inputRef={ref}
value={inputTokenValue}
Expand Down Expand Up @@ -194,19 +201,21 @@ export const TradingInput = forwardRef<HTMLInputElement, TradingInputProps>(
color: 'text.primary',
}}
>
<TokenIconRevamp
symbols={[token.symbol]}
sx={{
maxWidth: 18,
maxHeight: 18,
}}
/>
{!isMultiAssetToken && (
<TokenIconRevamp
symbols={[tokenSymbol]}
sx={{
maxWidth: 18,
maxHeight: 18,
}}
/>
)}
<Typography
variant="buttonMedium"
color="inherit"
noWrap
>
{token.symbol}
{tokenSymbol}
</Typography>
</Stack>
</MenuItem>
Expand All @@ -227,15 +236,18 @@ export const TradingInput = forwardRef<HTMLInputElement, TradingInputProps>(
width: 120,
}}
>
<TokenIconRevamp
symbols={[token.symbol]}
sx={{
maxWidth: 18,
maxHeight: 18,
}}
/>
{!isMultiAssetToken && (
<TokenIconRevamp
symbols={[tokenSymbol]}
sx={{
maxWidth: 18,
maxHeight: 18,
}}
/>
)}

<Typography variant="buttonMedium" color="inherit" noWrap>
{token.symbol}
{tokenSymbol}
</Typography>
</Stack>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { MULTI_ASSET_TOKEN } from '@dhedge/core-ui-kit/const';
import { usePoolTokenPrice } from '@dhedge/core-ui-kit/hooks/pool';
import {
useIsDepositTradingPanelType,
Expand Down Expand Up @@ -81,17 +82,22 @@ const useTradingTokensOverview = () => {
)
? poolTokenPrice
: nonPoolAssetPrice;
const isMultiAssetWithdraw = receiveToken.symbol === MULTI_ASSET_TOKEN.symbol;
const sendTokenUsdValue = new BigNumber(sendToken.value || 0)
.multipliedBy(sendTokenPrice)
.toFixed();

return {
sendToken,
receiveToken,
isDeposit,
sendTokenUsdValue: new BigNumber(sendToken.value || 0)
.multipliedBy(sendTokenPrice)
.toFixed(),
receiveTokenUsdValue: new BigNumber(receiveToken.value || 0)
.multipliedBy(receiveTokenPrice)
.toFixed(),
sendTokenUsdValue,
receiveTokenUsdValue: isMultiAssetWithdraw
? sendTokenUsdValue
: new BigNumber(receiveToken.value || 0)
.multipliedBy(receiveTokenPrice)
.toFixed(),
isMultiAssetWithdraw,
};
};

Expand All @@ -103,6 +109,7 @@ export const TradingTokensOverview: FC<StackProps> = (props) => {
isDeposit,
sendTokenUsdValue,
receiveTokenUsdValue,
isMultiAssetWithdraw,
} = useTradingTokensOverview();

return (
Expand Down Expand Up @@ -143,6 +150,8 @@ export const TradingTokensOverview: FC<StackProps> = (props) => {
<Typography variant="value5" color="text.secondary">
{receiveToken.isLoading ? (
<Skeleton width={100} />
) : isMultiAssetWithdraw ? (
'All Assets'
) : (
`≈${formatNumberToLimitedDecimals(
receiveToken.value || 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ const useTradingTransactionOverview = () => {
const logEvent = useLogAnalyticsEvent();
const [isDisclosureOpen, setIsDisclosureOpen] = useState(false);
const {
meta: { minWithdrawalUsd },
config: { address, chainId },
} = useVault();
const [{ slippage, minSlippage, isMaxSlippageLoading }] =
Expand Down Expand Up @@ -99,7 +98,6 @@ const useTradingTransactionOverview = () => {
hasMinDeposit: !!minDepositUSD && isDeposit,
minDeposit: formatToUsd({ value: minDepositUSD, minimumFractionDigits: 0 }),
lockTime,
minWithdrawalUsd,
isDisclosureOpen,
toggleDisclosureSection,
exitFee,
Expand All @@ -120,7 +118,6 @@ export const TradingTransactionOverview: FC<StackProps> = (props) => {
hasMinDeposit,
minDeposit,
lockTime,
minWithdrawalUsd,
toggleDisclosureSection,
isDisclosureOpen,
exitFee,
Expand Down Expand Up @@ -248,18 +245,6 @@ export const TradingTransactionOverview: FC<StackProps> = (props) => {
</Stack>
</CollapsibleSection>
)}
{!isDeposit && minWithdrawalUsd && (
<Typography variant="hint" color="warning.dark">
{intl.formatMessage(
{
defaultMessage:
'Due to possible high slippage on lower withdrawal amounts, please consider withdrawing a minimum of ${minWithdrawalUsd} or manually increasing the maximum slippage.',
id: 'Tp2Mnw',
},
{ minWithdrawalUsd },
)}
</Typography>
)}
</Stack>
);
};
5 changes: 1 addition & 4 deletions libs/shared/constants/src/core-vaults/optimism/mhrvst.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { optimism } from '@dhedge/core-ui-kit/const';

import { USDC_OPTIMISM } from '../../tokens';

import type { PoolConfig } from '@dhedge/core-ui-kit/types';

import type { VaultConfig } from '../../types';
Expand All @@ -14,7 +12,7 @@ export const MHRVST_OPTIMISM: PoolConfig = {
customTokens: [],
},
withdrawParams: {
customTokens: [USDC_OPTIMISM],
customTokens: [],
},
};

Expand All @@ -39,5 +37,4 @@ export const MHRVST_OPTIMISM_VAULT: VaultConfig = {
'Continuously evaluates market conditions, rebalances the allocation of funds between sub-vaults, and adjusts strategies to optimize returns.',
},
],
minWithdrawalUsd: 100,
};
1 change: 0 additions & 1 deletion libs/shared/constants/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export interface PoolConfigMeta {
strategies?: VaultStrategy[];
featured?: boolean;
primaryColor: string;
minWithdrawalUsd?: number;
}

export interface VaultStrategy {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"*.{js,jsx,ts,tsx,mdx}": "eslint --fix"
},
"dependencies": {
"@dhedge/core-ui-kit": "^0.4.7",
"@dhedge/core-ui-kit": "^0.4.8",
"@dhedge/crypto-assets": "^0.2.27",
"@emotion/react": "11.10.6",
"@emotion/styled": "11.10.6",
Expand Down
14 changes: 7 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1983,10 +1983,10 @@
enabled "2.0.x"
kuler "^2.0.0"

"@dhedge/core-ui-kit@^0.4.7":
version "0.4.7"
resolved "https://registry.yarnpkg.com/@dhedge/core-ui-kit/-/core-ui-kit-0.4.7.tgz#87bad9f22eb24d017543fe0031d1b94e9284e5ec"
integrity sha512-xB7fH+ZJ9lkHHPwJMeijyZ7zPhedDiuxGCjWGpa1a9wS+79/LuH1BSAddOJ98a7jyikhVPaL6dfIvjVAMAgu9Q==
"@dhedge/core-ui-kit@^0.4.8":
version "0.4.8"
resolved "https://registry.yarnpkg.com/@dhedge/core-ui-kit/-/core-ui-kit-0.4.8.tgz#024152d89826b17dc8ce1c727abf7220a6a3b74c"
integrity sha512-E4nLAR/f+cQts3mU2tzA5IAErNP3e7wrjt6xUmSpMM3DQhguVsiii8YXOowlRWUzFdRANXGaN1FsN8RDFGemzg==
dependencies:
"@wagmi/chains" "^0.2.25"
lodash.chunk "^4.2.0"
Expand Down Expand Up @@ -10060,9 +10060,9 @@ camelcase@^6.2.0:
integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==

caniuse-lite@^1.0.30001400:
version "1.0.30001512"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001512.tgz"
integrity sha512-2S9nK0G/mE+jasCUsMPlARhRCts1ebcp2Ji8Y8PWi4NDE1iRdLCnEPHkEfeBrGC45L4isBx5ur3IQ6yTE2mRZw==
version "1.0.30001695"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001695.tgz"
integrity sha512-vHyLade6wTgI2u1ec3WQBxv+2BrTERV28UXQu9LO6lZ9pYeMk34vjXFLOxo1A4UBA8XTL4njRQZdno/yYaSmWw==

capital-case@^1.0.4:
version "1.0.4"
Expand Down

0 comments on commit 8db3ed3

Please sign in to comment.