Skip to content

Commit

Permalink
some fixes for update profile
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhupesh-mfsi committed Aug 30, 2024
1 parent f46e2df commit b265b70
Show file tree
Hide file tree
Showing 4 changed files with 236 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ export function MobileView() {
const { dm3Configuration } = useContext(DM3ConfigurationContext);

const {
updateProfileForAddressOrDm3Name,
updateProfileWithTransaction,
isProfileUpdatedForAddrName,
isProfileUpdatedForDm3Name,
isProfileUpdatedForEnsName,
} = useContext(DM3UserProfileContext);

const ensDomainName =
(existingDm3Name &&
(existingEnsName &&
(existingEnsName?.endsWith('.gno') ||
existingEnsName?.endsWith('.gnosis.eth')
? 'GNO'
Expand Down Expand Up @@ -88,8 +90,10 @@ export function MobileView() {
{/* Wallet address */}
<div className="d-flex">
<p
className="m-0
font-size-14 font-weight-500 line-height-24 title-content"
className={'m-0 font-size-14 font-weight-500 line-height-24 title-content'.concat(
' ',
!isProfileUpdatedForAddrName() ? 'error-text' : '',
)}
>
Wallet Address
<span className="address-tooltip">
Expand All @@ -110,12 +114,29 @@ export function MobileView() {
</p>
</div>
<p
className="dm3-address m-0
font-size-14 font-weight-500 line-height-24 grey-text"
className={'dm3-address m-0 font-size-14 font-weight-500 line-height-24'.concat(
' ',
!isProfileUpdatedForAddrName()
? 'error-text'
: 'grey-text',
)}
>
{ethAddress &&
ethAddress + dm3Configuration.addressEnsSubdomain}
</p>
{!isProfileUpdatedForAddrName() && (
<button
className="add-prof-btn-active update-btn"
onClick={() => updateProfileForAddressOrDm3Name('ADDR')}
>
<img
className="me-1 pointer-cursor "
src={updateIcon}
alt="update profile"
/>
update now
</button>
)}
</div>

{/* Existing DM3 name */}
Expand Down Expand Up @@ -165,9 +186,17 @@ export function MobileView() {
{!isProfileUpdatedForDm3Name() && (
<button
className="add-prof-btn-active update-btn"
onClick={() =>
updateProfileWithTransaction(existingDm3Name)
}
onClick={() => {
if (existingDm3Name.endsWith('.op.dm3.eth')) {
updateProfileWithTransaction(
existingEnsName
? existingEnsName
: existingDm3Name,
);
} else {
updateProfileForAddressOrDm3Name('DM3');
}
}}
>
<img
className="me-1 pointer-cursor "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ export function NormalView() {
const { dm3Configuration } = useContext(DM3ConfigurationContext);

const {
updateProfileForAddressOrDm3Name,
updateProfileWithTransaction,
isProfileUpdatedForAddrName,
isProfileUpdatedForDm3Name,
isProfileUpdatedForEnsName,
} = useContext(DM3UserProfileContext);

const ensDomainName =
(existingDm3Name &&
(existingEnsName &&
(existingEnsName?.endsWith('.gno') ||
existingEnsName?.endsWith('.gnosis.eth')
? 'GNO'
Expand Down Expand Up @@ -89,8 +91,12 @@ export function NormalView() {
{/* Wallet Address */}
<div className="d-flex">
<p
className="m-0
font-size-14 font-weight-500 line-height-24 title-content"
className={'m-0 font-size-14 font-weight-500 line-height-24 title-content'.concat(
' ',
!isProfileUpdatedForAddrName()
? 'error-text'
: '',
)}
>
Wallet Address
<span className="address-tooltip">
Expand All @@ -111,13 +117,32 @@ export function NormalView() {
</span>
</p>
<p
className="dm3-address m-0 ms-5
font-size-14 font-weight-500 line-height-24 grey-text"
className={'dm3-address m-0 ms-5 font-size-14 font-weight-500 line-height-24'.concat(
' ',
!isProfileUpdatedForAddrName()
? 'error-text'
: 'grey-text',
)}
>
{ethAddress &&
ethAddress +
dm3Configuration.addressEnsSubdomain}
</p>
{!isProfileUpdatedForAddrName() && (
<button
className="add-prof-btn-active update-btn"
onClick={() =>
updateProfileForAddressOrDm3Name('ADDR')
}
>
<img
className="me-1 pointer-cursor "
src={updateIcon}
alt="update profile"
/>
update now
</button>
)}
</div>

{/* Existing DM3 name */}
Expand Down Expand Up @@ -168,13 +193,23 @@ export function NormalView() {
{!isProfileUpdatedForDm3Name() && (
<button
className="add-prof-btn-active update-btn"
onClick={() =>
updateProfileWithTransaction(
existingEnsName
? existingEnsName
: existingDm3Name,
)
}
onClick={() => {
if (
existingDm3Name.endsWith(
'.op.dm3.eth',
)
) {
updateProfileWithTransaction(
existingEnsName
? existingEnsName
: existingDm3Name,
);
} else {
updateProfileForAddressOrDm3Name(
'DM3',
);
}
}}
>
<img
className="me-1 pointer-cursor "
Expand Down
14 changes: 8 additions & 6 deletions packages/messenger-widget/src/context/DM3UserProfileContext.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';
import {
INameProfile,
INodeDetails,
useDm3UserProfile,
} from '../hooks/userProfile/useDm3UserProfile';

export type DM3UserProfileContextType = {
initialize: () => void;
updateProfileForAddressOrDm3Name: (nameType: string) => void;
updateProfileWithTransaction: (existingName: string) => void;
addNode: () => void;
deleteNode: (id: number) => void;
Expand All @@ -18,23 +18,20 @@ export type DM3UserProfileContextType = {
nodeName: string;
handleNodeNameChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
isProfileUpdated: () => boolean;
isProfileUpdatedForAddrName: () => boolean;
isProfileUpdatedForDm3Name: () => boolean;
isProfileUpdatedForEnsName: () => boolean;
};

export const DM3UserProfileContext =
React.createContext<DM3UserProfileContextType>({
initialize: () => {},
updateProfileForAddressOrDm3Name: (nameType: string) => {},
updateProfileWithTransaction: (existingName: string) => {},
addNode: () => {},
deleteNode: (id: number) => {},
nodes: {
dsNames: [''],
profile: {
publicSigningKey: '',
publicEncryptionKey: '',
deliveryServices: [''],
},
},
isModalOpenToAddNode: false,
setIsModalOpenToAddNode: (action: boolean) => {},
Expand All @@ -43,6 +40,7 @@ export const DM3UserProfileContext =
nodeName: '',
handleNodeNameChange: (e: React.ChangeEvent<HTMLInputElement>) => {},
isProfileUpdated: () => true,
isProfileUpdatedForAddrName: () => true,
isProfileUpdatedForDm3Name: () => true,
isProfileUpdatedForEnsName: () => true,
});
Expand All @@ -55,6 +53,7 @@ export const DM3UserProfileContextProvider = ({
const {
initialize,
addNode,
updateProfileForAddressOrDm3Name,
updateProfileWithTransaction,
deleteNode,
nodes,
Expand All @@ -65,6 +64,7 @@ export const DM3UserProfileContextProvider = ({
nodeName,
handleNodeNameChange,
isProfileUpdated,
isProfileUpdatedForAddrName,
isProfileUpdatedForDm3Name,
isProfileUpdatedForEnsName,
} = useDm3UserProfile();
Expand All @@ -74,6 +74,7 @@ export const DM3UserProfileContextProvider = ({
value={{
initialize,
addNode,
updateProfileForAddressOrDm3Name,
updateProfileWithTransaction,
deleteNode,
nodes,
Expand All @@ -84,6 +85,7 @@ export const DM3UserProfileContextProvider = ({
nodeName,
handleNodeNameChange,
isProfileUpdated,
isProfileUpdatedForAddrName,
isProfileUpdatedForDm3Name,
isProfileUpdatedForEnsName,
}}
Expand Down
Loading

0 comments on commit b265b70

Please sign in to comment.