Skip to content

Commit

Permalink
fix: fixed signer bug (#1073)
Browse files Browse the repository at this point in the history
  • Loading branch information
mishramonalisha76 authored Jan 30, 2024
1 parent 3f84c10 commit 0d3fd91
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
18 changes: 15 additions & 3 deletions packages/examples/sdk-frontend-react/src/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useContext, useEffect, useMemo, useState } from 'react';
import styled from 'styled-components';
import { Route, Routes, Link } from 'react-router-dom';
import { useWeb3React } from '@web3-react/core';
import { PushAPI } from "@pushprotocol/restapi";
import ConnectButtonComp from './components/Connect';
import { Checkbox } from './components/Checkbox';
import Dropdown from './components/Dropdown';
Expand Down Expand Up @@ -69,7 +70,7 @@ import {
SpaceInvitesComponent,
} from './SpaceUITest';
import { useSpaceComponents } from './SpaceUITest/useSpaceComponents';
import * as PushAPI from '@pushprotocol/restapi';
import * as PushApi from '@pushprotocol/restapi';
import { ChatWidgetTest } from './ChatWidgetTest';
import {
CHAT_THEME_OPTIONS,
Expand All @@ -94,6 +95,7 @@ import GetGroupInfoTest from './ChatTest/GetGroupInfoTest';
import GetGroupMembersTest from './ChatTest/GetGroupMembersTest';
import VideoV2 from './Video';


window.Buffer = window.Buffer || Buffer;

interface Web3ReactState {
Expand Down Expand Up @@ -230,6 +232,7 @@ export function App() {
const { SpaceWidgetComponent } = useSpaceComponents();
const [spaceId, setSpaceId] = useState<string>('');
const [pgpPrivateKey, setPgpPrivateKey] = useState<string>('');
const [pushUser, setPushUser] = useState<PushAPI>();

const socketData = useSDKSocket({
account: account,
Expand All @@ -250,12 +253,18 @@ export function App() {
(async () => {
if (!account || !env || !library) return;

const user = await PushAPI.user.get({ account: account, env });
const user = await PushApi.user.get({ account: account, env });
let pgpPrivateKey;
const librarySigner = await library.getSigner(account);
const pushUser = await PushAPI.initialize(librarySigner!, {
env: env,
account: account,
alpha: { feature: ['SCALABILITY_V2'] },
})
setPushUser(pushUser);
setSigner(librarySigner);
if (user?.encryptedPrivateKey) {
pgpPrivateKey = await PushAPI.chat.decryptPGPKey({
pgpPrivateKey = await PushApi.chat.decryptPGPKey({
encryptedPGPPrivateKey: user.encryptedPrivateKey,
account: account,
signer: librarySigner,
Expand Down Expand Up @@ -320,6 +329,9 @@ export function App() {
<ChatUIProvider
env={env}
theme={lightChatTheme}
// pushUser={pushUser}
// account={account}
// pgpPrivateKey={pgpPrivateKey}
signer={signer}
>
<SpacesUIProvider spaceUI={spaceUI} theme={customDarkTheme}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,16 @@ interface IThemeProps {
}

const ConnectButtonSection = ({ autoConnect }: { autoConnect: boolean }) => {
const { signer } = useChatData();
const { pgpPrivateKey,account } = useChatData();

return (
<Section
width="100%"
justifyContent="space-between"
alignItems="center"
padding="8px"
>
{!signer && (
{!(pgpPrivateKey && account) && (
<Span
padding="8px 8px 8px 16px"
color="#B6BCD6"
Expand Down
7 changes: 4 additions & 3 deletions packages/uiweb/src/lib/dataProviders/ChatDataProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ export const ChatUIProvider = ({
const address = await getAddressFromSigner(signer!);
setAccountVal(address);
} else if (!signer && pushUser) {
const profile = await fetchChatProfile({});
const profile = await fetchChatProfile({pushUser});

setAccountVal(profile?.wallets);
} else {
setAccountVal(GUEST_MODE_ACCOUNT);
Expand All @@ -82,7 +83,7 @@ export const ChatUIProvider = ({
useEffect(() => {
(async () => {

if (accountVal && envVal ) {
if (accountVal && envVal && !pushUserVal ) {
const pushUser = await initializePushUser({
signer: signerVal,
account: accountVal!,
Expand Down Expand Up @@ -115,7 +116,7 @@ export const ChatUIProvider = ({
(async () => {
let user;
if (account) {
user = await fetchChatProfile({ profileId: account, env });
user = await fetchChatProfile({ profileId: account, env ,pushUser});
if (user) setConnectedProfile(user);
}
})();
Expand Down
9 changes: 6 additions & 3 deletions packages/uiweb/src/lib/hooks/chat/useChatProfile.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import * as PushAPI from '@pushprotocol/restapi';
import { useCallback, useContext } from 'react';
import { useChatData } from './useChatData';
import { Env } from '@pushprotocol/restapi';
import { PushAPI } from "@pushprotocol/restapi";

export interface FetchProfileParams {
profileId?: string;
env?: Env;
pushUser?: PushAPI;
}

const useChatProfile = () => {
const { pushUser } = useChatData();
const { pushUser:contextPushUser } = useChatData();
const fetchChatProfile = useCallback(
async ({
profileId,
pushUser = contextPushUser,
//note: remove env when chat and notification component is shifted to class based
env
}: FetchProfileParams): Promise<any> => {
try {
let userReadOnly;
if(profileId)

if(profileId && pushUser)
userReadOnly = await pushUser!.info({ overrideAccount: profileId });
else
userReadOnly = await pushUser!.info();
Expand Down

0 comments on commit 0d3fd91

Please sign in to comment.