From 67ffbfa3b08b6fcdcaa207d9f6e0f30464b2eec3 Mon Sep 17 00:00:00 2001 From: Igor Prokopev Date: Mon, 21 Nov 2022 10:25:32 +0400 Subject: [PATCH] NDEV-830. Upgraded Wormhole portal for Neon transfer --- .gitignore | 3 +- src/components/FeeMethodSelector.tsx | 135 +++++++++++++++++---------- src/components/Transfer/Redeem.tsx | 5 +- src/hooks/useHandleRedeem.tsx | 17 +++- src/hooks/useNeonRelayerInfo.ts | 88 +++++++++++++++++ src/store/selectors.ts | 9 +- src/store/transferSlice.ts | 33 ++++++- src/utils/consts.ts | 9 +- 8 files changed, 241 insertions(+), 58 deletions(-) create mode 100644 src/hooks/useNeonRelayerInfo.ts diff --git a/.gitignore b/.gitignore index a6d38d4..2be5a38 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ # dependencies /node_modules +.idea /.pnp .pnp.js @@ -24,4 +25,4 @@ yarn-error.log* # ethereum contracts /contracts -/src/ethers-contracts \ No newline at end of file +/src/ethers-contracts diff --git a/src/components/FeeMethodSelector.tsx b/src/components/FeeMethodSelector.tsx index f349e46..aa97e62 100644 --- a/src/components/FeeMethodSelector.tsx +++ b/src/components/FeeMethodSelector.tsx @@ -1,6 +1,7 @@ import { CHAIN_ID_ACALA, CHAIN_ID_KARURA, + CHAIN_ID_NEON, CHAIN_ID_TERRA, hexToNativeAssetString, isEVMChain, @@ -32,6 +33,7 @@ import { } from "../store/selectors"; import { setRelayerFee, setUseRelayer } from "../store/transferSlice"; import { CHAINS_BY_ID, getDefaultNativeCurrencySymbol } from "../utils/consts"; +import { useNeonRelayerInfo } from "../hooks/useNeonRelayerInfo"; const useStyles = makeStyles((theme) => ({ feeSelectorContainer: { @@ -107,6 +109,11 @@ function FeeMethodSelector() { vaaNormalizedAmount, originChain ? hexToNativeAssetString(originAsset, originChain) : undefined ); + const neonRelayerInfo = useNeonRelayerInfo( + targetChain, + vaaNormalizedAmount, + originChain ? hexToNativeAssetString(originAsset, originChain) : undefined + ); const sourceChain = useSelector(selectTransferSourceChain); const dispatch = useDispatch(); const relayerSelected = !!useSelector(selectTransferUseRelayer); @@ -123,6 +130,9 @@ function FeeMethodSelector() { targetChain === CHAIN_ID_ACALA || targetChain === CHAIN_ID_KARURA; const acalaRelayerEligible = acalaRelayerInfo.data?.shouldRelay; + const targetIsNeon = targetChain === CHAIN_ID_NEON; + const neonRelayerEligible = neonRelayerInfo.data?.shouldRelay; + const chooseAcalaRelayer = useCallback(() => { if (targetIsAcala && acalaRelayerEligible) { dispatch(setUseRelayer(true)); @@ -130,6 +140,13 @@ function FeeMethodSelector() { } }, [dispatch, targetIsAcala, acalaRelayerEligible]); + const chooseNeonRelayer = useCallback(() => { + if (targetIsNeon && neonRelayerEligible) { + dispatch(setUseRelayer(true)); + dispatch(setRelayerFee(undefined)); + } + }, [dispatch, targetIsNeon, neonRelayerEligible]); + const chooseRelayer = useCallback(() => { if (relayerEligible) { dispatch(setUseRelayer(true)); @@ -149,66 +166,84 @@ function FeeMethodSelector() { } else { chooseManual(); } + } else if (targetIsNeon) { + if (neonRelayerEligible) { + chooseNeonRelayer(); + } else { + chooseManual(); + } } else if (relayerInfo.data?.isRelayable === true) { chooseRelayer(); } else if (relayerInfo.data?.isRelayable === false) { chooseManual(); } //If it's undefined / null it's still loading, so no action is taken. - }, [ - relayerInfo, + }, [relayerInfo, chooseRelayer, chooseManual, targetIsAcala, acalaRelayerEligible, chooseAcalaRelayer, - ]); + targetIsNeon, + neonRelayerEligible, + chooseNeonRelayer]); - const acalaRelayerContent = ( - -
- -
- {acalaRelayerEligible ? ( -
- - {CHAINS_BY_ID[targetChain].name} - - - {CHAINS_BY_ID[targetChain].name} pays gas for you 🎉 - -
- ) : ( - <> - - {"Automatic redeem is unavailable for this token."} - -
- - )} + const relayerContentFactory = (relayerEligible: any, chooseRelayer: any) => { + return ( + +
+ +
+ {relayerEligible ? ( + <> + + {CHAINS_BY_ID[targetChain].name} + + + {CHAINS_BY_ID[targetChain].name} pays gas for you 🎉 + + + ) : ( + <> + + {"Automatic redeem is unavailable for this token."} + +
+ + )} +
-
- {acalaRelayerEligible ? ( - <> -
-
- - ) : null} -
+ {relayerEligible ? ( + <> +
+
+ + ) : null} + + ); + }; + + const acalaRelayerContent = relayerContentFactory( + acalaRelayerEligible, + chooseAcalaRelayer + ); + const neonRelayerContent = relayerContentFactory( + neonRelayerEligible, + chooseNeonRelayer ); const relayerContent = ( @@ -323,7 +358,11 @@ function FeeMethodSelector() { > How would you like to pay the target chain fees? - {targetIsAcala ? acalaRelayerContent : relayerContent} + {targetIsAcala + ? acalaRelayerContent + : targetIsNeon + ? neonRelayerContent + : relayerContent} {manualRedeemContent}
); diff --git a/src/components/Transfer/Redeem.tsx b/src/components/Transfer/Redeem.tsx index 1cd49a3..7d7f16c 100644 --- a/src/components/Transfer/Redeem.tsx +++ b/src/components/Transfer/Redeem.tsx @@ -92,7 +92,9 @@ function Redeem() { }, [useRelayer]); const targetChain = useSelector(selectTransferTargetChain); const targetIsAcala = - targetChain === CHAIN_ID_ACALA || targetChain === CHAIN_ID_KARURA; + targetChain === CHAIN_ID_ACALA || + targetChain === CHAIN_ID_KARURA || + targetChain === CHAIN_ID_NEON; const targetAsset = useSelector(selectTransferTargetAsset); const isRecovery = useSelector(selectTransferIsRecovery); const { isTransferCompletedLoading, isTransferCompleted } = @@ -273,7 +275,6 @@ function Redeem() { - {useRelayer && !isTransferCompleted ? (