Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(oracle deployed): adding deployment check part 1 #17

Merged
merged 3 commits into from
Jul 31, 2024
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
1 change: 1 addition & 0 deletions src/component/OracleDecoder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ Provided: ${decimalResult.quoteTokenDecimalsProvided}, Expected: ${decimalResult
<CheckItemFeeds
title="Feeds Check"
isVerified={routeResult?.isValid ?? null}
isHardcoded={routeResult?.isHardcoded ?? null}
details={
routeResult
? routeResult.isValid
Expand Down
53 changes: 53 additions & 0 deletions src/component/OracleTestor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { LuExternalLink } from "react-icons/lu";
import useOraclePriceCheck from "../hooks/testor/useOraclePriceCheck";
import CheckItemFeeds from "./common/CheckItemFeeds";
import { Asset } from "../hooks/types";
import useOracleDeploymentCheck from "../hooks/testor/useOracleDeploymentCheck";
import CheckItemDeployment from "./common/CheckItemDeployment";

const ethLogo = "https://cdn.morpho.org/assets/chains/eth.svg";
const baseLogo = "https://cdn.morpho.org/assets/chains/base.png";
Expand Down Expand Up @@ -101,6 +103,14 @@ const OracleTestor = () => {
assets
);

const {
result: deploymentResult,
loading: deploymentLoading,
//eslint-disable-next-line
errors: deploymentError,
checkDeployment,
} = useOracleDeploymentCheck();

useEffect(() => {
setIsSubmitEnabled(
collateralAssetTouched &&
Expand Down Expand Up @@ -187,6 +197,7 @@ const OracleTestor = () => {
loanAssetSymbol
);
await priceCheck();
await checkDeployment(selectedNetwork.value, oracleInputs);
setIsSubmitting(false);
};

Expand Down Expand Up @@ -247,6 +258,14 @@ const OracleTestor = () => {
},
];

const getExplorerUrl = (address: string) => {
const baseUrl =
selectedNetwork.value === 1
? "https://etherscan.io/address/"
: "https://basescan.org/address/";
return `${baseUrl}${address}`;
};

return (
<div className="main-background">
<div className="oracle-container">
Expand Down Expand Up @@ -570,9 +589,43 @@ Provided: ${decimalResult.quoteTokenDecimalsProvided}, Expected: ${decimalResult
loading={formSubmitted ? decimalLoading : false}
/>

<CheckItemDeployment
title="Deployment Check"
isVerified={
deploymentResult ? !deploymentResult.isDeployed : null
}
details={
deploymentResult ? (
deploymentResult.isDeployed ? (
<>
An oracle with these inputs is already deployed at
address:{" "}
<a
href={getExplorerUrl(deploymentResult.address || "")}
target="_blank"
rel="noopener noreferrer"
style={{ fontWeight: "bold" }}
>
{deploymentResult.address}
</a>
</>
) : (
"No oracle with these inputs has been deployed yet, feel free to proceed."
)
) : (
""
)
}
description="Check if an oracle with the same inputs has already been deployed."
loading={deploymentLoading}
/>

<CheckItemFeeds
title="Feeds Check"
isVerified={formSubmitted ? routeResult?.isValid ?? null : null}
isHardcoded={
formSubmitted ? routeResult?.isHardcoded ?? null : null
}
details={
formSubmitted && routeResult
? routeResult.isValid
Expand Down
22 changes: 10 additions & 12 deletions src/component/common/CheckItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const CheckItem: React.FC<CheckItemProps> = ({
{description}
</p>
)}
{isOpen && (
{isOpen && details && (
<>
<div
style={{
Expand All @@ -79,17 +79,15 @@ const CheckItem: React.FC<CheckItemProps> = ({
{loading ? (
<p style={{ margin: "0", fontSize: "0.7rem" }}>Loading...</p>
) : (
details && (
<div
style={{
fontSize: "0.8rem",
margin: "0",
whiteSpace: "pre-wrap",
}}
>
<p>{details}</p>
</div>
)
<div
style={{
fontSize: "0.8rem",
margin: "0",
whiteSpace: "pre-wrap",
}}
>
<p>{details}</p>
</div>
)}
</div>
</>
Expand Down
97 changes: 97 additions & 0 deletions src/component/common/CheckItemDeployment.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import React, { useState } from "react";
import { BiCheckDouble, BiError, BiCaretDown, BiCaretUp } from "react-icons/bi";

interface CheckItemProps {
title: string;
isVerified: boolean | null;
details?: React.ReactNode;
description?: string;
loading?: boolean;
}

const CheckItem: React.FC<CheckItemProps> = ({
title,
isVerified,
details,
description,
loading,
}) => {
const [isOpen, setIsOpen] = useState(false);

const backgroundColor =
isVerified === null ? "#e2e3e5" : isVerified ? "#d4edda" : "#ffeeba";
const textColor =
isVerified === null ? "#6c757d" : isVerified ? "#155724" : "#6c757d";
const handleToggle = () => {
setIsOpen(!isOpen);
};
return (
<div
style={{
border: `0.5px solid ${backgroundColor}`,
borderRadius: "8px",
padding: "10px",
margin: "10px 0 0 0",
backgroundColor: backgroundColor,
color: textColor,
maxHeight: "130px",
overflowY: "auto",
}}
>
<div
style={{ display: "flex", alignItems: "center", cursor: "pointer" }}
onClick={handleToggle}
>
{isOpen ? <BiCaretUp /> : <BiCaretDown />}
<h2 style={{ margin: "2px", fontSize: "1rem", marginLeft: "8px" }}>
{title}{" "}
{isVerified === null ? (
""
) : isVerified ? (
<BiCheckDouble />
) : (
<BiError />
)}
</h2>
</div>
{description && (
<p
style={{
fontSize: "0.7rem",
color: "#6c757d",
fontStyle: "italic",
margin: "1px",
}}
>
{description}
</p>
)}
{isOpen && details && (
<div
style={{
background: "white",
borderRadius: "4px",
padding: "0.3rem",
marginTop: "10px",
}}
>
{loading ? (
<p style={{ margin: "0", fontSize: "0.7rem" }}>Loading...</p>
) : (
<div
style={{
fontSize: "0.8rem",
margin: "0",
whiteSpace: "pre-wrap",
}}
>
<p>{details}</p>
</div>
)}
</div>
)}
</div>
);
};

export default CheckItem;
Loading