Skip to content

Commit bf581ea

Browse files
Bhupesh-mfsiAlexNi245
authored andcommitted
New storage frontend bug fixes
1 parent f3fb1c0 commit bf581ea

File tree

18 files changed

+64
-90
lines changed

18 files changed

+64
-90
lines changed

packages/messenger-widget/src/components/AddConversation/AddConversation.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export default function AddConversation() {
3434
const submit = async (e: React.FormEvent) => {
3535
e.preventDefault();
3636
setName(name.trim());
37-
console.log('name', name);
3837
if (name.length) {
3938
// start loader
4039
dispatch({

packages/messenger-widget/src/components/ConfigureProfile/ConfigureProfile.tsx

+1-4
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,7 @@ export function ConfigureDM3Profile() {
127127

128128
// handles existing ENS name
129129
useEffect(() => {
130-
if (
131-
account!.ensName &&
132-
!account!.ensName.endsWith(globalConfig.ADDR_ENS_SUBDOMAIN())
133-
) {
130+
if (account!.ensName) {
134131
fetchExistingDM3Name(mainnetProvider, account!, setExistingDm3Name);
135132
}
136133
}, [account]);

packages/messenger-widget/src/components/ConfigureProfile/bl.tsx

+14-12
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,23 @@ import { Account, ProfileKeys, hasUserProfile } from '@dm3-org/dm3-lib-profile';
22
import {
33
Actions,
44
ConnectionType,
5-
GlobalState,
65
ModalStateType,
76
} from '../../utils/enum-type-utils';
87

9-
import { createAlias, getAliasChain } from '@dm3-org/dm3-lib-delivery-api';
8+
import { createAlias } from '@dm3-org/dm3-lib-delivery-api';
109
import { globalConfig, log } from '@dm3-org/dm3-lib-shared';
1110
import { ethers } from 'ethers';
1211
import React from 'react';
1312
import {
1413
claimSubdomain,
1514
removeAlias,
1615
} from '../../adapters/offchain-resolver-api';
17-
import { getLastDm3Name } from '../../utils/common-utils';
1816
import { checkEnsDM3Text } from '../../utils/ens-utils';
19-
import { setContactHeightToMaximum } from '../Contacts/bl';
2017
import { closeLoader, startLoader } from '../Loader/Loader';
2118
import { NAME_TYPE } from './chain/common';
2219
import { ConfigureEnsProfile } from './chain/ens/ConfigureEnsProfile';
2320
import { ConfigureGenomeProfile } from './chain/genome/ConfigureGenomeProfile';
21+
import { Dm3Name } from '../../hooks/topLevelAlias/nameService/Dm3Name';
2422

2523
export const PROFILE_INPUT_FIELD_CLASS =
2624
'profile-input font-weight-400 font-size-14 border-radius-6 w-100 line-height-24';
@@ -116,7 +114,6 @@ export const submitDm3UsernameClaim = async (
116114
);
117115

118116
setDisplayName(ensName);
119-
setContactHeightToMaximum(true);
120117
} catch (e) {
121118
setError('Name is not available', NAME_TYPE.DM3_NAME);
122119
}
@@ -157,7 +154,6 @@ export const removeAliasFromDm3Name = async (
157154
},
158155
});
159156

160-
setContactHeightToMaximum(true);
161157
closeLoader();
162158
return true;
163159
} else {
@@ -185,12 +181,18 @@ export const fetchExistingDM3Name = async (
185181
) => {
186182
try {
187183
if (account) {
188-
const dm3Names: any = await getAliasChain(account, mainnetProvider);
189-
let dm3Name;
190-
if (dm3Names && dm3Names.length) {
191-
dm3Name = getLastDm3Name(dm3Names);
192-
}
193-
setExistingDm3Name(dm3Name ? dm3Name : null);
184+
const dm3NameService = new Dm3Name(mainnetProvider);
185+
const dm3Name = await dm3NameService.resolveAliasToTLD(
186+
account.ensName,
187+
);
188+
// Not a DM3 name -> 0xa966.beta-addr.dm3.eth
189+
// Its DM3 name -> bob.beta-user.dm3.eth
190+
// Checks user sub domain for setting DM3 name
191+
setExistingDm3Name(
192+
dm3Name.endsWith(globalConfig.USER_ENS_SUBDOMAIN())
193+
? dm3Name
194+
: null,
195+
);
194196
} else {
195197
setExistingDm3Name(null);
196198
}

packages/messenger-widget/src/components/ConfigureProfile/chain/ens/bl.ts

-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Account, SignedUserProfile } from '@dm3-org/dm3-lib-profile';
33
import { ethersHelper, stringify } from '@dm3-org/dm3-lib-shared';
44
import { ethers } from 'ethers';
55
import { Actions, ModalStateType } from '../../../../utils/enum-type-utils';
6-
import { setContactHeightToMaximum } from '../../../Contacts/bl';
76
import { closeLoader, startLoader } from '../../../Loader/Loader';
87
import { NAME_TYPE } from '../common';
98

@@ -92,8 +91,6 @@ export const submitEnsNameTransaction = async (
9291
const response = await ethersHelper.executeTransaction(tx);
9392
await response.wait();
9493
setEnsNameFromResolver(ensName);
95-
96-
setContactHeightToMaximum(true);
9794
} else {
9895
throw Error('Error creating publish transaction');
9996
}

packages/messenger-widget/src/components/ConfigureProfile/chain/genome/bl.ts

-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { ethersHelper, stringify } from '@dm3-org/dm3-lib-shared';
44
import { getConractInstance } from '@dm3-org/dm3-lib-shared/dist/ethersHelper';
55
import { ethers } from 'ethers';
66
import { Actions, ModalStateType } from '../../../../utils/enum-type-utils';
7-
import { setContactHeightToMaximum } from '../../../Contacts/bl';
87
import { closeLoader, startLoader } from '../../../Loader/Loader';
98

109
import { Address, namehash, toHex } from 'viem';
@@ -157,8 +156,6 @@ export const submitGenomeNameTransaction = async (
157156
const response = await ethersHelper.executeTransaction(tx);
158157
await response.wait();
159158
setEnsNameFromResolver(ensName);
160-
161-
setContactHeightToMaximum(true);
162159
} else {
163160
throw Error('Error creating publish transaction');
164161
}

packages/messenger-widget/src/components/Contacts/Contacts.tsx

+6-25
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { globalConfig } from '@dm3-org/dm3-lib-shared';
21
import { useContext, useEffect, useState } from 'react';
32
import loader from '../../assets/images/loader.svg';
43
import threeDotsIcon from '../../assets/images/three-dots.svg';
5-
import { AuthContext } from '../../context/AuthContext';
64
import { ConversationContext } from '../../context/ConversationContext';
75
import { MessageContext } from '../../context/MessageContext';
86
import { DashboardProps } from '../../interfaces/props';
@@ -13,13 +11,12 @@ import {
1311
} from '../../utils/enum-type-utils';
1412
import { ContactMenu } from '../ContactMenu/ContactMenu';
1513
import './Contacts.css';
16-
import { setContactHeightToMaximum, showMenuInBottom } from './bl';
14+
import { showMenuInBottom } from './bl';
1715
import { getAccountDisplayName } from '@dm3-org/dm3-lib-profile';
1816

1917
export function Contacts(props: DashboardProps) {
2018
// fetches context api data
2119
const { state, dispatch } = useContext(GlobalContext);
22-
const { account } = useContext(AuthContext);
2320
const {
2421
contacts,
2522
setSelectedContactName,
@@ -33,22 +30,11 @@ export function Contacts(props: DashboardProps) {
3330
boolean | null
3431
>(null);
3532

36-
// fetches sub domain of ENS
37-
const isAddrEnsName = account?.ensName?.endsWith(
38-
globalConfig.ADDR_ENS_SUBDOMAIN(),
39-
);
40-
41-
// handles contact box view
42-
//Can be removed once responsive design has been implemented @Bhupesh
43-
useEffect(() => {
44-
setContactHeightToMaximum(!isAddrEnsName ? true : false);
45-
}, [account?.ensName]);
46-
4733
// handles active contact removal
4834
// move to a better place (profile window) and Contact Info
4935
useEffect(() => {
5036
if (
51-
selectedContact !== null &&
37+
selectedContact &&
5238
state.uiView.selectedRightView !== RightViewSelected.Chat &&
5339
state.uiView.selectedRightView !== RightViewSelected.ContactInfo
5440
) {
@@ -58,7 +44,7 @@ export function Contacts(props: DashboardProps) {
5844

5945
// handles UI view on contact select
6046
useEffect(() => {
61-
if (selectedContact !== undefined) {
47+
if (selectedContact) {
6248
// set selected contact
6349

6450
if (state.uiView.selectedRightView !== RightViewSelected.Chat) {
@@ -92,7 +78,7 @@ export function Contacts(props: DashboardProps) {
9278
//If a selected contact is selected and the menu is open, we want to align the menu at the bottom
9379
if (scroller) {
9480
scroller.addEventListener('scroll', () => {
95-
if (selectedContact != null) {
81+
if (selectedContact) {
9682
setIsMenuAlignedAtBottom(
9783
showMenuInBottom(selectedContact.name),
9884
);
@@ -136,10 +122,6 @@ export function Contacts(props: DashboardProps) {
136122
: '',
137123
)}
138124
onClick={() => {
139-
console.log(
140-
'set selected contact ',
141-
data.contactDetails.account.ensName,
142-
);
143125
setSelectedContactName(
144126
data.contactDetails.account.ensName,
145127
);
@@ -179,7 +161,6 @@ export function Contacts(props: DashboardProps) {
179161
</p>
180162
</div>
181163

182-
{/* @Bhupesh what is this cached contacts section for */}
183164
{id !==
184165
selectedContact?.contactDetails
185166
.account.ensName &&
@@ -260,7 +241,7 @@ export function Contacts(props: DashboardProps) {
260241
<div
261242
key={data}
262243
className={
263-
selectedContact !== null
244+
selectedContact
264245
? 'highlight-right-border'
265246
: 'highlight-right-border-none'
266247
}
@@ -274,7 +255,7 @@ export function Contacts(props: DashboardProps) {
274255
<div
275256
key={data}
276257
className={
277-
selectedContact !== null
258+
selectedContact
278259
? 'highlight-right-border'
279260
: 'highlight-right-border-none'
280261
}

packages/messenger-widget/src/components/Contacts/bl.ts

-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
// sets height of the left view according to content
2-
export const setContactHeightToMaximum = (isProfileConfigured: boolean) => {
3-
const element = document.getElementsByClassName(
4-
'contacts-scroller',
5-
)[0] as HTMLElement;
6-
element.style.height = isProfileConfigured ? '88.5vh' : '88.5vh';
7-
};
8-
91
export const showMenuInBottom = (id: string | null): boolean => {
102
const scroller: HTMLElement = document.getElementById(
113
'chat-scroller',

packages/messenger-widget/src/components/Loader/Loader.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ import loader from '../../assets/images/loader.svg';
55
import { GlobalContext } from '../../utils/context-utils';
66

77
export const closeLoader = () => {
8-
console.log('stop loader');
98
const loader = document.getElementsByClassName('loading')[0] as HTMLElement;
109
loader.setAttribute('style', 'display:none !important');
1110
};
1211

1312
export const startLoader = () => {
14-
console.log('start loader');
1513
const loader = document.getElementsByClassName('loading')[0] as HTMLElement;
1614
loader.setAttribute('style', 'display:flex !important');
1715
};

packages/messenger-widget/src/components/Message/Message.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ export function Message(props: MessageProps) {
9393
: state.uiView.selectedMessageView
9494
.actionType === MessageActionType.EDIT &&
9595
state.uiView.selectedMessageView.messageData
96-
?.envelop.id === props.envelop.id
96+
?.envelop.message.signature ===
97+
props.envelop.message.signature
9798
? 'msg-editing-active'
9899
: 'ms-3 own-msg-background'
99100
: !props.message &&

packages/messenger-widget/src/components/MessageAction/MessageAction.tsx

+9-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ export function MessageAction(props: MessageProps) {
4848
};
4949

5050
const setAction = (action: MessageActionType) => {
51-
console.log('setAction', action);
5251
dispatch({
5352
type: UiViewStateType.SetMessageView,
5453
payload: {
@@ -64,10 +63,15 @@ export function MessageAction(props: MessageProps) {
6463
throw Error('no contact selected');
6564
}
6665

67-
// @Bhupesh why do we need to filter here
68-
// const filteredElemtns = props.reactions.some(
69-
// (data) => data.message.message === message,
70-
// );
66+
// Filters if the reaction already exists
67+
const filteredReactions = props.reactions.filter(
68+
(data) => data.message.message === message,
69+
);
70+
71+
// if same reaction already exists, then it should not be added again so returns
72+
if (filteredReactions.length) {
73+
return;
74+
}
7175

7276
dispatch({
7377
type: UiViewStateType.SetMessageView,

packages/messenger-widget/src/components/SendMessage/onSubmitMessage.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export const onSubmitMessage = async (
3737
referenceMessageHash!,
3838
props.filesSelected.map((file) => file.data),
3939
);
40-
await addMessage(
40+
41+
addMessage(
4142
selectedContact?.contactDetails.account.ensName!,
4243
messageData,
4344
);
@@ -48,6 +49,16 @@ export const onSubmitMessage = async (
4849
type: ModalStateType.LastMessageAction,
4950
payload: MessageActionType.REPLY,
5051
});
52+
53+
// Removes preview of reply to message in the UI
54+
dispatch({
55+
type: UiViewStateType.SetMessageView,
56+
payload: {
57+
actionType: MessageActionType.NONE,
58+
messageData: undefined,
59+
},
60+
});
61+
5162
return;
5263
}
5364
if (state.uiView.selectedMessageView.actionType === 'EDIT') {

packages/messenger-widget/src/hooks/conversation/hydrateContact.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable no-console */
22
import {
33
Account,
4-
getAccountDisplayName,
54
getDeliveryServiceProfile,
65
getUserProfile,
76
normalizeEnsName,

packages/messenger-widget/src/hooks/conversation/useConversation.tsx

-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export const useConversation = (config: Config) => {
3333
const conversationCount = useMemo(() => contacts.length, [contacts]);
3434

3535
const selectedContact = useMemo(() => {
36-
console.log('selectedContactName MEMO', selectedContactName);
3736
return contacts.find(
3837
(contact) =>
3938
contact.contactDetails.account.ensName === selectedContactName,
@@ -67,8 +66,6 @@ export const useConversation = (config: Config) => {
6766
}
6867
const currentConversationsPage = await getConversations(page);
6968

70-
console.log('currentConversationsPage', currentConversationsPage);
71-
7269
//Hydrate the contacts by fetching their profile and DS profile
7370
const storedContacts = await Promise.all(
7471
currentConversationsPage.map((conversation) => {
@@ -180,7 +177,6 @@ export const useConversation = (config: Config) => {
180177
conversation,
181178
resolveAliasToTLD,
182179
);
183-
console.log('hydrated contact', hydratedContact);
184180
setContacts((prev) => {
185181
return prev.map((existingContact) => {
186182
//Find the contact in the list and replace it with the hydrated one
@@ -227,7 +223,6 @@ export const useConversation = (config: Config) => {
227223
...contact,
228224
isHidden: false,
229225
};
230-
console.log('unhiddenContact', unhiddenContact);
231226
setSelectedContactName(unhiddenContact.contactDetails.account.ensName);
232227
hydrateExistingContactAsync(unhiddenContact);
233228
};

packages/messenger-widget/src/hooks/messages/renderer/messageTypes/renderDelete.ts

+19-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const renderDelete = (messages: MessageModel[]) => {
1313
(deleteMessage) =>
1414
deleteMessage.envelop.message.metadata.referenceMessageHash,
1515
);
16+
1617
//We return the messages with out messages that are to be deleted and the delete requests
1718
return messages
1819
.filter(
@@ -35,12 +36,28 @@ export const renderDelete = (messages: MessageModel[]) => {
3536
message: '',
3637
metadata: {
3738
...message.envelop.message.metadata,
38-
type: MessageActionType.DELETE as MessageType,
39+
// REACT messages are set, so that it can be filtered out
40+
// to be not shown on UI
41+
type:
42+
message.envelop.message.metadata.type ===
43+
MessageActionType.REACT
44+
? (MessageActionType.REACT as MessageType)
45+
: (MessageActionType.DELETE as MessageType),
3946
},
4047
},
4148
},
4249
};
4350
}
4451
return message;
45-
});
52+
// filter out all the reaction messages those are deleted
53+
// its not to be shown on UI
54+
})
55+
.filter(
56+
(messageData) =>
57+
!(
58+
messageData.envelop.message.message === '' &&
59+
messageData.envelop.message.metadata.type ===
60+
MessageActionType.REACT
61+
),
62+
);
4663
};

0 commit comments

Comments
 (0)