From b961fe3ca543149df1bd43630b70b0f29647ef38 Mon Sep 17 00:00:00 2001 From: Jan Langheimer Date: Thu, 2 Jun 2022 10:57:44 +0200 Subject: [PATCH 1/8] fix mobile --- src/elements/earn/portfolio/v3/V3Portfolio.tsx | 8 ++++++++ .../portfolio/v3/externalHoldings/externalHoldings.ts | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/elements/earn/portfolio/v3/V3Portfolio.tsx b/src/elements/earn/portfolio/v3/V3Portfolio.tsx index 7c380fd07..022ec55ab 100644 --- a/src/elements/earn/portfolio/v3/V3Portfolio.tsx +++ b/src/elements/earn/portfolio/v3/V3Portfolio.tsx @@ -11,6 +11,7 @@ import { ReactComponent as HoldingsLight } from 'assets/holdingsLight.svg'; import { ReactComponent as HoldingsDark } from 'assets/holdingsDark.svg'; import { V3Holdings } from 'elements/earn/portfolio/v3/holdings/V3Holdings'; import { useWalletConnect } from 'elements/walletConnect/useWalletConnect'; +import V3ExternalHoldings from 'elements/earn/portfolio/v3/externalHoldings/V3ExternalHoldings'; const V3Portfolio = () => { const account = useAppSelector((state) => state.user.account); @@ -55,6 +56,13 @@ const V3Portfolio = () => { + +
+

+ External Holdings +

+ +
) : ( diff --git a/src/elements/earn/portfolio/v3/externalHoldings/externalHoldings.ts b/src/elements/earn/portfolio/v3/externalHoldings/externalHoldings.ts index 85696e397..3a2445fd3 100644 --- a/src/elements/earn/portfolio/v3/externalHoldings/externalHoldings.ts +++ b/src/elements/earn/portfolio/v3/externalHoldings/externalHoldings.ts @@ -33,7 +33,7 @@ const fetchApyVisionUniswap = async ( const fetchApyVisionNonUniswap = async ( user: string ): Promise => { - const url = `https://api.apy.vision/portfolio/1/core/${user}?accessToken=${process.env.REACT_APP_APY_VISION_TOKEN}`; + const url = `https://api.apy.vision/portfolio/1/core/${user}?accessToken=${process.env.REACT_APP_APY_VISION_TOKEN}&isInWallet=true`; try { const { data } = await axios.get(url); return data.userPools; @@ -128,7 +128,7 @@ export const getExternalHoldingsNonUni = ( return ( positions // TODO Remove this filter once we support more than 2 reseves - .filter((pos) => pos.tokens.length === 2) + .filter((pos) => pos.tokens.length) .map((pos) => { const tokens = pos.tokens .map((token) => { From 0cafad2ac8e1eb2c68acd94bff7a322b7710438a Mon Sep 17 00:00:00 2001 From: Jan Langheimer Date: Thu, 2 Jun 2022 14:21:08 +0100 Subject: [PATCH 2/8] fix partial vampire attack --- .../V3ExternalHoldingsModal.tsx | 31 +++++++------------ .../v3/externalHoldings/externalHoldings.ts | 10 ++++-- .../externalHoldings.types.ts | 23 ++++++++------ 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/elements/earn/portfolio/v3/externalHoldings/V3ExternalHoldingsModal.tsx b/src/elements/earn/portfolio/v3/externalHoldings/V3ExternalHoldingsModal.tsx index 5fce1608d..3708abb95 100644 --- a/src/elements/earn/portfolio/v3/externalHoldings/V3ExternalHoldingsModal.tsx +++ b/src/elements/earn/portfolio/v3/externalHoldings/V3ExternalHoldingsModal.tsx @@ -11,6 +11,7 @@ import { useApproveModal } from 'hooks/useApproveModal'; import { mockToken } from 'utils/mocked'; import { getMigrateFnByAmmProvider } from 'elements/earn/portfolio/v3/externalHoldings/externalHoldings'; import { shrinkToken } from 'utils/formulas'; +import { ProtectedSettingsV3 } from 'components/protectedSettingsV3/ProtectedSettingsV3'; interface Props { position: ExternalHolding; @@ -27,20 +28,6 @@ export const V3ExternalHoldingsModal = ({ const account = useAppSelector((state) => state.user.account); const dispatch = useDispatch(); - const { withdrawalFee, lockDuration } = useAppSelector( - (state) => state.v3Portfolio.withdrawalSettings - ); - - const lockDurationInDays = useMemo( - () => lockDuration / 60 / 60 / 24, - [lockDuration] - ); - - const withdrawalFeeInPercent = useMemo( - () => (withdrawalFee * 100).toFixed(2), - [withdrawalFee] - ); - const tokensToApprove = useMemo( () => [ { @@ -70,7 +57,7 @@ export const V3ExternalHoldingsModal = ({ try { const res = await migrateFn( position.tokens[0].address, - position.tokens[1].address, + position.tokens[1]?.address ?? position.nonBancorTokens[0].tokenAddress, position.poolTokenBalanceWei ); await res.wait(); @@ -123,6 +110,15 @@ export const V3ExternalHoldingsModal = ({ ))} +

Exit risky position and move to your wallet

+
+ {position.nonBancorTokens.map((t) => ( +
+ {t.tokenCurrentBalance} {t.tokenName} +
+ ))} +
+ - -
- {activeIndex} of {positions.length} + {positions.length > 1 && ( +
+ + +
+ {activeIndex} of {positions.length} +
-
+ )} ) : (
diff --git a/src/elements/earn/portfolio/v3/externalHoldings/V3ExternalHoldingsModal.tsx b/src/elements/earn/portfolio/v3/externalHoldings/V3ExternalHoldingsModal.tsx index 17a0aed51..6fb623d64 100644 --- a/src/elements/earn/portfolio/v3/externalHoldings/V3ExternalHoldingsModal.tsx +++ b/src/elements/earn/portfolio/v3/externalHoldings/V3ExternalHoldingsModal.tsx @@ -17,6 +17,7 @@ import { TokenMinimal } from 'services/observables/tokens'; import { Image } from 'components/image/Image'; import { confirmMigrateExtHoldingNotification, + failedNotification, rejectNotification, } from 'services/notifications/notifications'; import { ErrorCode } from 'services/web3/types'; @@ -78,7 +79,10 @@ export const V3ExternalHoldingsModal = ({ console.error('failed to migrate position', e); if (e.code === ErrorCode.DeniedTx) { rejectNotification(dispatch); + } else { + failedNotification(dispatch, 'Migration Failed'); } + setIsOpen(false); } finally { setTxBusy(false); } diff --git a/src/elements/earn/portfolio/v3/externalHoldings/useExternalHoldings.ts b/src/elements/earn/portfolio/v3/externalHoldings/useExternalHoldings.ts index 515999eb9..d4d606d93 100644 --- a/src/elements/earn/portfolio/v3/externalHoldings/useExternalHoldings.ts +++ b/src/elements/earn/portfolio/v3/externalHoldings/useExternalHoldings.ts @@ -12,6 +12,7 @@ import { ExternalHolding, } from 'elements/earn/portfolio/v3/externalHoldings/externalHoldings.types'; import { getV3Tokens } from 'store/bancor/token'; +import { orderBy } from 'lodash'; const initialApyVisionData: ApyVisionData = { positionsUni: [], @@ -40,7 +41,7 @@ export const useExternalHoldings = () => { ); const positions: ExternalHolding[] = useMemo( - () => [...positionsUni, ...positionsNonUni], + () => orderBy([...positionsUni, ...positionsNonUni], 'usdValue', 'desc'), [positionsUni, positionsNonUni] ); diff --git a/src/services/notifications/notifications.ts b/src/services/notifications/notifications.ts index 92c6976a7..51e4b4b2a 100644 --- a/src/services/notifications/notifications.ts +++ b/src/services/notifications/notifications.ts @@ -682,3 +682,17 @@ export const confirmMigrateExtHoldingNotification = ( }, dispatch ); + +export const failedNotification = ( + dispatch: any, + title = 'Unknown Error', + msg = `Something went wrong. Please try again or contact support.` +) => + showNotification( + { + type: NotificationType.error, + title, + msg, + }, + dispatch + ); From 871a4d61287df7f1951df9d2ee7f0eab6592d954 Mon Sep 17 00:00:00 2001 From: Jan Langheimer Date: Fri, 3 Jun 2022 13:57:54 +0100 Subject: [PATCH 7/8] fix darkmode styling --- .../earn/portfolio/v3/externalHoldings/V3ExternalHoldings.tsx | 2 +- .../portfolio/v3/externalHoldings/V3ExternalHoldingsItem.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/elements/earn/portfolio/v3/externalHoldings/V3ExternalHoldings.tsx b/src/elements/earn/portfolio/v3/externalHoldings/V3ExternalHoldings.tsx index 6fcc0996c..8c16fbbc6 100644 --- a/src/elements/earn/portfolio/v3/externalHoldings/V3ExternalHoldings.tsx +++ b/src/elements/earn/portfolio/v3/externalHoldings/V3ExternalHoldings.tsx @@ -19,7 +19,7 @@ const V3ExternalHoldings = () => { return positions.length ? (

External Holdings at risk

-

+

Your holdings on other platforms are vulnerable to impermanent loss

{ : undefined; return ( -
+
Date: Wed, 8 Jun 2022 11:02:35 +0100 Subject: [PATCH 8/8] fix feedback --- .../externalHoldings/V3ExternalHoldings.tsx | 21 ++++++++----------- .../V3ExternalHoldingsItem.tsx | 5 ++++- .../V3ExternalHoldingsModal.tsx | 4 ++++ 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/elements/earn/portfolio/v3/externalHoldings/V3ExternalHoldings.tsx b/src/elements/earn/portfolio/v3/externalHoldings/V3ExternalHoldings.tsx index 8c16fbbc6..597c93303 100644 --- a/src/elements/earn/portfolio/v3/externalHoldings/V3ExternalHoldings.tsx +++ b/src/elements/earn/portfolio/v3/externalHoldings/V3ExternalHoldings.tsx @@ -1,9 +1,10 @@ -import { memo, useState } from 'react'; +import { memo } from 'react'; import V3ExternalHoldingsItem from 'elements/earn/portfolio/v3/externalHoldings/V3ExternalHoldingsItem'; import { Navigation } from 'swiper'; import { Swiper, SwiperSlide } from 'swiper/react/swiper-react'; import { NavigationOptions } from 'swiper/types'; import { useExternalHoldings } from 'elements/earn/portfolio/v3/externalHoldings/useExternalHoldings'; +import { ReactComponent as IconArrow } from 'assets/icons/arrow.svg'; const navOptions: NavigationOptions = { nextEl: '.external-holding-swiper-next-btn', @@ -13,12 +14,14 @@ const navOptions: NavigationOptions = { }; const V3ExternalHoldings = () => { - const [activeIndex, setActiveIndex] = useState(1); const { positions } = useExternalHoldings(); return positions.length ? (
-

External Holdings at risk

+

+ External Holdings at risk{' '} + ({positions.length}) +

Your holdings on other platforms are vulnerable to impermanent loss

@@ -27,9 +30,6 @@ const V3ExternalHoldings = () => { spaceBetween={20} slidesPerView={1} grabCursor - onActiveIndexChange={({ activeIndex }) => - setActiveIndex(activeIndex + 1) - } navigation={navOptions} > {positions.map((pos, i) => ( @@ -40,16 +40,13 @@ const V3ExternalHoldings = () => { {positions.length > 1 && ( -
+
-
- {activeIndex} of {positions.length} -
)}
diff --git a/src/elements/earn/portfolio/v3/externalHoldings/V3ExternalHoldingsItem.tsx b/src/elements/earn/portfolio/v3/externalHoldings/V3ExternalHoldingsItem.tsx index 8aad2a05b..11e03ac06 100644 --- a/src/elements/earn/portfolio/v3/externalHoldings/V3ExternalHoldingsItem.tsx +++ b/src/elements/earn/portfolio/v3/externalHoldings/V3ExternalHoldingsItem.tsx @@ -43,7 +43,10 @@ const V3ExternalHoldingsItem = ({ position }: Props) => {
Rekt Status:
-
{position.rektStatus}
+
+ {position.rektStatus !== 'At risk' && '-'} + {position.rektStatus} +