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

Fixed some snap flow issue #1374

Merged
merged 6 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import React, { useEffect } from 'react';

// External Packages
import styled, { useTheme } from 'styled-components';
import { useNavigate } from 'react-router-dom';


// Internal Compoonents
import { A } from 'primaries/SharedStyling';
Expand All @@ -16,10 +18,9 @@ import AppStoreQRCode from 'assets/PushSnaps/AppStoreQRCode.svg';
import PlayStoreQRCode from 'assets/PushSnaps/PlayStoreQRCode.svg';
import AppleIcon from 'assets/PushSnaps/AppleIcon.svg';
import PlayStore from 'assets/PushSnaps/PlayStore.svg';
import { useNavigate } from 'react-router-dom';


const InstallMetamaskSnapModal = ({
const InstallPushSnapModal = ({
setSnapState,
configure,
setConfigure
Expand Down Expand Up @@ -65,7 +66,7 @@ const InstallMetamaskSnapModal = ({
configure ? (
<InstallButton onClick={() => {
setSnapState(3)
navigate('/snap')
// navigate('/snap')
}}>
Configure
</InstallButton>
Expand All @@ -91,7 +92,9 @@ const InstallMetamaskSnapModal = ({
Push Browser Extension
</SpanV2>
</SnapInner>
<InstallButton>Install</InstallButton>
<a href='https://chromewebstore.google.com/detail/push-protocol-alpha/lbdcbpaldalgiieffakjhiccoeebchmg' target='_blank'>
<InstallButton>Install</InstallButton>
</a>
</SnapContainer>
<SnapContainer>
<SnapInner>
Expand Down Expand Up @@ -203,7 +206,7 @@ const InstallMetamaskSnapModal = ({
);
};

export default InstallMetamaskSnapModal;
export default InstallPushSnapModal;

const SnapContainer = styled(ItemHV2)`
border-radius: 14px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import { useAccount } from 'hooks';
import { device } from 'config/Globals';


const MetamaskSnapConfigureModal = ({
title
}) => {
const PushSnapConfigureModal = () => {
const [walletAddresses, setWalletAddresses] = useState([]);
const [addresses, setAddresses] = useState([]);
const [searchedUser, setSearchedUser] = useState('');
Expand Down Expand Up @@ -141,7 +139,6 @@ const MetamaskSnapConfigureModal = ({

const containerRef = React.useRef(null);
useClickAway(containerRef, () => {
console.log('Set show to be null');
setWalletSelected(null);
setShowRemove(null);
});
Expand All @@ -154,14 +151,7 @@ const MetamaskSnapConfigureModal = ({

return (
<Container >
<SpanV2
fontSize="22px"
fontWeight="500"
color={theme.modalMessageColor}
alignSelf={title === 'Push Snap Settings' ? 'baseline' : 'center'}
>
{title}
</SpanV2>


<ItemVV2
alignItems="baseline"
Expand Down Expand Up @@ -249,7 +239,7 @@ const MetamaskSnapConfigureModal = ({
);
};

export default MetamaskSnapConfigureModal;
export default PushSnapConfigureModal;

const InfoToolTip = () => {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { device } from 'config/Globals';
import LoaderSpinner, { LOADER_TYPE } from 'components/reusables/loaders/LoaderSpinner';
import InfoLogo from 'assets/PushSnaps/spam-icon.svg';
import { useAccount } from 'hooks';
import MetamaskSnapConfigureModal from './MetamaskSnapConfigureModal';
import PushSnapConfigureModal from './PushSnapConfigureModal';
import useModalBlur, { MODAL_POSITION } from 'hooks/useModalBlur';
import AboutSnapModal from 'modules/snap/AboutSnapModal';

Expand Down Expand Up @@ -182,7 +182,18 @@ const PushSnapSettings = () => {
return (
<>
{!snapInstalled ? <InstallSnap /> : (
<MetamaskSnapConfigureModal title={'Push Snap Settings'}/>
<>
<SpanV2
fontWeight="500"
fontSize="22px"
color={theme.modalMessageColor}
flex="1"
padding='0px 0px 0px 9px'
>
Push Snap Settings
</SpanV2>
<PushSnapConfigureModal/>
</>
)}

</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react';

// External Packages
import styled, { useTheme } from 'styled-components';
import { useNavigate } from 'react-router-dom';

// Internal Compoonents
import { ItemHV2, ItemVV2, SpanV2 } from 'components/reusables/SharedStylingV2';
Expand All @@ -14,8 +15,11 @@ import WalletLogo from 'assets/PushSnaps/Wallet.svg';
import NotificationLogo from 'assets/PushSnaps/Notification.svg';
import Metamask from 'assets/PushSnaps/metamasksnap.svg';

const SnapInformationModal = () => {
const SnapInformationModal = ({
handleCloseModal
}) => {
const theme = useTheme();
const navigate = useNavigate();

const defaultSnapOrigin = 'npm:@pushprotocol/snap';

Expand All @@ -29,18 +33,22 @@ const SnapInformationModal = () => {
};

const installSnap = async () => {
await connectSnap();
const res = await window.ethereum?.request({
method: 'wallet_invokeSnap',
params: {
snapId: defaultSnapOrigin,
request: { method: 'pushproto_welcome' },
},
});

if (res) {
window.open("/snap", '_self');
}
handleCloseModal();
navigate('/snap');

// await connectSnap();
// const res = await window.ethereum?.request({
// method: 'wallet_invokeSnap',
// params: {
// snapId: defaultSnapOrigin,
// request: { method: 'pushproto_welcome' },
// },
// });

// if (res) {
// window.open("/snap", '_self');
// }
};

return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/userSettings/UserSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import ManageNotifSettingDropdown from 'components/dropdowns/ManageNotifSettingD
// Internal Configs
import { device } from 'config/Globals';
import ChannelListSettings from 'components/channel/ChannelListSettings';
import PushSnapSettings from 'components/MetamaskSnap/PushSnapSettings';
import PushSnapSettings from 'components/PushSnap/PushSnapSettings';
import EmptyNotificationSettings from 'components/channel/EmptyNotificationSettings';

interface ChannelListItem {
Expand Down
39 changes: 26 additions & 13 deletions src/modules/receiveNotifs/MetamaskPushSnapModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ import React, { useEffect, useState } from 'react';

// External Packages
import styled, { useTheme } from 'styled-components';
import { useLocation } from 'react-router-dom';

// Internal Compoonents
import InstallPushSnapModal from 'components/PushSnap/InstallPushSnapModal';
import PushSnapConfigureModal from 'components/PushSnap/PushSnapConfigureModal';
import SnapInformationModal from 'components/PushSnap/SnapInformationModal';
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 InstallMetamaskSnapModal from 'components/MetamaskSnap/InstallMetamaskSnapModal';
import MetamaskSnapConfigureModal from 'components/MetamaskSnap/MetamaskSnapConfigureModal';
import SnapInformationModal from 'components/MetamaskSnap/SnapInformationModal';
import { Button } from 'components/SharedStyling';
import { ItemHV2, ItemVV2, SpanV2 } from 'components/reusables/SharedStylingV2';
import GLOBALS, { device, globalsMargin } from "config/Globals";

// Internal Configs
import { AppContext } from 'contexts/AppContext';
import { useLocation } from 'react-router-dom';


const MetamaskPushSnapModal = ({
onClose,
Expand All @@ -35,20 +37,22 @@ const MetamaskPushSnapModal = ({
var uri = window.location.toString();

if (uri.indexOf("#") > 0) {
var clean_uri = uri.substring(0,uri.indexOf("#"));
var clean_uri = uri.substring(0, uri.indexOf("#"));

window.history.replaceState({},document.title, clean_uri);
window.history.replaceState({}, document.title, clean_uri);
}

setSnapState(1);
onClose();
}

const isSnapRoute = location?.pathname === '/snap';

return (
<Container padding="20px 15px" >
<ItemHV2 justifyContent='space-between'>

{SnapState !== 1 && <Back width='24px' cursor='pointer' onClick={() => setSnapState(1)} />}
{(SnapState !== 1 && !isSnapRoute) && <Back width='24px' cursor='pointer' onClick={() => setSnapState(1)} />}

{SnapState === 1 && <SpanV2
fontWeight="500"
Expand All @@ -58,17 +62,26 @@ const MetamaskPushSnapModal = ({
>
Receive Notifications
</SpanV2>}
{closeEnabled &&
{SnapState === 3 && <SpanV2
fontWeight="500"
fontSize="22px"
color={theme.modalMessageColor}
flex="1"
>
Settings
</SpanV2>}

{closeEnabled &&
<Close
onClick={handleCloseModal}
style={{ cursor: 'pointer' }}
/>
}
</ItemHV2>

{SnapState == 1 && <InstallMetamaskSnapModal setSnapState={setSnapState} setConfigure={setConfigure} configure={configure} />}
{SnapState == 2 && <SnapInformationModal />}
{SnapState == 3 && <MetamaskSnapConfigureModal title={'Settings'}/>}
{SnapState == 1 && <InstallPushSnapModal setSnapState={setSnapState} setConfigure={setConfigure} configure={configure} />}
{SnapState == 2 && <SnapInformationModal handleCloseModal={handleCloseModal} />}
{SnapState == 3 && <PushSnapConfigureModal/>}


</Container>
Expand Down
67 changes: 41 additions & 26 deletions src/modules/snap/SnapModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ import { useNavigate } from 'react-router-dom';
import styled, { useTheme } from 'styled-components';

// Internal Components
import { ButtonV2, H2V2, ItemHV2, ItemVV2, SpanV2 } from 'components/reusables/SharedStylingV2';
import LoaderSpinner, { LOADER_TYPE } from 'components/reusables/loaders/LoaderSpinner';
import { AppContext } from 'contexts/AppContext';
import { useAccount } from 'hooks';
import Info from 'segments/Info';
import { H2, Image, Item, Section, Span } from '../../primaries/SharedStyling';

// Internal Configs
import ActiveIcon from 'assets/PushSnaps/ActiveIcon.svg';
import BellRinging from 'assets/PushSnaps/BellRinging.svg';
import GasPump from 'assets/PushSnaps/GasPump.svg';
Expand All @@ -23,9 +15,17 @@ import NotificationLogo from 'assets/PushSnaps/Notification.svg';
import PushMetamaskLogo from 'assets/PushSnaps/PushMetamaskLogo.svg';
import SnapExample from 'assets/PushSnaps/SnapExample.svg';
import InfoLogo from 'assets/PushSnaps/spam-icon.svg';
import { ButtonV2, H2V2, ItemHV2, ItemVV2, SpanV2 } from 'components/reusables/SharedStylingV2';
import LoaderSpinner, { LOADER_TYPE } from 'components/reusables/loaders/LoaderSpinner';
import { AppContext } from 'contexts/AppContext';
import { useAccount } from 'hooks';
import Info from 'segments/Info';
import { H2, Image, Item, Section, Span } from '../../primaries/SharedStyling';
import AboutSnapModal from './AboutSnapModal';

// Internal Configs
import GLOBALS, { device, globalsMargin } from 'config/Globals';
import useModalBlur, { MODAL_POSITION } from 'hooks/useModalBlur';
import AboutSnapModal from './AboutSnapModal';


const SnapModule = () => {
Expand Down Expand Up @@ -264,18 +264,32 @@ const SnapModule = () => {
</SpanV2>
</ItemHV2>
) : (
<ItemVV2>
{loading ? (
<LoaderSpinner
type={LOADER_TYPE.SEAMLESS}
spinnerSize={44}
/>
) : (
<ConnectButton onClick={() => connectToMetaMask()}>
{!snapInstalled ? 'Connect Snap' : 'Connect Using MetaMask '}
</ConnectButton>
)}
</ItemVV2>
<ItemHV2 gap="16px">
<ItemVV2>
{loading && !snapInstalled ? (
<LoaderSpinner
type={LOADER_TYPE.SEAMLESS}
spinnerSize={44}
/>
) : (
<ConnectButton disabled={!snapInstalled ? false : true} onClick={() => connectToMetaMask()} >
{!snapInstalled ? 'Step 1: Install Snap' : 'Step 1: Completed'}
</ConnectButton>
)}
</ItemVV2>
<ItemVV2>
{loading && snapInstalled ? (
<LoaderSpinner
type={LOADER_TYPE.SEAMLESS}
spinnerSize={44}
/>
) : (
<ConnectButton disabled={snapInstalled ? false : true} signOnMM={snapInstalled ? true : false} onClick={() => connectToMetaMask()} >
Step 2: Sign In with Metamask 🦊
</ConnectButton>
)}
</ItemVV2>
</ItemHV2>
)}

{walletConnected || addedAddress ? (
Expand Down Expand Up @@ -382,12 +396,13 @@ const SnapButton = styled(ButtonV2)`
`;

const ConnectButton = styled(SnapButton)`
min-width: 230px;
min-width: 280px;
padding: 16px 24px;
background: #d53a94;
border: 1px solid #d53a94;


background: ${props => props.signOnMM ? '#222222' : '#d53a94'};
border: ${props => props.signOnMM ? '1px solid #2a2a2a' : '1px solid #d53a94'};
opacity: ${props => props.disabled ? '0.5' : '1'};
pointer-events: ${props => props.disabled ? 'none' : 'auto'};
cursor: ${props => props.disabled ? 'not-allowed' : 'pointer'};
`;

const SettingsButton = styled(SnapButton)`
Expand Down
1 change: 0 additions & 1 deletion src/pages/SnapPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import styled from 'styled-components';

// Internal Components
import { SectionV2 } from 'components/reusables/SharedStylingV2';
import ReceiveNotifsModule from "modules/receiveNotifs/ReceiveNotifsModule";

// Internal Configs
import GLOBALS from "config/Globals";
Expand Down