diff --git a/components/Rpc/index.tsx b/components/Rpc/index.tsx index b8c1aa63..db8aa235 100644 --- a/components/Rpc/index.tsx +++ b/components/Rpc/index.tsx @@ -1,10 +1,8 @@ /* eslint-disable jsx-a11y/label-has-associated-control */ import React, { useEffect, useState } from "react"; -import { FiChevronDown } from "@react-icons/all-files/fi/FiChevronDown"; -import { getRpcList, ping, switchPoint } from "./tool"; +import { getRpcList, ping } from "./tool"; import { isMobileDevice } from "../../helpers/helpers"; import { displayCurrentRpc, ModalAddCustomNetWork } from "./component/Common"; -import { MoreButtonIcon } from "./component/svg"; const RpcList = () => { const rpclist = getRpcList(); diff --git a/components/appInit/index.tsx b/components/appInit/index.tsx new file mode 100644 index 00000000..fcbd3edb --- /dev/null +++ b/components/appInit/index.tsx @@ -0,0 +1,80 @@ +import { useEffect } from "react"; +import { useIdle, useInterval } from "react-use"; +import ModalReact from "react-modal"; +import { useAppDispatch, useAppSelector } from "../../redux/hooks"; +import { fetchAssets, fetchRefPrices } from "../../redux/assetsSlice"; +import { fetchConfig } from "../../redux/appSlice"; +import { fetchAccount } from "../../redux/accountSlice"; +import { fetchAssetsMEME, fetchRefPricesMEME } from "../../redux/assetsSliceMEME"; +import { fetchAccountMEME } from "../../redux/accountSliceMEME"; +import { fetchConfig as fetchMemeConfig } from "../../redux/appSliceMEME"; +import { fetchMarginAccount } from "../../redux/marginAccountSlice"; +import { fetchMarginAccountMEME } from "../../redux/marginAccountSliceMEME"; +import { fetchMarginConfig } from "../../redux/marginConfigSlice"; +import { fetchMarginConfigMEME } from "../../redux/marginConfigSliceMEME"; +import { fetchAllPools } from "../../redux/poolSlice"; +import { getAccountId } from "../../redux/accountSelectors"; + +ModalReact.defaultStyles = { + overlay: { + position: "fixed", + top: 0, + left: 0, + right: 0, + bottom: 0, + backgroundColor: "rgba(20, 22, 43, 0.8)", + zIndex: 100, + outline: "none", + }, + content: { + position: "absolute", + display: "flex", + alignItems: "center", + justifyContent: "center", + top: "50%", + left: "50%", + transform: "translate(-50%, -65%)", + outline: "none", + }, +}; +ModalReact.setAppElement("#root"); + +const IDLE_INTERVAL = 90e3; +const REFETCH_INTERVAL = 60e3; + +const Init = () => { + const isIdle = useIdle(IDLE_INTERVAL); + const dispatch = useAppDispatch(); + const accountId = useAppSelector(getAccountId); + + const fetchData = () => { + dispatch(fetchAssets()).then(() => dispatch(fetchRefPrices())); + dispatch(fetchAssetsMEME()).then(() => dispatch(fetchRefPricesMEME())); + dispatch(fetchConfig()); + dispatch(fetchMemeConfig()); + dispatch(fetchMarginConfig()); + dispatch(fetchMarginConfigMEME()); + dispatch(fetchAllPools()); + }; + const fetchDataAccount = () => { + dispatch(fetchAccount()); + dispatch(fetchAccountMEME()); + dispatch(fetchMarginAccount()); + dispatch(fetchMarginAccountMEME()); + }; + const fetchAllData = () => { + fetchData(); + fetchDataAccount(); + }; + useEffect(fetchData, []); + useEffect(() => { + if (accountId) { + fetchDataAccount(); + } + }, [accountId]); + useInterval(fetchAllData, !isIdle ? REFETCH_INTERVAL : null); + + return null; +}; + +export default Init; diff --git a/components/blockTip/index.tsx b/components/blockTip/index.tsx new file mode 100644 index 00000000..664c8f26 --- /dev/null +++ b/components/blockTip/index.tsx @@ -0,0 +1,63 @@ +import { useEffect, useState } from "react"; +import { get_blocked } from "../../api/get-blocked"; + +export default function BlockTip() { + const [isBlocked, setIsBlocked] = useState(false); + const blockFeatureEnabled = true; + useEffect(() => { + if (blockFeatureEnabled) { + checkBlockedStatus(); + } + }, [blockFeatureEnabled]); + function checkBlockedStatus() { + get_blocked().then((res) => { + if (res.blocked === true) { + const blockConfirmationTime = localStorage.getItem("blockConfirmationTime"); + if (blockConfirmationTime) { + const currentTime = new Date().getTime(); + const weekInMilliseconds = 7 * 24 * 60 * 60 * 1000; + if (currentTime - parseInt(blockConfirmationTime, 10) < weekInMilliseconds) { + setIsBlocked(false); + } else { + setIsBlocked(true); + } + } else { + setIsBlocked(true); + } + } + }); + } + function handleBlockConfirmation() { + const currentTime = new Date().getTime(); + localStorage.setItem("blockConfirmationTime", currentTime.toString()); + setIsBlocked(false); + } + if (!(isBlocked && blockFeatureEnabled)) return null; + return ( +
+
+

+ You are prohibited from accessing app.burrow.finance due to your location or other + infringement of the Terms of Services. +

+
+ Confirm +
+
+
+ ); +} diff --git a/components/popup/index.tsx b/components/popup/index.tsx index e3bd53a2..56e518de 100644 --- a/components/popup/index.tsx +++ b/components/popup/index.tsx @@ -83,7 +83,7 @@ const Popup = ({ className }) => { - + {/* {
-
+
*/} diff --git a/components/process/index.tsx b/components/process/index.tsx new file mode 100644 index 00000000..63c571a7 --- /dev/null +++ b/components/process/index.tsx @@ -0,0 +1,24 @@ +import { useEffect, useState } from "react"; +import { useRouter } from "next/router"; +import LoadingBar from "react-top-loading-bar"; + +export default function Process() { + const [progress, setProgress] = useState(0); + const router = useRouter(); + useEffect(() => { + router.events.on("routeChangeStart", () => { + setProgress(30); + }); + router.events.on("routeChangeComplete", () => { + setProgress(100); + }); + }, []); + return ( + setProgress(0)} + /> + ); +} diff --git a/components/upgrade/index.tsx b/components/upgrade/index.tsx new file mode 100644 index 00000000..8c234fdc --- /dev/null +++ b/components/upgrade/index.tsx @@ -0,0 +1,79 @@ +import { useEffect, useState } from "react"; +import { useAppDispatch, useAppSelector } from "../../redux/hooks"; +import { getAccountId, getAccountPortfolio } from "../../redux/accountSelectors"; +import { getAssets } from "../../redux/assetsSelectors"; +import { getConfig } from "../../redux/appSelectors"; +import { fetchAssets, fetchRefPrices } from "../../redux/assetsSlice"; +import { fetchConfig } from "../../redux/appSlice"; +import { fetchAccount, logoutAccount } from "../../redux/accountSlice"; +import { logoutAccount as logoutAccountMEME } from "../../redux/accountSliceMEME"; +import RpcList from "../Rpc"; +import { Layout, Modal } from ".."; +import Popup from "../popup"; +import { ToastMessage } from "../ToastMessage"; +import BalanceReminder from "../BalanceReminder"; +import PubTestModal from "../PubTestModal"; +import Init from "../appInit"; + +export default function Upgrade({ Component, pageProps }) { + const [upgrading, setUpgrading] = useState(true); + const dispatch = useAppDispatch(); + const accountId = useAppSelector(getAccountId); + const portfolio = useAppSelector(getAccountPortfolio()); + const assets = useAppSelector(getAssets); + const config = useAppSelector(getConfig); + useEffect(() => { + if ( + !portfolio.positions || + !Object.keys(assets?.data || {}).length || + !config?.booster_token_id + ) { + setUpgrading(true); + fetch(); + } else { + setUpgrading(false); + } + }, [ + accountId, + portfolio.positions, + Object.keys(assets?.data || {}).length, + JSON.stringify(config || {}), + ]); + async function fetch() { + localStorage.removeItem("persist:root"); + await dispatch(fetchAssets()).then(() => dispatch(fetchRefPrices())); + await dispatch(fetchConfig()); + if (accountId) { + await dispatch(fetchAccount()); + // await dispatch(fetchAccountMEME()); No need to obtain a meme account when upgrading + } else { + await dispatch(logoutAccount()); + await dispatch(logoutAccountMEME()); + } + } + return ( +
+ {upgrading ? ( +
+ + + Refreshing assets data... + + +
+ ) : ( + + + + + + + + + + + + )} +
+ ); +} diff --git a/package.json b/package.json index cc80a3a4..7f822a35 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,6 @@ "@ref-finance/ref-sdk": "^1.4.6", "@sentry/cli": "^2.5.2", "@sentry/react": "^7.13.0", - "@sentry/tracing": "^7.13.0", "@tanstack/react-query": "^5.56.2", "@types/big.js": "^6.2.2", "@types/bn.js": "^5.1.1", @@ -83,7 +82,6 @@ "next": "latest", "pluralize": "^8.0.0", "postcss": "^8.4.28", - "posthog-js": "^1.20.2", "ramda": "^0.28.0", "react": "^18.2.0", "react-copy-to-clipboard": "^5.1.0", diff --git a/pages/_app.tsx b/pages/_app.tsx index 4e7a1d13..eba9f278 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -1,263 +1,29 @@ -import { useEffect, useState } from "react"; import Head from "next/head"; import { Provider } from "react-redux"; import type { AppProps } from "next/app"; import { PersistGate } from "redux-persist/integration/react"; -import { init, ErrorBoundary } from "@sentry/react"; -import { Integrations } from "@sentry/tracing"; -import posthogJs from "posthog-js"; -import { useIdle, useInterval } from "react-use"; -import ModalReact from "react-modal"; - -import "../styles/global.css"; -import LoadingBar from "react-top-loading-bar"; -import { useRouter } from "next/router"; -import { BtcWalletSelectorContextProvider } from "btc-wallet"; +import { ErrorBoundary } from "@sentry/react"; import { store, persistor } from "../redux/store"; -import { FallbackError, Layout, Modal } from "../components"; -import { posthog, isPostHogEnabled } from "../utils/telemetry"; -import { useAppDispatch, useAppSelector } from "../redux/hooks"; -import { fetchAssets, fetchRefPrices } from "../redux/assetsSlice"; -import { fetchAssetsMEME } from "../redux/assetsSliceMEME"; -import { fetchAccount, logoutAccount } from "../redux/accountSlice"; -import { fetchAccountMEME, logoutAccount as logoutAccountMEME } from "../redux/accountSliceMEME"; -import { fetchConfig } from "../redux/appSlice"; -import { fetchConfig as fetchMemeConfig } from "../redux/appSliceMEME"; -import { fetchMarginAccount } from "../redux/marginAccountSlice"; -import { fetchMarginAccountMEME } from "../redux/marginAccountSliceMEME"; -import { fetchMarginConfig } from "../redux/marginConfigSlice"; -import { fetchMarginConfigMEME } from "../redux/marginConfigSliceMEME"; -import { ToastMessage } from "../components/ToastMessage"; -import RpcList from "../components/Rpc"; -import PubTestModal from "../components/PubTestModal"; -import { getAccountId, getAccountPortfolio } from "../redux/accountSelectors"; -import { getAssets } from "../redux/assetsSelectors"; -import { getConfig } from "../redux/appSelectors"; -import { fetchAllPools } from "../redux/poolSlice"; -import "./slip.css"; -import { get_blocked } from "../api/get-blocked"; -import Popup from "../components/popup"; -import BalanceReminder from "../components/BalanceReminder"; - -ModalReact.defaultStyles = { - overlay: { - position: "fixed", - top: 0, - left: 0, - right: 0, - bottom: 0, - backgroundColor: "rgba(20, 22, 43, 0.8)", - zIndex: 100, - outline: "none", - }, - content: { - position: "absolute", - display: "flex", - alignItems: "center", - justifyContent: "center", - top: "50%", - left: "50%", - transform: "translate(-50%, -65%)", - outline: "none", - }, -}; - -ModalReact.setAppElement("#root"); - -const SENTRY_ORG = process.env.NEXT_PUBLIC_SENTRY_ORG as string; -const SENTRY_PID = process.env.NEXT_PUBLIC_SENTRY_PID as unknown as number; - -const integrations = [new Integrations.BrowserTracing()] as Array< - Integrations.BrowserTracing | any ->; - -if (isPostHogEnabled) { - integrations.push(new posthogJs.SentryIntegration(posthog, SENTRY_ORG, SENTRY_PID)); -} - -init({ - dsn: process.env.NEXT_PUBLIC_SENTRY_DSN, - environment: process.env.NEXT_PUBLIC_DEFAULT_NETWORK, - integrations, - tracesSampleRate: 0.1, - release: "v1", -}); - -const IDLE_INTERVAL = 400e3; -const REFETCH_INTERVAL = 300e3; - -const Init = () => { - const isIdle = useIdle(IDLE_INTERVAL); - const dispatch = useAppDispatch(); - - const fetchData = () => { - dispatch(fetchAssets()).then(() => dispatch(fetchRefPrices())); - dispatch(fetchAssetsMEME()).then(() => dispatch(fetchRefPrices())); - dispatch(fetchAccount()); - dispatch(fetchAccountMEME()); - dispatch(fetchConfig()); - dispatch(fetchMemeConfig()); - dispatch(fetchMarginAccount()); - dispatch(fetchMarginAccountMEME()); - dispatch(fetchMarginConfig()); - dispatch(fetchMarginConfigMEME()); - dispatch(fetchAllPools()); - }; - useEffect(fetchData, []); - useInterval(fetchData, !isIdle ? REFETCH_INTERVAL : null); +import { FallbackError } from "../components"; +import Upgrade from "../components/upgrade"; +import ProcessBar from "../components/process"; +import BlockContryTip from "../components/blockTip"; +import "../styles/global.css"; - return null; -}; -function Upgrade({ Component, pageProps }) { - const [upgrading, setUpgrading] = useState(true); - const dispatch = useAppDispatch(); - const accountId = useAppSelector(getAccountId); - const portfolio = useAppSelector(getAccountPortfolio()); - const assets = useAppSelector(getAssets); - const config = useAppSelector(getConfig); - useEffect(() => { - if ( - !portfolio.positions || - !Object.keys(assets?.data || {}).length || - !config?.booster_token_id - ) { - setUpgrading(true); - fetch(); - } else { - setUpgrading(false); - } - }, [ - accountId, - portfolio.positions, - Object.keys(assets?.data || {}).length, - JSON.stringify(config || {}), - ]); - async function fetch() { - localStorage.removeItem("persist:root"); - await dispatch(fetchAssets()).then(() => dispatch(fetchRefPrices())); - await dispatch(fetchConfig()); - if (accountId) { - await dispatch(fetchAccount()); - await dispatch(fetchAccountMEME()); - } else { - await dispatch(logoutAccount()); - await dispatch(logoutAccountMEME()); - } - } - return ( -
- {upgrading ? ( -
- - - Refreshing assets data... - - -
- ) : ( - - - - - - - - - - - - )} -
- ); -} export default function MyApp({ Component, pageProps }: AppProps) { - const [progress, setProgress] = useState(0); - const [isBlocked, setIsBlocked] = useState(false); - const blockFeatureEnabled = true; - // const blockFeatureEnabled = false; - const router = useRouter(); - useEffect(() => { - if (blockFeatureEnabled) { - checkBlockedStatus(); - } - }, [blockFeatureEnabled]); - useEffect(() => { - router.events.on("routeChangeStart", () => { - setProgress(30); - }); - router.events.on("routeChangeComplete", () => { - setProgress(100); - }); - }, []); - function checkBlockedStatus() { - get_blocked().then((res) => { - if (res.blocked === true) { - const blockConfirmationTime = localStorage.getItem("blockConfirmationTime"); - if (blockConfirmationTime) { - const currentTime = new Date().getTime(); - const weekInMilliseconds = 7 * 24 * 60 * 60 * 1000; - if (currentTime - parseInt(blockConfirmationTime, 10) < weekInMilliseconds) { - setIsBlocked(false); - } else { - setIsBlocked(true); - } - } else { - setIsBlocked(true); - } - } - }); - } - function handleBlockConfirmation() { - const currentTime = new Date().getTime(); - localStorage.setItem("blockConfirmationTime", currentTime.toString()); - setIsBlocked(false); - } return ( - setProgress(0)} - /> - - - - - - Burrow Finance - - - - - {isBlocked && blockFeatureEnabled && ( -
-
-

- You are prohibited from accessing app.burrow.finance due to your location or other - infringement of the Terms of Services. -

-
- Confirm -
-
-
- )} -
+ + + + + + + Burrow Finance + + + +
); } diff --git a/pages/slip.css b/pages/slip.css deleted file mode 100644 index 762f2d8c..00000000 --- a/pages/slip.css +++ /dev/null @@ -1,9 +0,0 @@ -.slip-fater:hover .slip-child { - display: block; -} -.slip-child { - display: none; -} -.slip-child:hover { - display: block; -} diff --git a/redux/assetsSliceMEME.ts b/redux/assetsSliceMEME.ts index 0637b162..29f5694e 100644 --- a/redux/assetsSliceMEME.ts +++ b/redux/assetsSliceMEME.ts @@ -13,7 +13,7 @@ export const fetchAssetsMEME = createAsyncThunk("assetsMEME/fetchAssets", async return { assets, netTvlFarm, allFarms }; }); -export const fetchRefPrices = createAsyncThunk("assetsMEME/fetchRefPrices", async () => { +export const fetchRefPricesMEME = createAsyncThunk("assetsMEME/fetchRefPrices", async () => { const prices = await fetch( "https://raw.githubusercontent.com/NearDeFi/token-prices/main/ref-prices.json", ).then((r) => r.json()); @@ -40,7 +40,7 @@ export const assetSliceMEME = createSlice({ console.error(action.payload); throw new Error("Failed to fetch assets and metadata"); }); - builder.addCase(fetchRefPrices.fulfilled, (state, action) => { + builder.addCase(fetchRefPricesMEME.fulfilled, (state, action) => { missingPriceTokens.forEach((missingToken) => { const missingTokenId = missingToken[defaultNetwork]; if (missingTokenId && state.data[missingTokenId] && !state.data[missingTokenId]["price"]) { @@ -61,10 +61,10 @@ export const assetSliceMEME = createSlice({ } }); }); - builder.addCase(fetchRefPrices.pending, (state) => { + builder.addCase(fetchRefPricesMEME.pending, (state) => { state.status = "fetching"; }); - builder.addCase(fetchRefPrices.rejected, (state, action) => { + builder.addCase(fetchRefPricesMEME.rejected, (state, action) => { state.status = action.meta.requestStatus; console.error(action.payload); throw new Error("Failed to fetch REF prices"); diff --git a/styles/global.css b/styles/global.css index 39df4460..54cca7bf 100644 --- a/styles/global.css +++ b/styles/global.css @@ -877,3 +877,12 @@ options-list::-webkit-scrollbar { .need-small { font-size: 8px !important; } +.slip-fater:hover .slip-child { + display: block; +} +.slip-child { + display: none; +} +.slip-child:hover { + display: block; +} diff --git a/utils/telemetry.ts b/utils/telemetry.ts index 9afe8c1a..8c1cbf34 100644 --- a/utils/telemetry.ts +++ b/utils/telemetry.ts @@ -1,32 +1,19 @@ -import posthogJs from "posthog-js"; - -const POSTHOG_KEY = process.env.NEXT_PUBLIC_POSTHOG_KEY as string; -const POSTHOG_HOST = process.env.NEXT_PUBLIC_POSTHOG_HOST as string; - // export const isPostHogEnabled = POSTHOG_KEY && POSTHOG_HOST; export const isPostHogEnabled = false; -const initPostHog = () => { - if (typeof window !== "undefined" && isPostHogEnabled) { - posthogJs.init(POSTHOG_KEY, { - api_host: POSTHOG_HOST, - autocapture: false, - }); - } - - return posthogJs; -}; +// eslint-disable-next-line @typescript-eslint/no-empty-function +const initPostHog = () => {}; export const posthog = initPostHog(); export const track = (name, props = {}) => { - if (!isPostHogEnabled) return; - posthog.capture(name, props); + // if (!isPostHogEnabled) return; + // posthog.capture(name, props); }; export const identifyUser = (id, traits = {}) => { - if (!isPostHogEnabled) return; - posthog.identify(id, traits); + // if (!isPostHogEnabled) return; + // posthog.identify(id, traits); }; export const trackConnectWallet = () => { diff --git a/yarn.lock b/yarn.lock index fd312e66..8883d045 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4398,17 +4398,7 @@ hoist-non-react-statics "^3.3.2" tslib "^1.9.3" -"@sentry/tracing@^7.13.0": - version "7.13.0" - resolved "https://registry.npmjs.org/@sentry/tracing/-/tracing-7.13.0.tgz" - integrity sha512-/MKSd25rGv6Pc0FPBLXJifkfvSaYVPA8XUOLzVeDN0gl07h8AXli4qG9amTh/4Wb5h4dFpbcscOvW2VC+pxkIA== - dependencies: - "@sentry/hub" "7.13.0" - "@sentry/types" "7.13.0" - "@sentry/utils" "7.13.0" - tslib "^1.9.3" - -"@sentry/types@7.13.0", "@sentry/types@^7.2.0": +"@sentry/types@7.13.0": version "7.13.0" resolved "https://registry.npmjs.org/@sentry/types/-/types-7.13.0.tgz" integrity sha512-ttckM1XaeyHRLMdr79wmGA5PFbTGx2jio9DCD/mkEpSfk6OGfqfC7gpwy7BNstDH/VKyQj/lDCJPnwvWqARMoQ== @@ -9036,11 +9026,6 @@ fetch-blob@^3.1.2, fetch-blob@^3.1.4: node-domexception "^1.0.0" web-streams-polyfill "^3.0.3" -fflate@^0.4.1: - version "0.4.8" - resolved "https://registry.npmjs.org/fflate/-/fflate-0.4.8.tgz" - integrity sha512-FJqqoDBR00Mdj9ppamLa/Y7vxm+PRmNWA67N846RvsoYVMKB4q3y/de5PA7gUmRMYK/8CMz2GDZQmCRN1wBcWA== - figures@^4.0.1: version "4.0.1" resolved "https://registry.npmjs.org/figures/-/figures-4.0.1.tgz" @@ -13178,15 +13163,6 @@ postcss@^8.4.23, postcss@^8.4.28: picocolors "^1.0.0" source-map-js "^1.0.2" -posthog-js@^1.20.2: - version "1.31.0" - resolved "https://registry.npmjs.org/posthog-js/-/posthog-js-1.31.0.tgz" - integrity sha512-d6vBb/ChS+t33voi37HA76etwWIukEcvJLZLZvkhJZcIrR29shwkAFUzd8lL7VdAelLlaAtmoPMwr820Yq5GUg== - dependencies: - "@sentry/types" "^7.2.0" - fflate "^0.4.1" - rrweb-snapshot "^1.1.14" - posthtml-parser@^0.10.1: version "0.10.2" resolved "https://registry.npmjs.org/posthtml-parser/-/posthtml-parser-0.10.2.tgz#df364d7b179f2a6bf0466b56be7b98fd4e97c573" @@ -14112,11 +14088,6 @@ rpc-websockets@^9.0.2: bufferutil "^4.0.1" utf-8-validate "^5.0.2" -rrweb-snapshot@^1.1.14: - version "1.1.14" - resolved "https://registry.npmjs.org/rrweb-snapshot/-/rrweb-snapshot-1.1.14.tgz" - integrity sha512-eP5pirNjP5+GewQfcOQY4uBiDnpqxNRc65yKPW0eSoU1XamDfc4M8oqpXGMyUyvLyxFDB0q0+DChuxxiU2FXBQ== - rtl-css-js@^1.14.0: version "1.16.0" resolved "https://registry.npmjs.org/rtl-css-js/-/rtl-css-js-1.16.0.tgz"