Skip to content

Commit

Permalink
Merge pull request #241 from CarmineOptions/feature/price-protect-vid…
Browse files Browse the repository at this point in the history
…eo-popup

feat: add price protect video popup
  • Loading branch information
DaveVodrazka authored Oct 2, 2024
2 parents b065760 + f7622ea commit fde5835
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import PriceGuardPage from "./pages/priceGuard";
import "./style/base.css";
import YieldPage from "./pages/yield";
import SwapPage from "./pages/swap";
import PriceProtectVideoPage from "./pages/priceProtectVideo";

const App = () => {
const [check, rerender] = useState(false);
Expand Down Expand Up @@ -76,6 +77,10 @@ const App = () => {
<Route path="/battlecharts" element={<BattlechartsPage />} />
<Route path="/priceprotect" element={<PriceGuardPage />} />
<Route path="/yield" element={<YieldPage />} />
<Route
path="/price-protect-video"
element={<PriceProtectVideoPage />}
/>
<Route path="*" element={<NotFound />} />
</Routes>
</Router>
Expand Down
5 changes: 5 additions & 0 deletions src/components/Announce/BraavosAnnounce.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export const BraavosAnnounce = () => {
}
}, [account, data, show]);

if (window?.location?.pathname === "/price-protect-video") {
// do not show in video popup
return null;
}

if (isLoading || isError || !data || !show || !account) {
return null;
}
Expand Down
1 change: 1 addition & 0 deletions src/components/Popup/Popup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const Popup = () => {};
27 changes: 27 additions & 0 deletions src/components/Popup/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export type PopupConfig = {
url: string;
width?: number;
height?: number;
left?: number;
top?: number;
};

export const openPopupWindow = (config: PopupConfig) => {
if (!window) {
return;
}

const { url, width, height, left, top } = {
width: 987,
height: 555,
left: 0,
top: 0,
...config,
};

window.open(
url,
"popupWindow", // Window name
`width=${width},height=${height},top=${top},left=${left},resizable,scrollbars`
);
};
49 changes: 48 additions & 1 deletion src/pages/priceGuard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,48 @@
/* eslint-disable no-unreachable */
/* eslint-disable jsx-a11y/anchor-is-valid */
import { Helmet } from "react-helmet";
import { Layout } from "../components/Layout";
import { UserPriceGuard, PriceGuard } from "../components/PriceGuard";
import { openPopupWindow, PopupConfig } from "../components/Popup";

const getVideoPopupConfig = (): PopupConfig => {
const url = "/price-protect-video";

return { url };

// video has fixed size, cannot use this unless video can be resized inside iframe
const defaultWidth = 987;
const defaultHeight = 555;
const aspectRatio = defaultWidth / defaultHeight;
const width = window.innerWidth;
const height = window.innerHeight;

if (width >= defaultWidth && height >= defaultHeight) {
return {
url,
width: defaultWidth,
height: defaultHeight,
};
}

const widthBasedHeight = width / aspectRatio;

if (height >= widthBasedHeight) {
return {
url,
width,
height: widthBasedHeight,
};
}

const heightBasedWidth = height * aspectRatio;

return {
url,
width: heightBasedWidth,
height,
};
};

const PriceGuardPage = () => {
return (
Expand All @@ -18,7 +60,12 @@ const PriceGuardPage = () => {
<a
rel="noopener nofollow noreferrer"
target="_blank"
href="https://docs.carmine.finance/carmine-options-amm/use-cases"
href="#"
onClick={() => {
const cfg = getVideoPopupConfig();
console.log(cfg);
openPopupWindow(cfg);
}}
>
Learn more
</a>
Expand Down
14 changes: 14 additions & 0 deletions src/pages/priceProtectVideo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const PriceProtectVideoPage = () => (
<iframe
src="https://drive.google.com/file/d/1M7ROxzZ-d9XhePYe-15j0T--UGdoiYPi/preview"
style={{
border: "none",
}}
width="987"
height="555"
allow="autoplay"
title="CarmineOptions Price Protect"
></iframe>
);

export default PriceProtectVideoPage;

0 comments on commit fde5835

Please sign in to comment.