From c2a879ec7cbafffe9e2d4c037a78123f7d0f7df2 Mon Sep 17 00:00:00 2001 From: Evan Gray Date: Sat, 22 Jan 2022 16:00:17 +0000 Subject: [PATCH] bridge_ui: solana tps warning --- bridge_ui/src/components/NFT/Redeem.tsx | 4 +- bridge_ui/src/components/NFT/Send.tsx | 4 +- bridge_ui/src/components/NFT/Source.tsx | 2 + bridge_ui/src/components/NFT/Target.tsx | 2 + bridge_ui/src/components/SolanaTPSWarning.tsx | 53 +++++++++++++++++++ bridge_ui/src/components/Transfer/Redeem.tsx | 2 + bridge_ui/src/components/Transfer/Send.tsx | 8 ++- .../Transfer/SendConfirmationDialog.tsx | 4 +- bridge_ui/src/components/Transfer/Source.tsx | 2 + bridge_ui/src/components/Transfer/Target.tsx | 2 + 10 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 bridge_ui/src/components/SolanaTPSWarning.tsx diff --git a/bridge_ui/src/components/NFT/Redeem.tsx b/bridge_ui/src/components/NFT/Redeem.tsx index 94ad98f40..348cd6426 100644 --- a/bridge_ui/src/components/NFT/Redeem.tsx +++ b/bridge_ui/src/components/NFT/Redeem.tsx @@ -1,10 +1,11 @@ -import { CHAIN_ID_TERRA } from "@certusone/wormhole-sdk"; +import { CHAIN_ID_SOLANA, CHAIN_ID_TERRA } from "@certusone/wormhole-sdk"; import { useSelector } from "react-redux"; import { useHandleNFTRedeem } from "../../hooks/useHandleNFTRedeem"; import useIsWalletReady from "../../hooks/useIsWalletReady"; import { selectNFTTargetChain } from "../../store/selectors"; import ButtonWithLoader from "../ButtonWithLoader"; import KeyAndBalance from "../KeyAndBalance"; +import SolanaTPSWarning from "../SolanaTPSWarning"; import StepDescription from "../StepDescription"; import TerraFeeDenomPicker from "../TerraFeeDenomPicker"; import WaitingForWalletMessage from "./WaitingForWalletMessage"; @@ -20,6 +21,7 @@ function Redeem() { {targetChain === CHAIN_ID_TERRA && ( )} + {targetChain === CHAIN_ID_SOLANA && } + {sourceChain === CHAIN_ID_SOLANA && } ) : null} + {sourceChain === CHAIN_ID_SOLANA && } ({ @@ -136,6 +137,7 @@ function Target() { )} + {targetChain === CHAIN_ID_SOLANA && } ({ + alert: { + marginTop: theme.spacing(1), + marginBottom: theme.spacing(1), + }, +})); + +export default function SolanaTPSWarning() { + const classes = useStyles(); + const [tps, setTps] = useState(null); + useEffect(() => { + let cancelled = false; + let interval = setInterval(() => { + (async () => { + try { + const connection = new Connection(SOLANA_HOST); + const samples = await connection.getRecentPerformanceSamples(1); + if (samples.length >= 1) { + let short = samples + .filter((sample) => sample.numTransactions !== 0) + .map( + (sample) => sample.numTransactions / sample.samplePeriodSecs + ); + const avgTps = short[0]; + if (!cancelled) { + setTps(avgTps); + } + } + } catch (e) {} + })(); + }, 5000); + return () => { + cancelled = true; + clearInterval(interval); + }; + }, []); + return tps !== null && tps < 1500 ? ( + {`WARNING! The Solana Transactions Per Second (TPS) is below 1500. This is a sign of network congestion. Proceed with caution as you may have difficulty submitting transactions and the guardians may have difficulty witnessing them (this could lead to processing delays). Current TPS: ${numeral( + tps + ).format("0,0")}`} + ) : null; +} diff --git a/bridge_ui/src/components/Transfer/Redeem.tsx b/bridge_ui/src/components/Transfer/Redeem.tsx index 82d806588..2d8daf245 100644 --- a/bridge_ui/src/components/Transfer/Redeem.tsx +++ b/bridge_ui/src/components/Transfer/Redeem.tsx @@ -41,6 +41,7 @@ import ButtonWithLoader from "../ButtonWithLoader"; import KeyAndBalance from "../KeyAndBalance"; import SmartAddress from "../SmartAddress"; import { SolanaCreateAssociatedAddressAlternate } from "../SolanaCreateAssociatedAddress"; +import SolanaTPSWarning from "../SolanaTPSWarning"; import StepDescription from "../StepDescription"; import TerraFeeDenomPicker from "../TerraFeeDenomPicker"; import AddToMetamask from "./AddToMetamask"; @@ -129,6 +130,7 @@ function Redeem() { label="Automatically unwrap to native currency" /> )} + {targetChain === CHAIN_ID_SOLANA && } {targetChain === CHAIN_ID_SOLANA ? ( ) : null} diff --git a/bridge_ui/src/components/Transfer/Send.tsx b/bridge_ui/src/components/Transfer/Send.tsx index 68339f609..210b18440 100644 --- a/bridge_ui/src/components/Transfer/Send.tsx +++ b/bridge_ui/src/components/Transfer/Send.tsx @@ -1,4 +1,8 @@ -import { CHAIN_ID_TERRA, isEVMChain } from "@certusone/wormhole-sdk"; +import { + CHAIN_ID_SOLANA, + CHAIN_ID_TERRA, + isEVMChain, +} from "@certusone/wormhole-sdk"; import { Checkbox, FormControlLabel } from "@material-ui/core"; import { Alert } from "@material-ui/lab"; import { ethers } from "ethers"; @@ -22,6 +26,7 @@ import { CHAINS_BY_ID } from "../../utils/consts"; import ButtonWithLoader from "../ButtonWithLoader"; import KeyAndBalance from "../KeyAndBalance"; import ShowTx from "../ShowTx"; +import SolanaTPSWarning from "../SolanaTPSWarning"; import StepDescription from "../StepDescription"; import TerraFeeDenomPicker from "../TerraFeeDenomPicker"; import TransactionProgress from "../TransactionProgress"; @@ -140,6 +145,7 @@ function Send() { completing Step 4, you will have to perform the recovery workflow to complete the transfer. + {sourceChain === CHAIN_ID_SOLANA && } {approveButtonNeeded ? ( <> + {sourceChain === CHAIN_ID_SOLANA && }