forked from burrowfdn/burrow-cash
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
286 additions
and
320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<div | ||
className="fixed inset-0 bg-black bg-opacity-70 flex items-center justify-center" | ||
style={{ | ||
zIndex: "999999999", | ||
backdropFilter: "blur(6px)", | ||
height: "100vh", | ||
overflow: "hidden", | ||
}} | ||
> | ||
<div | ||
className="text-white text-center bg-dark-100 px-5 pt-9 pb-7 rounded-md border border-dark-300" | ||
style={{ width: "278px" }} | ||
> | ||
<p className="text-sm"> | ||
You are prohibited from accessing app.burrow.finance due to your location or other | ||
infringement of the Terms of Services. | ||
</p> | ||
<div | ||
onClick={handleBlockConfirmation} | ||
className="mt-6 border border-primary h-9 flex items-center justify-center rounded-md text-sm text-black text-primary cursor-pointer ml-1.5 mr-1.5" | ||
> | ||
Confirm | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<LoadingBar | ||
color="#D2FF3A" | ||
height={3} | ||
progress={progress} | ||
onLoaderFinished={() => setProgress(0)} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<boolean>(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 ( | ||
<div> | ||
{upgrading ? ( | ||
<div className="flex flex-col items-center justify-center h-screen"> | ||
<img src="/loading-brrr.gif" alt="" width="75px" /> | ||
<span className="flex items-center text-sm text-gray-300 mt-2"> | ||
Refreshing assets data... | ||
</span> | ||
<RpcList /> | ||
</div> | ||
) : ( | ||
<Layout> | ||
<Popup className="lg:hidden" /> | ||
<Init /> | ||
<Modal /> | ||
<ToastMessage /> | ||
<Component {...pageProps} /> | ||
<Popup className="xsm:hidden" /> | ||
<BalanceReminder /> | ||
<RpcList /> | ||
<PubTestModal /> | ||
</Layout> | ||
)} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.