Skip to content
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
6 changes: 3 additions & 3 deletions src/components/Elixir/AddLiquidity/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,10 @@ const AddLiquidity: React.FC<AddLiquidityProps> = (props) => {
<Box display="flex" justifyContent="center" alignItems="center">
<Text fontSize={14} style={{ fontWeight: 500 }} textAlign="left" color="text1">
{invertPrice
? price?.invert()?.toSignificant(24).substring(0, 24)
: price?.toSignificant(24).substring(0, 24)}
? price?.invert()?.toSignificant(12).substring(0, 12)
: price?.toSignificant(12).substring(0, 12)}
</Text>{' '}
<span style={{ marginLeft: '4px' }}>{currency1?.symbol}</span>
<span style={{ fontSize: '14px', marginLeft: '4px' }}>{currency1?.symbol}</span>
</Box>
) : (
'-'
Expand Down
178 changes: 95 additions & 83 deletions src/components/Elixir/DetailModal/EarnWidget/Remove/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Percent } from '@pangolindex/sdk';
import mixpanel from 'mixpanel-browser';
import React, { useState } from 'react';
import React, { useContext, useState } from 'react';
import { AlertTriangle } from 'react-feather';
import { useTranslation } from 'react-i18next';
import { ThemeContext } from 'styled-components';
import { Box, Button, Loader, NumberOptions, Text, TextInput, TransactionCompleted } from 'src/components';
import { useChainId, useLibrary, usePangolinWeb3 } from 'src/hooks';
import { MixPanelEvents } from 'src/hooks/mixpanel';
Expand All @@ -10,7 +12,7 @@ import { useWalletModalToggle } from 'src/state/papplication/hooks';
import { useElixirRemoveLiquidityHook } from 'src/state/pburn/elixir';
import { useDerivedBurnInfo } from 'src/state/pburn/elixir/common';
import { useUserSlippageTolerance } from 'src/state/puser/hooks';
import { ButtonWrapper, RemoveLiquidityWrapper, RemoveWrapper } from './styles';
import { BlackWrapper, ButtonWrapper, ErrorBox, ErrorWrapper, RemoveWrapper } from './styles';
import { RemoveProps } from './types';

const Remove = ({ position }: RemoveProps) => {
Expand All @@ -20,12 +22,15 @@ const Remove = ({ position }: RemoveProps) => {
const toggleWalletModal = useWalletModalToggle();
const [hash, setHash] = useState<string | undefined>();
const [attempting, setAttempting] = useState<boolean>(false);
const [error, setError] = useState<string | undefined>();
function wrappedOnDismiss() {
setHash(undefined);
setAttempting(false);
setError(undefined);
}
const { t } = useTranslation();
const [percentage, setPercentage] = useState<number>(4);
const theme = useContext(ThemeContext);

const {
position: positionSDK,
Expand All @@ -34,7 +39,6 @@ const Remove = ({ position }: RemoveProps) => {
liquidityValue1,
feeValue0,
feeValue1,
removed,
} = useDerivedBurnInfo(position, percentage);

const [userSlippage] = useUserSlippageTolerance();
Expand Down Expand Up @@ -77,15 +81,17 @@ const Remove = ({ position }: RemoveProps) => {

setHash(removeLiqResponse?.hash as string);

mixpanel.track(MixPanelEvents.REMOVE_LIQUIDITY, {
chainId: chainId,
token0: liquidityValue0?.currency?.symbol,
token1: liquidityValue1?.currency?.symbol,
tokenId: position?.tokenId,
});
if (removeLiqResponse?.hash) {
mixpanel.track(MixPanelEvents.REMOVE_LIQUIDITY, {
chainId: chainId,
token0: liquidityValue0?.currency?.symbol,
token1: liquidityValue1?.currency?.symbol,
tokenId: position?.tokenId,
});
}
} catch (err) {
const _err = err as any;

const _err = typeof err === 'string' ? new Error(err) : (err as any);
setError(_err?.message);
console.error(_err);
} finally {
setAttempting(false);
Expand Down Expand Up @@ -119,88 +125,94 @@ const Remove = ({ position }: RemoveProps) => {
);
};

const removeLiquidityContent = () => {
return (
<RemoveLiquidityWrapper>
{!attempting && !hash && (
<>
<Box flex={1}>
<Box>
<Box display="flex" flexDirection="column" style={{ gap: '12px' }}>
<TextInput
addonAfter={
<Box display="flex" alignItems="center">
<Text color="text4" fontSize={[24, 18]}>
{liquidityValue0?.currency?.symbol}
</Text>
</Box>
}
disabled
value={liquidityValue0 ? parseFloat(liquidityValue0.toSignificant(6)) / 100 : '-'} // We divide by 100 to get the correct value, because of the percentage
fontSize={24}
isNumeric={true}
placeholder="0.00"
return (
<RemoveWrapper>
{!attempting && !hash && !error && (
<>
<Box flex={1}>
<Box>
<Box display="flex" flexDirection="column" style={{ gap: '12px' }}>
<TextInput
addonAfter={
<Box display="flex" alignItems="center">
<Text color="text4" fontSize={[24, 18]}>
{liquidityValue0?.currency?.symbol}
</Text>
</Box>
}
disabled
value={liquidityValue0 ? parseFloat(liquidityValue0.toSignificant(6)) / 100 : '-'} // We divide by 100 to get the correct value, because of the percentage
fontSize={24}
isNumeric={true}
placeholder="0.00"
/>
<TextInput
addonAfter={
<Box display="flex" alignItems="center">
<Text color="text4" fontSize={[24, 18]}>
{liquidityValue1?.currency?.symbol}
</Text>
</Box>
}
value={liquidityValue1 ? parseFloat(liquidityValue1.toSignificant(6)) / 100 : '-'} // We divide by 100 to get the correct value, because of the percentage
disabled
fontSize={24}
isNumeric={true}
placeholder="0.00"
/>

<Box my="5px">
<NumberOptions
onChange={(value) => {
setPercentage(value);
}}
currentValue={percentage}
variant="step"
isPercentage={true}
/>
<TextInput
addonAfter={
<Box display="flex" alignItems="center">
<Text color="text4" fontSize={[24, 18]}>
{liquidityValue1?.currency?.symbol}
</Text>
</Box>
}
value={liquidityValue1 ? parseFloat(liquidityValue1.toSignificant(6)) / 100 : '-'} // We divide by 100 to get the correct value, because of the percentage
disabled
fontSize={24}
isNumeric={true}
placeholder="0.00"
/>

<Box my="5px">
<NumberOptions
onChange={(value) => {
setPercentage(value);
}}
currentValue={percentage}
variant="step"
isPercentage={true}
/>
</Box>
</Box>
</Box>
</Box>
<Box mt={0}>{renderButton()}</Box>
</>
)}

{attempting && !hash && <Loader size={100} label={`${t('common.removingLiquidity')}...`} />}
{hash && (
</Box>
<Box mt={0}>{renderButton()}</Box>
</>
)}

{error && (
<BlackWrapper>
<ErrorWrapper>
<ErrorBox>
<AlertTriangle color={theme.red1} style={{ strokeWidth: 1.5 }} size={64} />
<Text fontWeight={500} fontSize={16} color={'red1'} textAlign="center" style={{ width: '85%' }}>
{error}
</Text>
</ErrorBox>
<Button variant="primary" onClick={wrappedOnDismiss}>
Comment thread
SarjuHansaliya marked this conversation as resolved.
{t('transactionConfirmation.dismiss')}
</Button>
</ErrorWrapper>
</BlackWrapper>
)}

{attempting && !hash && !error && (
<BlackWrapper>
<Loader size={100} label={`${t('common.removingLiquidity')}...`} />
</BlackWrapper>
)}

{hash && (
<BlackWrapper>
<TransactionCompleted
rootStyle={{ width: '100%' }}
buttonText={t('common.close')}
submitText={t('common.removedLiquidity')}
isShowButtton={true}
onButtonClick={wrappedOnDismiss}
/>
)}
</RemoveLiquidityWrapper>
);
};

const renderRemoveContent = () => {
if (!removed) {
return removeLiquidityContent();
} else {
return (
<Box display="flex" justifyContent="center" alignItems="center" height="100%">
<Text color="text2" fontSize={16} fontWeight={500} textAlign="center">
{t('common.noLiquidity')}
</Text>
</Box>
);
}
};

return <RemoveWrapper>{renderRemoveContent()}</RemoveWrapper>;
</BlackWrapper>
)}
</RemoveWrapper>
);
};

export default Remove;
35 changes: 30 additions & 5 deletions src/components/Elixir/DetailModal/EarnWidget/Remove/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,42 @@ export const RemoveWrapper = styled(Box)`
}
`;

export const RemoveLiquidityWrapper = styled(Box)`
export const ButtonWrapper = styled(Box)`
justify-content: space-between;
width: 100%;
display: flex;
padding: 0;
align-items: center;
`;

export const BlackWrapper = styled(Box)`
flex: 1;
width: 100%;
height: 100%;
display: flex;
padding: 20px 30px;
flex-direction: column;
z-index: 999;
position: absolute;
align-items: center;
pointer-events: all;
justify-content: center;
right: 0;
top: 0;
background-color: ${({ theme }) => theme.bg2};
`;

export const ButtonWrapper = styled(Box)`
justify-content: space-between;
width: 100%;
export const ErrorWrapper = styled(Box)`
display: grid;
grid-template-rows: minmax(100px, auto) max-content;
height: 100%;
padding: 10px;
`;

export const ErrorBox = styled(Box)`
display: flex;
padding: 0;
width: 100%;
align-items: center;
justify-content: center;
flex-direction: column;
`;
Loading