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

fix: added alias for chatview #820

Merged
merged 3 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -2,7 +2,7 @@ import styled from 'styled-components';

import { Section } from '../components/StyledComponents';
import { CreateGroupModal, MODAL_BACKGROUND_TYPE } from "@pushprotocol/uiweb";
import { ChatViewComponent } from '@pushprotocol/uiweb';
import { ChatView } from '@pushprotocol/uiweb';

const ChatViewComponentTest = () => {
const chatFilterList = [
Expand All @@ -15,7 +15,7 @@ const ChatViewComponentTest = () => {
<h2>Chat UI Test page</h2>
{/* <CreateGroupModal onClose={()=>{console.log('in close')}} modalBackground={MODAL_BACKGROUND_TYPE.OVERLAY}/> */}
<ChatViewComponentCard>
<ChatViewComponent
<ChatView
onVerificationFail={() => console.log("BOIIII RETURNNNSSSSS")}
chatId='4ac5ab85c9c3d57adbdf2dba79357e56b2f9ef0256befe750d9f93af78d2ca68'
limit={10}
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/sdk-frontend-react/src/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ export function App() {
<Web3Context.Provider value={{ account, active, library, chainId }}>
<SocketContext.Provider value={socketData}>
<AccountContext.Provider value={{ pgpPrivateKey, setSpaceId }}>
<ChatUIProvider env={env} theme={lightChatTheme} account={account} pgpPrivateKey={pgpPrivateKey} signer={signer}>
<ChatUIProvider env={env} theme={lightChatTheme} >
<SpacesUIProvider spaceUI={spaceUI} theme={customDarkTheme}>
<Routes>
<Route
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export const ChatProfile: React.FC<IChatProfile> = ({
customStyle={{ fontSize: '17px' }}
/>
<Section
zIndex="300"
zIndex="unset"
flexDirection="row"
gap="10px"
margin="0 20px 0 auto"
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export {ChatViewComponent} from './ChatViewComponent';
export {ChatViewComponent} from './ChatViewComponent';
export {ChatViewComponent as ChatView} from './ChatViewComponent';
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ export const ConnectButtonSub = ({autoConnect = false}) => {
setSigner,
} = useChatData();
const theme = useContext(ThemeContext);
const {fetchChatProfile} = useGetChatProfile();
const {creteChatProfile} = useCreateChatProfile();
const {decryptPGPKey} = useDecryptPGPKey();


const setUserData = () => {
Expand All @@ -54,7 +51,6 @@ export const ConnectButtonSub = ({autoConnect = false}) => {
} else if (!wallet) {
setAccount('')
setSigner(undefined)
setPgpPrivateKey(null)
}
}
useEffect(() => {
Expand All @@ -63,37 +59,7 @@ export const ConnectButtonSub = ({autoConnect = false}) => {
setUserData()
}, [wallet])

useEffect(() => {
(async () => {
if (account && signer) {
if (!pgpPrivateKey) await handleUserCreation();
}
})();
}, [account, signer]);


const handleUserCreation = async () => {
if (!account && !env) return;
try {
let user = await fetchChatProfile({ profileId: account! ,env});
if (!user) {
if (!signer) return;
user = await creteChatProfile({ signer: signer ,env});
}
if (user?.encryptedPrivateKey && !pgpPrivateKey) {
const decryptPgpKey = await decryptPGPKey({
encryptedPrivateKey: user.encryptedPrivateKey,
account: account!,
signer: signer,
env: env,
});
if(decryptPgpKey)
setPgpPrivateKey(decryptPgpKey);
}
} catch (e: any) {
console.log(e);
}
};
return !signer ? (
<ConnectButtonDiv theme={theme}>
<button onClick={() => (wallet ? disconnect(wallet) : connect())}>{connecting ? 'connecting' : wallet ? 'disconnect' : 'Connect Wallet'}</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,23 +375,19 @@ export const MessageInput: React.FC<MessageInputProps> = ({
}
};

return !Object.keys(chatFeed || {}).length ? (
<>
{!pgpPrivateKey && (isConnected || !!signer) && (
<TypebarSection
width="100%"
overflow="hidden"
borderRadius="13px"
position="static"
padding={` ${pgpPrivateKey ? '13px 16px' : ''}`}
background={`${theme.backgroundColor?.messageInputBackground}`}
alignItems="center"
justifyContent="space-between"
>
<ConnectButtonSection autoConnect={autoConnect} />
</TypebarSection>
)}
</>
return !(pgpPrivateKey && account) && isConnected ? (
<TypebarSection
width="100%"
overflow="hidden"
borderRadius="13px"
position="static"
padding={` ${pgpPrivateKey ? '13px 16px' : ''}`}
background={`${theme.backgroundColor?.messageInputBackground}`}
alignItems="center"
justifyContent="space-between"
>
<ConnectButtonSection autoConnect={autoConnect} />
</TypebarSection>
) : !checkIfIntent({ chat: chatFeed, account: account! }) &&
Object.keys(chatFeed || {}).length ? (
<TypebarSection
Expand Down Expand Up @@ -484,7 +480,7 @@ export const MessageInput: React.FC<MessageInputProps> = ({
groupInfo={chatFeed?.groupInformation}
subheader="Please make sure the following conditions
are met to pariticpate and send messages."
alert={true}
alert={true}
/>
<ConnectWrapperClose
onClick={() => {
Expand All @@ -496,7 +492,10 @@ export const MessageInput: React.FC<MessageInputProps> = ({
>
<ConnectClose>Cancel</ConnectClose>
</ConnectWrapperClose>
<InfoContainer cta='https://push.org/docs/chat/build/conditional-rules-for-group/' label="Learn more about access gating rules" />
<InfoContainer
cta="https://push.org/docs/chat/build/conditional-rules-for-group/"
label="Learn more about access gating rules"
/>
</Section>
{/* </Section> */}
</Modal>
Expand Down
37 changes: 36 additions & 1 deletion packages/uiweb/src/lib/dataProviders/ChatDataProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import useGetChatProfile from '../hooks/useGetChatProfile';
import { IUser, SignerType } from '@pushprotocol/restapi';
import { IChatTheme, lightChatTheme } from '../components/chat/theme';
import { getAddressFromSigner, pCAIP10ToWallet } from '../helpers';
import useCreateChatProfile from '../hooks/useCreateChatProfile';
import useDecryptPGPKey from '../hooks/useDecryptPGPKey';


export interface IChatUIProviderProps {
Expand Down Expand Up @@ -40,6 +42,8 @@ export const ChatUIProvider = ({

const [isPushChatSocketConnected, setIsPushChatSocketConnected] =
useState<boolean>(false);
const {createChatProfile} = useCreateChatProfile();
const {decryptPGPKey} = useDecryptPGPKey();

useEffect(() => {
(async()=>{
Expand All @@ -59,9 +63,40 @@ export const ChatUIProvider = ({
setPgpPrivateKeyVal(pgpPrivateKey);
})()

}, [env,account,pgpPrivateKey,signer])
}, [env,account,signer,pgpPrivateKey])


useEffect(() => {
(async () => {
if (accountVal && signerVal) {
if (!pgpPrivateKeyVal) await handleUserCreation();
}
})();
}, [accountVal, signerVal]);


const handleUserCreation = async () => {
if (!accountVal && !envVal) return;
try {
let user = await fetchChatProfile({ profileId: accountVal! ,env:envVal});
if (!user) {
if (!signerVal) return;
user = await createChatProfile({ signer: signerVal ,env:envVal});
}
if (user?.encryptedPrivateKey && !pgpPrivateKey) {
const decryptedPgpKey = await decryptPGPKey({
encryptedPrivateKey: user.encryptedPrivateKey,
account: accountVal!,
signer: signerVal,
env: envVal,
});
if(decryptedPgpKey)
setPgpPrivateKeyVal(decryptedPgpKey);
}
} catch (e: any) {
console.log(e);
}
};



Expand Down
4 changes: 2 additions & 2 deletions packages/uiweb/src/lib/hooks/useCreateChatProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface CreateChatProfileParams {
}

const useCreateChatProfile = () => {
const creteChatProfile = useCallback(
const createChatProfile = useCallback(
async ({
signer,
env
Expand All @@ -27,7 +27,7 @@ const useCreateChatProfile = () => {
[]
);

return { creteChatProfile };
return { createChatProfile };
};

export default useCreateChatProfile;