Skip to content

Commit

Permalink
Search issue (#1270)
Browse files Browse the repository at this point in the history
* fix: fixed lint issues

* fix: added test for chat preview search list

* fix: fixed review comment

* Update ChatPreviewSearchList.tsx
  • Loading branch information
mishramonalisha76 authored May 21, 2024
1 parent e0f7bae commit f5070a2
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ChatPreviewSearchList } from '@pushprotocol/uiweb';
import styled from 'styled-components';

const ChatPreviewSearchListTest = () => {
const walletAddress = "0xFA3F8E79fb9B03e7a04295594785b91588Aa4DC8";
return (
<>
<Conatiner>
<ChatPreviewSearchList searchParamter={walletAddress} />
</Conatiner>
</>
);
};

export default ChatPreviewSearchListTest;

const Conatiner = styled.div`
background: '#ffeded',
border: '1px solid rgb(226,8,128)',
height: '28.5vh',
`;
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const ChatUITest = () => {
CHAT BUBBLE
</Link>
<Link to="/ChatViewList" className="nav-button">
CHAT VIEW LIST
CHAT VIEW LIST
</Link>
<Link to="/ChatView" className="nav-button">
CHAT VIEW
Expand All @@ -44,6 +44,9 @@ const ChatUITest = () => {
<Link to="/ChatPreviewList" className="nav-button">
CHAT PREVIEW LIST
</Link>
<Link to="/ChatPreviewSearchList" className="nav-button">
CHAT PREVIEW SEARCH LIST
</Link>
<Link to="/userProfile" className="nav-button">
USER PROFILE COMPONENT
</Link>
Expand Down
5 changes: 5 additions & 0 deletions packages/examples/sdk-frontend-react/src/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ import { SubscriptionManagerTest } from './widget/SubscriptionManagerTest';
import Widget from './widget/Widget';
// import { SubscriptionManagerTest } from './widget/SubscriptionManagerTest';
import { UserProfileTest } from './ChatUITest/UserProfileTest';
import ChatPreviewSearchListTest from './ChatUITest/ChatPreviewSearchList';

window.Buffer = window.Buffer || Buffer;

Expand Down Expand Up @@ -656,6 +657,10 @@ export function App() {
path="ChatPreview"
element={<ChatPreviewTest />}
/>
<Route
path="ChatPreviewSearchList"
element={<ChatPreviewSearchListTest />}
/>
<Route
path="ChatPreviewList"
element={<ChatPreviewListTest />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,10 +610,9 @@ export const ChatPreviewList: React.FC<IChatPreviewListProps> = (options: IChatP
message: 'Invalid search',
};
}

console.debug(error);
if (!error) {
const chatInfo = await fetchChat({ chatId: formattedChatId });

if (chatInfo && chatInfo?.meta?.group)
groupProfile = await getGroupByIDnew({
groupId: formattedChatId,
Expand All @@ -622,7 +621,6 @@ export const ChatPreviewList: React.FC<IChatPreviewListProps> = (options: IChatP
formattedChatId = pCAIP10ToWallet(
chatInfo?.participants.find((address) => address != walletToPCAIP10(user?.account)) || formattedChatId
);

//fetch profile
if (!groupProfile) {
userProfile = await getNewChatUser({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ export const ChatViewList: React.FC<IChatViewListProps> = (options: IChatViewLis

return () => clearTimeout(timer);
}

return () => {};
}, [chatAcceptStream, participantJoinStream]);

// Change listtype to 'UINITIALIZED' and hidden to true when participantRemoveStream or participantLeaveStream is received
Expand Down
2 changes: 1 addition & 1 deletion packages/uiweb/src/lib/dataProviders/ChatDataProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const ChatUIProvider = ({

console.debug(`UIWeb::ChatDataProvider::user changed - ${new Date().toISOString()}`, user);

if (!user.readmode()) {
if (!user?.readmode()) {
await initStream(user);
}

Expand Down
8 changes: 2 additions & 6 deletions packages/uiweb/src/lib/helpers/chat/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ export const getNewChatUser = async ({
let chatProfile: IUser | undefined;
let address: string | null = null;
address = await getAddress(searchText, env);
// const provider = new ethers.providers.InfuraProvider();
// address = await provider.resolveName(searchText);
// if (!address) {
// address = await getAddress(searchText, env);
// }
if (address) {
chatProfile = await fetchChatProfile({ profileId: address, env, user });
if (!chatProfile) chatProfile = displayDefaultUser({ caip10: walletToPCAIP10(address) });
Expand All @@ -70,7 +65,8 @@ export const getAddress = async (searchText: string, env: Env) => {
let address: string | null = null;
if (searchText.includes('.')) {
try {
address = await udResolver.owner(searchText);
if (!udResolver) throw new Error('No udResolver available for the network');
address = await udResolver?.owner(searchText);
} catch (err) {
try {
address = await provider.resolveName(searchText);
Expand Down
38 changes: 21 additions & 17 deletions packages/uiweb/src/lib/helpers/udResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@ import Resolution from '@unstoppabledomains/resolution';
import { ethers } from 'ethers';
import { allowedNetworks, InfuraAPIKey, NETWORK_DETAILS } from '../config';

export const getUdResolver = (env:Env): Resolution => {
const l1ChainId = allowedNetworks[env].includes(1) ? 1 : 5;
const l2ChainId = allowedNetworks[env].includes(137) ? 137 : 80002;
// ToDo: Enable for sepolia chainId once UD supports it
// const l1ChainId = appConfig.allowedNetworks.includes(1) ? 1 : 11155111;
return Resolution.fromEthersProvider({
uns: {
locations: {
Layer1: {
network: "mainnet", // add config for sepolia once it's supported by UD
provider: new ethers.providers.InfuraProvider(l1ChainId, InfuraAPIKey),
},
Layer2: {
network: NETWORK_DETAILS[l2ChainId].network,
provider: new ethers.providers.InfuraProvider(l2ChainId, InfuraAPIKey),
export const getUdResolver = (env: Env): Resolution => {
try {
const l1ChainId = allowedNetworks[env].includes(1) ? 1 : 5;
const l2ChainId = allowedNetworks[env].includes(137) ? 137 : 80002;
// ToDo: Enable for sepolia chainId once UD supports it
// const l1ChainId = appConfig.allowedNetworks.includes(1) ? 1 : 11155111;
return Resolution.fromEthersProvider({
uns: {
locations: {
Layer1: {
network: 'mainnet', // add config for sepolia once it's supported by UD
provider: new ethers.providers.InfuraProvider(l1ChainId, InfuraAPIKey),
},
Layer2: {
network: NETWORK_DETAILS[l2ChainId].network,
provider: new ethers.providers.InfuraProvider(l2ChainId, InfuraAPIKey),
},
},
},
},
});
});
} catch (e) {
console.debug(`Errored:UIWeb::helpers::getUdResolver::UD doesnot provide support for the network`);
}
};

0 comments on commit f5070a2

Please sign in to comment.