Skip to content

Commit

Permalink
Now showing how to and github link before connection for ease of unde…
Browse files Browse the repository at this point in the history
…rstanding of the platform and features
  • Loading branch information
leonacostaok committed Nov 8, 2023
1 parent b56aaaf commit 91dda98
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 55 deletions.
2 changes: 1 addition & 1 deletion example/components/Decrypt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function Decrypt({ isActive }: { isActive: boolean }) {
setMessage(null);
};
return (
<Tab isActive={isActive}>
<Tab isActive={isActive} requiresConnection={true}>
{message ? (
<>
<Text>This is your decrypted message</Text>
Expand Down
2 changes: 1 addition & 1 deletion example/components/Encrypt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function Encrypt({ isActive }: { isActive: boolean }) {
setEncryptedMessage(null);
};
return (
<Tab isActive={isActive}>
<Tab isActive={isActive} requiresConnection={true}>
{encryptedMessage ? (
<>
<Text>Encrypted message</Text>
Expand Down
32 changes: 12 additions & 20 deletions example/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import styled, {css} from "styled-components";
import styled from "styled-components";
import {LinkText, Text} from "./Text";
import {MainHeading} from "./Heading";
import MetaMaskCard from "./MetaMaskCard";
import React from "react";
import {useWeb3React} from "@web3-react/core";
import {shortenAddress} from "../utils";
Expand All @@ -14,24 +13,17 @@ export const Header = () => {
<MainHeading>
MetaMask Encrypt/Decrypt
</MainHeading>
{!account ? (
<ConnectSection>
<Text>Use the section below to connect to MetaMask wallet provider</Text>
<MetaMaskCard />
</ConnectSection>
) : (
<>
<Text>
Connected as: {shortenAddress(account)}
<br/>
<LinkText onClick={() => {
if (connector?.deactivate) connector.deactivate()
if (connector?.resetState) connector.resetState()
}}>
Disconnect
</LinkText>
</Text>
</>
{account && (
<Text>
Connected as: {shortenAddress(account)}
<br/>
<LinkText onClick={() => {
if (connector?.deactivate) connector.deactivate()
if (connector?.resetState) connector.resetState()
}}>
Disconnect
</LinkText>
</Text>
)}
</HeaderWrapper>
</HeaderContainer>
Expand Down
25 changes: 20 additions & 5 deletions example/components/HowTo.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
import { Tab } from "./Tab";
import {Text} from "./Text";
import {Link, Text} from "./Text";
import {TabOptions} from "../pages";
import {styled} from "styled-components";
import Image from 'next/image'

export function HowTo({ isActive, setActiveTab }: {
export function HowTo({ isActive }: {
setActiveTab?: (el: TabOptions) => void
isActive: boolean
}) {

return (
<Tab isActive={isActive}>
<Tab isActive={isActive} requiresConnection={false}>
<HowToWrapper>
<Text>
This project works with asymmetric cryptography to encrypt and decrypt messages.
The project is open-source and can be found in{' '}
<Link href="https://github.com/leonacostaok/metamask-encrypt-decrypt"
rel="noopener noreferrer"
target="_blank">
GitHub
</Link>.
</Text>
<Text>
Encryption is a feature of asymmetric cryptography that allows us to share PRIVATE messages between known parties. Private messages, in this context, are messages no one else than the recipient should see.
It works with asymmetric cryptography to encrypt and decrypt messages.
</Text>
<Text>
Encryption is a feature of asymmetric cryptography that allows us to share PRIVATE messages between known parties.
</Text>
<Text>
Private messages, in this context, are messages no one else than the recipient should see.
</Text>
<Text>
If I want to send a private message to a friend, and only for him to see that message, then I will encrypt it with his public key, and he will be able to decrypt it with his private key.
Expand All @@ -41,6 +52,10 @@ export function HowTo({ isActive, setActiveTab }: {
<Text>
This process is only used to share information that should not be public (it is masked behind an encryption), and no one but the person who has the message and then one that received the message can see it otherwise.
</Text>

<Text>
This app does not have access to your private key, and will interact with your wallet provider for the decryption of the messages.
</Text>
</HowToWrapper>
</Tab>
);
Expand Down
2 changes: 1 addition & 1 deletion example/components/RequestPublicKey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function RequestPublicKey({ isActive }: { isActive: boolean }) {
setPublicKey(await provider.send("eth_getEncryptionPublicKey", [account]));
};
return (
<Tab isActive={isActive}>
<Tab isActive={isActive} requiresConnection={true}>
{publicKey ? (
<>
<Text>This is your public key</Text>
Expand Down
31 changes: 30 additions & 1 deletion example/components/Tab.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
import { ReactNode } from "react";
import styled from "styled-components";
import {TabOptions} from "../pages";
import {useWeb3React} from "@web3-react/core";
import {Text} from "./Text";
import MetaMaskCard from "./MetaMaskCard";

export function Tab({
isActive,
children,
requiresConnection
}: {
requiresConnection?: boolean,
isActive: boolean;
setActiveTab?: (el: TabOptions) => void
children?: ReactNode;
}) {
return isActive ? <TabWrapper>{children}</TabWrapper> : <></>;
const { account } = useWeb3React();
return isActive ? (requiresConnection && account) || !requiresConnection ? (
<TabWrapper>
{children}
</TabWrapper>
) : (
<ConnectSection>
<Text>This section requires authentication, please connect to a wallet provider from the list below to continue</Text>
<MetaMaskCard />
</ConnectSection>
) : <></>;
}

const TabWrapper = styled.div`
Expand All @@ -28,3 +43,17 @@ const TabWrapper = styled.div`
max-width: 500px;
}
`;

const ConnectSection = styled.div`
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
gap: 20px;
padding: 50px 0;
p {
text-align: center;
max-width: 500px;
}
`;

14 changes: 14 additions & 0 deletions example/components/Text.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import styled from "styled-components";
import NextLink from 'next/link'

export const Text = styled.p`
text-align: center;
Expand Down Expand Up @@ -39,3 +40,16 @@ export const LinkText = styled.span`
cursor: pointer !important;
}
`

export const Link = styled(NextLink)`
text-align: center;
line-height: 1.4;
text-decoration: underline;
color:white;
margin-block-start: 0;
margin-block-end: 0;
&:hover {
color: rgb(42, 196, 231);
cursor: pointer !important;
}
`
1 change: 1 addition & 0 deletions example/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
const nextConfig = {
output: 'export',
images: {unoptimized: true},
env: {
infuraKey: process.env.INFURA_KEY,
alchemyKey: process.env.ALCHEMY_KEY,
Expand Down
49 changes: 23 additions & 26 deletions example/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,31 @@ const tabsList: TabType[] = [
{ tab: TabOptions.DECRYPT, name: "Decrypt", content: Decrypt },
];
export default function Home() {
const { account } = useWeb3React();
const [activeTab, setActiveTab] = useState(TabOptions.HOW_TO);
return (
<>
{account && (
<ScreenContainer>
<TabsSelector>
{tabsList.map((item) => (
<TabButton
active={activeTab === item.tab}
onClick={() => setActiveTab(item.tab)}
>
{item.name}
</TabButton>
))}
</TabsSelector>
<Tabs>
<TabContent>
{tabsList.map((item) => (
<item.content isActive={activeTab === item.tab}
setActiveTab={setActiveTab}
/>
))}
</TabContent>
</Tabs>
</ScreenContainer>
)}
</>
<ScreenContainer>
<TabsSelector>
{tabsList.map((item) => (
<TabButton
key={`tab-button-${item.name}`}
active={activeTab === item.tab}
onClick={() => setActiveTab(item.tab)}
>
{item.name}
</TabButton>
))}
</TabsSelector>
<Tabs>
<TabContent>
{tabsList.map((item) => (
<item.content key={`tab-content-${item.name}`}
isActive={activeTab === item.tab}
setActiveTab={setActiveTab}
/>
))}
</TabContent>
</Tabs>
</ScreenContainer>
);
}

Expand Down

0 comments on commit 91dda98

Please sign in to comment.