From 8a0ac144134a3e4d08050afd14d2c362b1f9090c Mon Sep 17 00:00:00 2001
From: Szymon Szlachtowicz <38212223+Szymx95@users.noreply.github.com>
Date: Wed, 5 Jan 2022 03:57:24 +0100
Subject: [PATCH] Add metamask support (#173)
---
.../src/components/Channels/Channels.tsx | 40 +++++----
packages/react-chat/src/components/Chat.tsx | 5 +-
.../src/components/Modals/LogoutModal.tsx | 3 +
.../components/Modals/UserCreationModal.tsx | 10 ++-
.../src/components/Modals/WalletModal.tsx | 84 ++++++++++++++++++-
.../src/contexts/identityProvider.tsx | 24 +++++-
packages/status-communities/src/contacts.ts | 31 ++-----
packages/status-communities/src/identity.ts | 7 +-
packages/status-communities/src/messenger.ts | 9 ++
packages/status-communities/src/utils.ts | 40 ++++++++-
10 files changed, 200 insertions(+), 53 deletions(-)
diff --git a/packages/react-chat/src/components/Channels/Channels.tsx b/packages/react-chat/src/components/Channels/Channels.tsx
index 7f782e54..3b4f6c12 100644
--- a/packages/react-chat/src/components/Channels/Channels.tsx
+++ b/packages/react-chat/src/components/Channels/Channels.tsx
@@ -2,8 +2,10 @@ import React, { useEffect } from "react";
import styled from "styled-components";
import { ChatState, useChatState } from "../../contexts/chatStateProvider";
+import { useIdentity } from "../../contexts/identityProvider";
import { useMessengerContext } from "../../contexts/messengerProvider";
import { CreateIcon } from "../Icons/CreateIcon";
+import { UserCreation } from "../UserCreation/UserCreation";
import { Channel } from "./Channel";
@@ -55,24 +57,34 @@ export function Channels({ onCommunityClick }: ChannelsProps) {
}
}, [notifications, activeChannel]);
const setChatState = useChatState()[1];
+ const identity = useIdentity();
+
return (
-
-
- Chat
- setChatState(ChatState.ChatCreation)}>
-
-
-
-
-
-
-
+ {identity ? (
+ <>
+
+ Chat
+ setChatState(ChatState.ChatCreation)}>
+
+
+
+
+
+
+
+ >
+ ) : (
+
+ )}
);
diff --git a/packages/react-chat/src/components/Chat.tsx b/packages/react-chat/src/components/Chat.tsx
index 83707e35..e6ec4c97 100644
--- a/packages/react-chat/src/components/Chat.tsx
+++ b/packages/react-chat/src/components/Chat.tsx
@@ -2,7 +2,6 @@ import React, { useState } from "react";
import styled from "styled-components";
import { ChatState, useChatState } from "../contexts/chatStateProvider";
-import { useIdentity } from "../contexts/identityProvider";
import { useNarrow } from "../contexts/narrowProvider";
import { Channels } from "./Channels/Channels";
@@ -20,7 +19,6 @@ import { UserCreationModal } from "./Modals/UserCreationModal";
import { WalletConnectModal } from "./Modals/WalletConnectModal";
import { WalletModal } from "./Modals/WalletModal";
import { ToastMessageList } from "./ToastMessages/ToastMessageList";
-import { UserCreation } from "./UserCreation/UserCreation";
function Modals() {
return (
@@ -42,13 +40,12 @@ export function Chat() {
const [state] = useChatState();
const [showMembers, setShowMembers] = useState(false);
const narrow = useNarrow();
- const identity = useIdentity();
return (
{!narrow && (
- {identity ? : }
+
)}
{state === ChatState.ChatBody && (
diff --git a/packages/react-chat/src/components/Modals/LogoutModal.tsx b/packages/react-chat/src/components/Modals/LogoutModal.tsx
index a720367b..c838dce4 100644
--- a/packages/react-chat/src/components/Modals/LogoutModal.tsx
+++ b/packages/react-chat/src/components/Modals/LogoutModal.tsx
@@ -6,6 +6,7 @@ import {
useIdentity,
useNickname,
useSetIdentity,
+ useSetNikcname,
} from "../../contexts/identityProvider";
import { useModal } from "../../contexts/modalProvider";
import { ButtonNo, ButtonYes } from "../Buttons/buttonStyle";
@@ -26,6 +27,7 @@ export const LogoutModalName = "LogoutModal";
export const LogoutModal = () => {
const { setModal } = useModal(LogoutModalName);
const logout = useSetIdentity();
+ const setNickname = useSetNikcname();
const identity = useIdentity();
const nickname = useNickname();
@@ -71,6 +73,7 @@ export const LogoutModal = () => {
onClick={() => {
setModal(false);
logout(undefined);
+ setNickname(undefined);
}}
>
Disconnect
diff --git a/packages/react-chat/src/components/Modals/UserCreationModal.tsx b/packages/react-chat/src/components/Modals/UserCreationModal.tsx
index 6a6c6e6d..15b6b29a 100644
--- a/packages/react-chat/src/components/Modals/UserCreationModal.tsx
+++ b/packages/react-chat/src/components/Modals/UserCreationModal.tsx
@@ -6,6 +6,7 @@ import {
useIdentity,
useSetIdentity,
useSetNikcname,
+ useWalletIdentity,
} from "../../contexts/identityProvider";
import { useModal } from "../../contexts/modalProvider";
import { Contact } from "../../models/Contact";
@@ -36,6 +37,7 @@ import { EmojiKey, UserAddress } from "./ProfileModal";
export const UserCreationModalName = "UserCreationModal";
export function UserCreationModal() {
+ const walletIdentity = useWalletIdentity();
const identity = useIdentity();
const setIdentity = useSetIdentity();
const setNickname = useSetNikcname();
@@ -93,7 +95,7 @@ export function UserCreationModal() {
onChange={(e) => setCustomNameInput(e.currentTarget.value)}
/>
)}
- {!nextStep && encryptedIdentity && (
+ {!nextStep && encryptedIdentity && !walletIdentity && (