Skip to content

Commit

Permalink
Invalid profile contact issue fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhupesh-mfsi authored and hai-ko committed Dec 1, 2023
1 parent db0bf3b commit 1a70261
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,10 @@ export function Contacts(props: DashboardProps) {
) {
const defaultContactIndex = contacts.findIndex(
(contact) =>
contact.contactDetails &&
contact.contactDetails.account &&
contact.contactDetails.account.ensName ===
props.dm3Props.config.defaultContact,
props.dm3Props.config.defaultContact,
);
if (defaultContactIndex > -1) {
setContactSelected(defaultContactIndex);
Expand Down Expand Up @@ -302,7 +304,10 @@ export function Contacts(props: DashboardProps) {
<div
className="pb-1"
title={
data.contactDetails.account.ensName
data.contactDetails
? data.contactDetails.account
.ensName
: ''
}
>
<p className="display-name">
Expand Down
27 changes: 23 additions & 4 deletions packages/messenger-widget/src/components/Contacts/bl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,14 @@ export const fetchAndSetContacts = async (
}

const profileAccounts = actualContactList.filter(
(item) => item.contactDetails.account.profileSignature,
(item) =>
item.contactDetails && item.contactDetails.account.profileSignature,
);

const nonProfileAccounts = actualContactList.filter(
(item) => !item.contactDetails.account.profileSignature,
(item) =>
item.contactDetails &&
!item.contactDetails.account.profileSignature,
);

const uniqueProfileAccounts = [
Expand Down Expand Up @@ -162,9 +165,11 @@ export const setContactIndexSelectedFromCache = (
const index = cacheContacts.findIndex(
(data) =>
(key &&
data.contactDetails &&
data.contactDetails.account.profile?.publicEncryptionKey ===
key) ||
name === data.contactDetails.account.ensName,
(data.contactDetails &&
name === data.contactDetails.account.ensName),
);

// close the loader
Expand All @@ -185,8 +190,9 @@ export const addNewConversationFound = async (
state.accounts.contacts.forEach((contact) => {
const data = existingList.filter(
(cacheContact) =>
cacheContact.contactDetails &&
cacheContact.contactDetails.account.ensName ===
contact.account.ensName,
contact.account.ensName,
);
if (!data || !data.length) {
contactList.push(contact);
Expand Down Expand Up @@ -434,6 +440,7 @@ export const updateContactOnAccountChange = async (
}
} else {
let contactToAdd;

if (profile?.profile) {
const deliveryServiceProfile =
await getDeliveryServiceProfile(
Expand Down Expand Up @@ -465,6 +472,18 @@ export const updateContactOnAccountChange = async (
contactToAdd = itemList[0];
}

if (!contactToAdd) {
contactToAdd = {
account: {
ensName: state.modal.addConversation
.ensName as string,
profile: undefined,
profileSignature: undefined,
},
deliveryServiceProfile: undefined,
};
}

// update the contact details
item.contactDetails = contactToAdd;

Expand Down

0 comments on commit 1a70261

Please sign in to comment.