Skip to content

Commit

Permalink
Fixed the infinte render issue
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishek-01k committed Feb 20, 2024
1 parent fb6074b commit 191b9ab
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 21 deletions.
3 changes: 1 addition & 2 deletions src/components/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ function Dropdown({ dropdownValues, textColor, iconFilter, hoverBGColor }: Dropd
spacing="1px"
width="max-content"
>
<DesktopAddress>{dropdownValue?.title} <SpanV2 fontWeight='600' margin='0 0 0 2px'>{mode}</SpanV2></DesktopAddress>
<DesktopAddress>{dropdownValue?.title}</DesktopAddress>

<MobileAddress>
{shortenText(dropdownValue?.title,3)}
<SpanV2 fontWeight='600' margin='0 0 0 2px'>{mode}</SpanV2>
</MobileAddress>
</Span>
{dropdownValue?.invertedIcon && (
Expand Down
1 change: 0 additions & 1 deletion src/components/ProfileModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ const ProfileModal = ({ showDropdown, setShowDropdown, dropdownValues })=>{
>
<MobileAddress>
{shortenText(dropdownValue?.title,3)}
<SpanV2 fontWeight='600' margin='0 0 0 2px'>{mode}</SpanV2>
</MobileAddress>
</Span>
{dropdownValue?.invertedIcon && <Image
Expand Down
7 changes: 3 additions & 4 deletions src/hooks/useAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ export const useAccount = () => {

const account = useMemo(() => {
if(wallet && wallet.accounts.length > 0) {
setReadOnlyWallet(undefined);
setMode(undefined);
return ethers.utils.getAddress(wallet.accounts[0].address);
}else{
return readOnlyWallet;
}
return readOnlyWallet;
}, [wallet, readOnlyWallet]);

const chainId = useMemo(() => {
Expand All @@ -54,7 +53,7 @@ export const useAccount = () => {
setWalletModules,
setPrimaryWallet,
provider,
account : account ? account : readOnlyWallet,
account : account,
chainId,
isActive,
setChain,
Expand Down
6 changes: 4 additions & 2 deletions src/modules/chat/ChatModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { checkIfIntent, getUpdatedChatAndIntent, getUpdatedGroupInfo } from 'hel
import { ChatUIProvider, darkChatTheme } from '@pushprotocol/uiweb';
import { appConfig } from 'config';
import GLOBALS, { device, globalsMargin } from 'config/Globals';
import { GlobalContext } from 'contexts/GlobalContext';

export const ToastPosition: ToastOptions = {
position: 'top-right',
Expand All @@ -59,7 +60,7 @@ export const Context = React.createContext<ChatUserAppContext | null>(null);

// Create Header
function Chat({ chatid }) {
const { account, chainId, provider } = useAccount();
const { account, chainId, provider,wallet } = useAccount();
const { videoCallData } = useContext(VideoCallContext);

const {
Expand Down Expand Up @@ -93,6 +94,7 @@ function Chat({ chatid }) {
const [userShouldBeSearched, setUserShouldBeSearched] = useState<boolean>(false);
const [filteredUserData, setFilteredUserData] = useState<User[]>([]);
const [signerData, setSignerData] = useState();
const { readOnlyWallet } = React.useContext(GlobalContext);

const isMobile = useDeviceWidthCheck(600);
const queryClient = new QueryClient({});
Expand Down Expand Up @@ -393,7 +395,7 @@ function Chat({ chatid }) {
theme={theme.scheme === 'dark' && darkChatTheme}
// signer={signerData}
env={appConfig?.appEnv}
account={account}
account={wallet?.accounts?.length > 0 ? account: readOnlyWallet}
pgpPrivateKey={pgpPvtKey}
user={userPushSDKInstance}
>
Expand Down
14 changes: 5 additions & 9 deletions src/primaries/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,9 @@ const Profile = ({ isDarkMode }) => {
id: 'disconnect',
value: '',
function: async () => {
if (readOnlyWallet) {
setReadOnlyWallet('0x0000000000000000000000000000000000000000');
} else {
await disconnect(wallet);
setMode(ReadOnlyWalletMode.GUEST_MODE);
setReadOnlyWallet('0x0000000000000000000000000000000000000000');
}
await disconnect(wallet);
setMode(ReadOnlyWalletMode.GUEST_MODE);
setReadOnlyWallet('0x0000000000000000000000000000000000000000');
},
title: 'Logout',
invertedIcon: './logout.svg',
Expand All @@ -103,7 +99,7 @@ const Profile = ({ isDarkMode }) => {
{account && account != '' && !authError ? (
<Body>

{mode === ReadOnlyWalletMode.GUEST_MODE ? (
{!(wallet?.accounts?.length > 0) ? (
<Wallet
bg="linear-gradient(87.17deg, #B6A0F5 0%, #F46EF7 57.29%, #FF95D5 100%)"
color='#FFF'
Expand Down Expand Up @@ -132,7 +128,7 @@ const Profile = ({ isDarkMode }) => {
) : (
<>{shortenText(account, 5)}</>
)}
<SpanV2 fontWeight='600' margin='0 0 0 2px'>{mode ? mode : userPushSDKInstance?.readMode && ReadOnlyWalletMode.READ_ONLY_MODE}</SpanV2>
<SpanV2 fontWeight='600' margin='0 0 0 2px'>{!(wallet?.accounts?.length > 0) ? ReadOnlyWalletMode.GUEST_MODE : userPushSDKInstance?.readMode && ReadOnlyWalletMode.READ_ONLY_MODE}</SpanV2>
<ToggleArrowImg filter={isDarkMode ? theme.snackbarBorderIcon : 'brightness(0) invert(1)'}>
<img
alt="arrow"
Expand Down
2 changes: 2 additions & 0 deletions src/sections/chat/ChatSidebarSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import NewTag from 'components/NewTag';
import GLOBALS from 'config/Globals';
import { appConfig } from '../../config';
import { useAccount } from 'hooks';
import { GlobalContext } from 'contexts/GlobalContext';


const createGroupOnMouseEnter = [
Expand Down Expand Up @@ -67,6 +68,7 @@ const ChatSidebarSection = ({ showCreateGroupModal, autofilledSearch }) => {
const theme = useTheme();

const { setSelectedChatId } = useContext(Context);
const { setMode } = useContext(GlobalContext);

const isNewTagVisible = getIsNewTagVisible(new Date('2023-02-22T00:00:00.000'), 90);

Expand Down
6 changes: 3 additions & 3 deletions src/structure/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ function Header({ isDarkMode, darkModeToggle }) {
)}

<ItemH justify="flex-end" flex="initial">
{!!error && <PrimaryTheme>{getErrorMessage(error)}</PrimaryTheme>}
{/* {!!error && <PrimaryTheme>{getErrorMessage(error)}</PrimaryTheme>} */}
{/* {!isActive && !error && <ThirdTheme>Please connect to a Web3 Network</ThirdTheme>} */}
{!!error && <ThirdTheme>Please connect to a Web3 Network</ThirdTheme>}
{/* {!!error && <ThirdTheme>Please connect to a Web3 Network</ThirdTheme>} */}
{/* {isActive && !showLoginControls && !error && (
<RightBarDesktop justify="flex-end" flex="initial">
<ChainIndicator isDarkMode={isDarkMode} />
Expand All @@ -264,7 +264,7 @@ function Header({ isDarkMode, darkModeToggle }) {

<RightBarDesktop justify="flex-end" flex="initial">
{/* //TODO: The chain Indicator should be removed in guest mode */}
{mode !== ReadOnlyWalletMode.GUEST_MODE && <ChainIndicator isDarkMode={isDarkMode} />}
{wallet?.accounts?.length > 0 && <ChainIndicator isDarkMode={isDarkMode} />}
<Profile isDarkMode={isDarkMode} />
</RightBarDesktop>
</ItemH>
Expand Down

0 comments on commit 191b9ab

Please sign in to comment.