diff --git a/src/components/PushSnap/EnableSnoozeModal.tsx b/src/components/PushSnap/EnableSnoozeModal.tsx new file mode 100644 index 0000000000..bbd77af532 --- /dev/null +++ b/src/components/PushSnap/EnableSnoozeModal.tsx @@ -0,0 +1,181 @@ +// React + Web3 Essentials +import React, { useState } from 'react'; + +// External Packages +import styled, { useTheme } from 'styled-components'; + +// Internal Compoonents +import { ItemHV2, ItemVV2, ButtonV2 } from 'components/reusables/SharedStylingV2'; + +// Internal Configs +import { device } from 'config/Globals'; +import { AppContext } from 'contexts/AppContext'; +import { SnoozeDurationType } from 'types'; +import { updateSnoozeDuration } from 'helpers'; +import { defaultSnapOrigin } from 'config'; + +const EnableSnoozeModal = ({ + setSnoozeDuration +}: + {setSnoozeDuration: (snoozeDuration: SnoozeDurationType) => void} +) => { + const { setSnapState } = React.useContext(AppContext); + const theme = useTheme(); + + const [snoozeDurationInput, setSnoozeDurationInput] = useState(1); + + const handleChange = async () => { + const duration = snoozeDurationInput; + + if (duration >= 1 && duration <= 72) { + await window.ethereum?.request({ + method: 'wallet_invokeSnap', + params: { + snapId: defaultSnapOrigin, + request: { + method: 'pushproto_setsnoozeduration', + params: { snoozeDuration: snoozeDurationInput.toString()}, + }, + }, + }) + + setSnapState(3); + } else { + // Display an error message if the input is invalid + console.error('Invalid input. Please enter a number between 1 and 72.'); + } + await updateSnoozeDuration(setSnoozeDuration); + }; + + const handleCancel = async () => { + setSnapState(3); // go back to step one + }; + + return ( + + + Set Snooze Duration + + How long would you like to snooze notifications? You can snooze for 1 to 72 hours. + + { + const duration = parseInt(e.target.value); + if (!isNaN(duration) && duration >= 1 && duration <= 72) { + setSnoozeDurationInput(duration); + } + }} + placeholder="Snooze duration in Hours (e.g. 6)" + /> + + + + + Cancel + + Enable Snooze + + + ); +}; + +export default EnableSnoozeModal; + +const Container = styled(ItemVV2)` + padding: 0px 0px 12px 9px; +`; + +const PrimaryText = styled.p` + margin: 0px; + font-size: 18px; + font-weight: 500; + align-self: baseline; + color: ${(props) => props.theme.modalMessageColor}; +`; + +const SecondaryText = styled.p` + margin: 0px; + font-size: 12px; + font-weight: 400; + line-height: 24px; + text-align: left; + overflow: hidden; + text-overflow: ellipsis; // Show ellipsis (...) when text overflows + + color: ${(props) => props.theme.snapSecondaryText}; +`; + +const SnapButton = styled(ButtonV2)` + align-self: end; + height: 36px; + z-index: 0; + font-family: 'Strawford'; + font-style: normal; + font-weight: 500; + font-size: 14px; + line-height: normal; + border-radius: 8px; +`; + +const FilledButton = styled(SnapButton)` + min-width: 79px; + padding: 14px; + background: #d53a94; + height: 48px; + radius: 12px; + padding: 0px 24px 0px 24px; + color: #fff; + white-space: nowrap; +`; + +const EnptyButton = styled(SnapButton)` + flex-direction: row; + text-align: center; + height: 48px; + padding: 0px 24px 0px 24px; + margin-right: 8px; + border: 1px solid #bac4d6; + color: ${(props) => props.theme.default.color}; + background: ${(props) => props.theme.default.bg}; + gap: 4px; +`; + +const Input = styled.input` + box-sizing: border-box; + display: flex; + flex: 1; + width: 240px; + height: 48px; + padding: 13px 16px 13px 16px; + margin: 10px 3px 0px; + background: ${(props) => props.theme.modalSearchBarBackground}; + + border-radius: 12px; + border: 1px solid #bac4d6; + + color: ${(props) => props.theme.default.secondaryColor || '#000'}; + &:focus { + outline: none; + background-origin: border; + border: 1px solid #bac4d6 !important; + background-clip: padding-box, border-box; + } + &::placeholder { + color: ${(props) => props.theme.default.secondaryColor || '#000'}; + } + @media ${device.mobileL} { + min-width: 300px; + } +`; diff --git a/src/components/PushSnap/PushSnapConfigureModal.tsx b/src/components/PushSnap/PushSnapConfigureModal.tsx index b14fab4240..96352390f1 100644 --- a/src/components/PushSnap/PushSnapConfigureModal.tsx +++ b/src/components/PushSnap/PushSnapConfigureModal.tsx @@ -9,64 +9,73 @@ import styled, { useTheme } from 'styled-components'; // Internal Compoonents import { ReactComponent as MinusCircle } from 'assets/PushSnaps/MinusCircle.svg'; -import InfoImage from "assets/info.svg"; import { Button } from 'components/SharedStyling'; import { ItemHV2, ItemVV2, SpanV2 } from 'components/reusables/SharedStylingV2'; -import Tooltip from 'components/reusables/tooltip/Tooltip'; import { shortenText } from 'helpers/UtilityHelper'; import { useAccount } from 'hooks'; +import { AppContext } from 'contexts/AppContext'; // Internal Configs import { device } from 'config/Globals'; - - -const PushSnapConfigureModal = () => { - const [walletAddresses, setWalletAddresses] = useState([]); +import { SnoozeDurationType } from 'types'; +import { updateSnoozeDuration } from 'helpers'; +import { defaultSnapOrigin } from 'config'; + +const PushSnapConfigureModal = ({ + snoozeDuration, setSnoozeDuration +}: + {snoozeDuration: SnoozeDurationType, setSnoozeDuration: (snoozeDuration: SnoozeDurationType) => void} +) => { const [addresses, setAddresses] = useState([]); const [searchedUser, setSearchedUser] = useState(''); - const [showRemove, setShowRemove] = useState(); - const [toggleStatus, setToggleStatus] = useState(0); - const theme = useTheme(); + const { setSnapState, SnapState } = React.useContext(AppContext); - const defaultSnapOrigin = 'npm:@pushprotocol/snap'; + useEffect(() => { + setChecked(SnapState === 6); + }, [SnapState]); + + const theme = useTheme(); const { chainId, account, provider } = useAccount(); useEffect(() => { - (async function () { - const res = await window.ethereum?.request({ + (async function() { + getWalletAddresses(); + await updateSnoozeDuration(setSnoozeDuration); + })(); + }, []); + + + const disableSnooze = async () => { + await window.ethereum?.request({ method: 'wallet_invokeSnap', params: { snapId: defaultSnapOrigin, request: { - method: 'pushproto_gettogglestatus', - params: { address: searchedUser }, + method: 'pushproto_disablesnooze', }, }, - }); - setToggleStatus(res); - })(); - }, [toggleStatus]); - - useEffect(() => { - getWalletAddresses(); - }, []); + }) + }; async function getSignature(mode: number) { if (mode == 1) { const signer = provider.getSigner(account); - const signature = await signer.signMessage(`Add address ${account} to receive notifications via Push Snap in MetaMask`); + const signature = await signer.signMessage( + `Add address ${account} to receive notifications via Push Snap in MetaMask` + ); return signature; } if (mode == 2) { const signer = provider.getSigner(account); - const signature = await signer.signMessage(`Remove address ${account} to stop receive notifications via Push Snap in MetaMask`); + const signature = await signer.signMessage( + `Remove address ${account} to stop receive notifications via Push Snap in MetaMask` + ); return signature; } } const addWalletAddresses = async () => { - console.debug('searchedUser', searchedUser); const signatureResult = await getSignature(1); if (signatureResult) { if (searchedUser) { @@ -89,25 +98,25 @@ const PushSnapConfigureModal = () => { }; const [checked, setChecked] = useState(false); + + useEffect(() => { + setChecked(snoozeDuration.enabled); + }, [snoozeDuration]); + const handleChange = async (nextChecked) => { setChecked(nextChecked); - await window.ethereum?.request({ - method: 'wallet_invokeSnap', - params: { - snapId: defaultSnapOrigin, - request: { method: 'pushproto_togglepopup' }, - }, - }); - if (toggleStatus < 40) { - setToggleStatus(42); + + // When the switch is turned on + if (nextChecked) { + setSnapState(4); // Enable snooze or show the EnableSnoozeModal } else { - setToggleStatus(0); + await disableSnooze(); } + await updateSnoozeDuration(setSnoozeDuration); }; const removeWalletAddresses = async (walletSelected: string) => { const signatureResult = await getSignature(2); - console.log("Ran",signatureResult) if (signatureResult) { if (walletSelected) { await window.ethereum?.request({ @@ -137,27 +146,27 @@ const PushSnapConfigureModal = () => { }); console.debug('result', result); setAddresses(result); - } + }; const containerRef = React.useRef(null); useClickAway(containerRef, () => { - console.warn('Set show to be null'); setWalletSelected(null); - setShowRemove(null); }); const [walletSelected, setWalletSelected] = useState(); const handleWalletSelect = (address) => { setWalletSelected(address); - } + }; return ( - - + Notification Address Add or remove wallet address to receive notifications @@ -169,133 +178,130 @@ const PushSnapConfigureModal = () => { }} placeholder="0x123 .... 4567" /> - - Add - - - + Add + {addresses?.map((wallet) => ( - - {shortenText(wallet, 8)} - handleWalletSelect(wallet)} color={theme.default.color} /> - - {walletSelected === wallet && - - removeWalletAddresses(walletSelected)}>Remove - - } + + + {shortenText(wallet, 8)} + + handleWalletSelect(wallet)} + color={theme.default.color} + /> + + {walletSelected === wallet && ( + + + removeWalletAddresses(walletSelected)} + > + Remove + + + )} ))} - - - - - Snooze Notification Pop-ups - - - - - - 40} - className="react-switch" - uncheckedIcon={false} - checkedIcon={false} - height={23} - onColor="#D53A94" - width={44} - /> - - {toggleStatus > 40 ? 'On' : 'Off'} - + + {' '} + Snooze Notifications{' '} + + + + {' '} + + + + + + + When snooze is enabled, you won't receive notifications for
a specified period of time. +
-
-
+ + + + {snoozeDuration.enabled == true ? ( + <> + + {' '} + Snooze Duration{' '} + + + + {' '} + {snoozeDuration.hrsLeft} hours + + + ) : ( + '' + )} + + ); }; export default PushSnapConfigureModal; -const InfoToolTip = () => { - - - return ( - - Toggle popups in case of frequent incoming notifications - - } - > - - - - - - ) -} - const Container = styled(ItemVV2)` padding: 0px 0px 12px 9px; `; const ToolTipContainer = styled(ItemVV2)` -box-sizing: border-box; -width: 18.75rem; -// height: 7.5rem; -// max-height: 7.5rem; -background: ${(props) => props.theme.default.bg}; -border-radius: 1rem 1rem 1rem 0.125rem; -justify-content: flex-start; -border: 1px solid rgba(173, 176, 190, 0.2); -align-items: flex-start; -padding: 0.75rem 0.25rem 0.75rem 1rem; -box-shadow: 0px 4px 20px rgba(0, 0, 0, 0.05); - -@media (max-width:400px){ - width:16.75rem; -} - - + box-sizing: border-box; + width: 18.75rem; + // height: 7.5rem; + // max-height: 7.5rem; + background: ${(props) => props.theme.default.bg}; + border-radius: 1rem 1rem 1rem 0.125rem; + justify-content: flex-start; + border: 1px solid rgba(173, 176, 190, 0.2); + align-items: flex-start; + padding: 0.75rem 0.25rem 0.75rem 1rem; + box-shadow: 0px 4px 20px rgba(0, 0, 0, 0.05); + + @media (max-width: 400px) { + width: 16.75rem; + } `; const PrimaryText = styled.p` @@ -303,16 +309,19 @@ const PrimaryText = styled.p` font-size: 18px; font-weight: 500; align-self: baseline; - color:${(props) => props.theme.modalMessageColor}; + color: ${(props) => props.theme.modalMessageColor}; `; const SecondaryText = styled.p` margin: 0px; - font-size: 16px; + font-size: 12px; font-weight: 400; line-height: 24px; text-align: left; - color:${(props) => props.theme.snapSecondaryText}; + overflow: hidden; + text-overflow: ellipsis; // Show ellipsis (...) when text overflows + + color: ${(props) => props.theme.snapSecondaryText}; `; const ToolTipText = styled.p` @@ -323,25 +332,27 @@ const ToolTipText = styled.p` color: #62626a; color: ${(props) => props.theme.modalMessageColor}; text-align: left; -` +`; const SnapButton = styled(Button)` -align-self: end; -height: 36px; -z-index: 0; -font-family: 'Strawford'; -font-style: normal; -font-weight: 500; -font-size: 14px; -line-height: normal; -border-radius: 8px; -` + align-self: end; + height: 36px; + z-index: 0; + font-family: 'Strawford'; + font-style: normal; + font-weight: 500; + font-size: 14px; + line-height: normal; + border-radius: 8px; +`; const FilledButton = styled(SnapButton)` min-width: 79px; padding: 14px; background: #d53a94; - width: fit-content; + width: 79px; + height: 48px; + radius: 12px; color: #fff; `; @@ -349,12 +360,12 @@ const EnptyButton = styled(SnapButton)` flex-direction: row; color: ${(props) => props.theme.default.secondaryColor}; text-align: center; - width:auto; + width: auto; padding: 16px 24px; border: 1px solid #bac4d6; background: ${(props) => props.theme.default.bg}; gap: 4px; -` +`; const ImageInfo = styled.img` margin-right: 5px; @@ -369,10 +380,10 @@ const Input = styled.input` box-sizing: border-box; display: flex; flex: 1; - width: 100%; + width: 240px; height: 48px; - padding: 13px 16px; - margin: 10px 0px 0px; + padding: 13px 16px 13px 16px; + margin: 10px 3px 0px; background: ${(props) => props.theme.modalSearchBarBackground}; border-radius: 12px; @@ -394,15 +405,15 @@ const Input = styled.input` `; const AddressesContainer = styled.div` - display:flex; - flex-direction:column; + display: flex; + flex-direction: column; width: -webkit-fill-available; overflow-y: scroll; gap: 8px; - margin:8px 0 0 0; + margin: 8px 0 0 0; max-height: 250px; flex-wrap: nowrap; - padding:5px 5px 5px 0; + padding: 5px 5px 5px 0; &::-webkit-scrollbar-track { border-radius: 10px; } @@ -422,7 +433,7 @@ const AddressesContainer = styled.div` color-stop(0.86, #cf1c84) ); } -` +`; const AddressesSubContainer = styled(ItemHV2)` max-height: 42px; @@ -430,18 +441,18 @@ const AddressesSubContainer = styled(ItemHV2)` border-radius: 12px; background: ${(props) => props.theme.snapBackground}; justify-content: space-between; -` +`; const MoreOptions = styled(AiOutlineMore)` - width:24px; - height:24px; - cursor:pointer; -` + width: 24px; + height: 24px; + cursor: pointer; +`; const RemoveDiv = styled(ItemHV2)` border-radius: 12px; - border: 1px solid #BAC4D6; - background: #FFF; + border: 1px solid #bac4d6; + background: #fff; cursor: pointer; box-shadow: 0px 4px 20px 0px rgba(0, 0, 0, 0.05); padding: 8px 12px 8px 8px; @@ -450,4 +461,4 @@ const RemoveDiv = styled(ItemHV2)` position: absolute; right: 0; top: 3px; -` +`; diff --git a/src/components/PushSnap/PushSnapSettings.tsx b/src/components/PushSnap/PushSnapSettings.tsx index b93a413b36..47573efeb3 100644 --- a/src/components/PushSnap/PushSnapSettings.tsx +++ b/src/components/PushSnap/PushSnapSettings.tsx @@ -12,192 +12,185 @@ import PushSnapConfigureModal from './PushSnapConfigureModal'; import useModalBlur, { MODAL_POSITION } from 'hooks/useModalBlur'; import AboutSnapModal from 'modules/snap/AboutSnapModal'; - const PushSnapSettings = () => { - const { account, provider } = useAccount(); - - const theme = useTheme(); - const [walletConnected, setWalletConnected] = useState(false); - const [loading, setLoading] = useState(false); - const [addedAddress, setAddedAddress] = useState(false); - - const [snapInstalled, setSnapInstalled] = useState(false); - const defaultSnapOrigin = `npm:@pushprotocol/snap`; - - async function getInstalledSnaps() { - const installedSnaps = await window.ethereum.request({ - method: 'wallet_getSnaps', - }); - console.debug("Snaps installed", installedSnaps); - Object.keys(installedSnaps).forEach((snap) => { - if (snap == 'npm:@pushprotocol/snap') { - setSnapInstalled(true); - } - }); - } - async function getWalletAddresses() { - const result = await window.ethereum?.request({ - method: 'wallet_invokeSnap', - params: { - snapId: defaultSnapOrigin, - request: { method: 'pushproto_getaddresses' }, - }, - }); - - console.debug(account); - console.debug(walletConnected); - if (result.includes(account)) { - setAddedAddress(true); - } else { - setAddedAddress(false); - } + const { account, provider } = useAccount(); + + const theme = useTheme(); + const [walletConnected, setWalletConnected] = useState(false); + const [loading, setLoading] = useState(false); + const [addedAddress, setAddedAddress] = useState(false); + + const [snapInstalled, setSnapInstalled] = useState(false); + const defaultSnapOrigin = `npm:@pushprotocol/snap`; + + async function getInstalledSnaps() { + const installedSnaps = await window.ethereum.request({ + method: 'wallet_getSnaps', + }); + console.debug('Snaps installed', installedSnaps); + Object.keys(installedSnaps).forEach((snap) => { + if (snap == 'npm:@pushprotocol/snap') { + setSnapInstalled(true); + } + }); + } + async function getWalletAddresses() { + const result = await window.ethereum?.request({ + method: 'wallet_invokeSnap', + params: { + snapId: defaultSnapOrigin, + request: { method: 'pushproto_getaddresses' }, + }, + }); + + console.debug(account); + console.debug(walletConnected); + if (result.includes(account)) { + setAddedAddress(true); + } else { + setAddedAddress(false); } + } + useEffect(() => { + getInstalledSnaps(); + getWalletAddresses(); + }, [account, walletConnected]); + + async function connectSnap() { + let snapId = defaultSnapOrigin, + params = {}; + await window.ethereum?.request({ + method: 'wallet_requestSnaps', + params: { + [snapId]: params, + }, + }); + console.info('Snap Installed'); + } - useEffect(() => { - getInstalledSnaps(); - getWalletAddresses(); - }, [account, walletConnected]); - - - async function connectSnap() { - let snapId = defaultSnapOrigin, - params = {}; - await window.ethereum?.request({ - method: 'wallet_requestSnaps', - params: { - [snapId]: params, - }, - }); - console.info('Snap Installed'); - } - - async function connectToMetaMask() { - setLoading(true); - try { - if (!snapInstalled) { - await connectSnap(); - setSnapInstalled(true); - } - setLoading(false); - } catch (error) { - setLoading(false); - console.error('Error', error); - } + async function connectToMetaMask() { + setLoading(true); + try { + if (!snapInstalled) { + await connectSnap(); + setSnapInstalled(true); + } + setLoading(false); + } catch (error) { + setLoading(false); + console.error('Error', error); } + } - console.info("snapInstalled", snapInstalled); - - const InstallSnap = () => { - const { - isModalOpen: isMetamaskPushSnapOpen, - showModal: showPushSnapAbout, - ModalComponent: AboutPushSnapModalComponent, - } = useModalBlur(); - return ( - - - - - - - - - - - - Push Snap - - - powered by MetaMask - - - - - - You’re about to install Push Snap which allows you to receive notifications from Push directly on - MetaMask! - - - - - - {loading ? ( - - ) : ( - connectToMetaMask()}> - {!snapInstalled && 'Connect Snap'} - - )} - - - - - - About this Snap - - - - - - - ) - } + console.info('snapInstalled', snapInstalled); + const InstallSnap = () => { + const { + isModalOpen: isMetamaskPushSnapOpen, + showModal: showPushSnapAbout, + ModalComponent: AboutPushSnapModalComponent, + } = useModalBlur(); return ( - <> - {!snapInstalled ? : ( - <> - - Push Snap Settings - - - + + + + + + + + + + + Push Snap + + + powered by MetaMask + + + + + + You’re about to install Push Snap which allows you to receive notifications from Push directly on + MetaMask! + + + + + + {loading ? ( + + ) : ( + connectToMetaMask()}>{!snapInstalled && 'Connect Snap'} )} + + + + + + About this Snap + + + + + ); + }; + return ( + <> + {!snapInstalled ? ( + + ) : ( + <> + + Snap Settings + + - ); + )} + + ); }; export default PushSnapSettings; @@ -243,4 +236,4 @@ const ConnectButton = styled(SnapButton)` const InfoDiv = styled(ItemHV2)` cursor: pointer; -`; \ No newline at end of file +`; diff --git a/src/config/index.js b/src/config/index.js index aab9cdf67e..c86f14108c 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -30,3 +30,5 @@ const appConfig = { ...dynamicConfig, ...generalConfig }; // export it out export { appConfig, addresses, abis, CHAIN_DETAILS }; + +export const defaultSnapOrigin = 'npm:@pushprotocol/snap'; \ No newline at end of file diff --git a/src/helpers/TimerHelper.ts b/src/helpers/TimerHelper.ts index eabfa323a2..831bc684a1 100644 --- a/src/helpers/TimerHelper.ts +++ b/src/helpers/TimerHelper.ts @@ -43,3 +43,22 @@ export const convertTimestampToDateDayTime = (time: Date):string => { } return `${time.getDate()}/${time.getMonth() + 1}/${time.getFullYear() % 100}`; }; + +export const hoursLeftToTimestamp = (futureTimestamp: number) => { + // Get the current timestamp + const currentTimestamp = Date.now(); + + // Calculate the difference between the future timestamp and the current timestamp + const timeDifference = futureTimestamp - currentTimestamp; + + // If the difference is negative, it means the future timestamp is in the past + if (timeDifference < 0) { + return 0; // Return 0 hours left + } + + // Convert the time difference from milliseconds to hours + const hoursLeft = Math.ceil(timeDifference / (1000 * 60 * 60)); + + // Return the number of hours left + return hoursLeft; +} \ No newline at end of file diff --git a/src/helpers/index.ts b/src/helpers/index.ts index 27d13a7ee8..4607237572 100644 --- a/src/helpers/index.ts +++ b/src/helpers/index.ts @@ -1 +1,27 @@ -export * from "./PushTokenContractHelper"; \ No newline at end of file +import { defaultSnapOrigin } from "config"; +import { hoursLeftToTimestamp } from "./TimerHelper"; + +export * from "./PushTokenContractHelper"; + +export const updateSnoozeDuration = async (setSnoozeDuration) => { + const result = await window.ethereum?.request({ + method: 'wallet_invokeSnap', + params: { + snapId: defaultSnapOrigin, + request: { method: 'pushproto_getsnoozeinfo' }, + }, + }); + + if (result?.enabled === true) { + const hrsLeft = hoursLeftToTimestamp(result.duration); + setSnoozeDuration({ + enabled: true, + hrsLeft: hrsLeft + }); + } else { + setSnoozeDuration({ + enabled: false, + hrsLeft: 0 + }); + } + }; \ No newline at end of file diff --git a/src/modules/receiveNotifs/MetamaskPushSnapModal.tsx b/src/modules/receiveNotifs/MetamaskPushSnapModal.tsx index d2f94cc56d..7c575836a6 100644 --- a/src/modules/receiveNotifs/MetamaskPushSnapModal.tsx +++ b/src/modules/receiveNotifs/MetamaskPushSnapModal.tsx @@ -13,88 +13,116 @@ import { Button } from 'components/SharedStyling'; import { ReactComponent as Back } from 'assets/chat/arrowleft.svg'; import { ReactComponent as Close } from 'assets/chat/group-chat/close.svg'; import { ItemHV2, ItemVV2, SpanV2 } from 'components/reusables/SharedStylingV2'; +import ArrowLeft from 'assets/chat/arrowleft.svg'; +import { ImageV2 } from 'components/reusables/SharedStylingV2'; // Internal Configs import { AppContext } from 'contexts/AppContext'; +import EnableSnoozeModal from 'components/PushSnap/EnableSnoozeModal'; +import { SnoozeDurationType } from 'types'; +const MetamaskPushSnapModal = ({ onClose, closeEnabled = true }: { onClose: () => void; closeEnabled?: boolean }) => { + const theme = useTheme(); + const location = useLocation(); -const MetamaskPushSnapModal = ({ - onClose, - closeEnabled = true -}: { - onClose: () => void, - closeEnabled?: boolean -}) => { - const theme = useTheme(); - const location = useLocation(); + const [configure, setConfigure] = useState(false); + const [snoozeDuration, setSnoozeDuration] = useState({ + enabled: false, + hrsLeft: 0 + }); - const [configure, setConfigure] = useState(false); + const { setSnapState, SnapState } = React.useContext(AppContext); - const { setSnapState, SnapState } = React.useContext(AppContext); + const handleCloseModal = () => { + var uri = window.location.toString(); - const handleCloseModal = () => { + if (uri.indexOf('#') > 0) { + var clean_uri = uri.substring(0, uri.indexOf('#')); - var uri = window.location.toString(); - - if (uri.indexOf("#") > 0) { - var clean_uri = uri.substring(0, uri.indexOf("#")); - - window.history.replaceState({}, document.title, clean_uri); - } - - setSnapState(1); - onClose(); + window.history.replaceState({}, document.title, clean_uri); } - const isSnapRoute = location?.pathname === '/snap'; - - return ( - - - - {(SnapState !== 1 && !isSnapRoute) && setSnapState(1)} />} - - {SnapState === 1 && - Receive Notifications - } - {SnapState === 3 && - Settings - } - - {closeEnabled && - - } - - - {SnapState == 1 && } - {SnapState == 2 && } - {SnapState == 3 && } - - - - ); + setSnapState(1); + onClose(); + }; + + const isSnapRoute = location?.pathname === '/snap'; + + return ( + + + + {SnapState === 1 && ( + + Receive Notifications + + )} + {(SnapState == 3 || SnapState == 2) && ( + { + setSnapState(1); + }} + /> + )} + {SnapState === 3 && ( + + Settings + + )} + {SnapState == 4 && ( + { + setSnapState(3); + }} + /> + )} + + {closeEnabled && ( + + )} + + + {SnapState == 1 && ( + + )} + {SnapState == 2 && } + {SnapState == 3 && } + {SnapState == 4 && } + + ); }; export default MetamaskPushSnapModal; const Container = styled(ItemVV2)` - width:420px; - - @media(max-width:476px){ - width:360px; - } + width: 420px; -` \ No newline at end of file + @media (max-width: 476px) { + width: 360px; + } +`; diff --git a/src/types/index.ts b/src/types/index.ts new file mode 100644 index 0000000000..a08a4c4d2f --- /dev/null +++ b/src/types/index.ts @@ -0,0 +1,4 @@ +export type SnoozeDurationType = { + enabled: boolean; + hrsLeft: number; +};