Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/use hooks #452

Merged
merged 71 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
40ea4fb
feat: add hooks packages
devceline Feb 28, 2024
003159c
chore: remove references to uiHooks
devceline Feb 28, 2024
1c572a9
chore: uiEnabled from context
devceline Feb 28, 2024
d387ea2
chore: remove intermediate hooks
devceline Feb 28, 2024
3e2c849
chore: remove messages components
devceline Feb 28, 2024
f3f4a23
chore: simplify signatureModal
devceline Feb 28, 2024
fece111
chore: fix build errors
devceline Feb 28, 2024
be84309
document: what is missing in hooks
devceline Feb 28, 2024
ef5a382
chore: update useNotification logic
devceline Feb 29, 2024
e8c8363
chore: fix mobile footer
devceline Feb 29, 2024
ef65a0c
chore: fix sidebar
devceline Feb 29, 2024
5c4e6a2
chore: fix modals
devceline Feb 29, 2024
9e771ef
chore: remove widget pages
devceline Feb 29, 2024
c64433f
chore: fix more build errors
devceline Feb 29, 2024
e4d3c69
chore: remove extra logic in routes
devceline Feb 29, 2024
137240a
chore: fix all build errors
devceline Feb 29, 2024
768238f
chore: remove empty space
devceline Feb 29, 2024
1052df7
chore: use symlinking
devceline Feb 29, 2024
6fde2a7
chore: remove unused listeners
devceline Feb 29, 2024
ed9c367
chore: run prettier
devceline Feb 29, 2024
b48c6e2
chore: remove rxjs
devceline Feb 29, 2024
6014603
chore: init Web3Inbox Client
devceline Feb 29, 2024
4522eea
fix: state to use valtio
devceline Mar 1, 2024
39acfa0
feat: fetch correct subscriptions and show loading states for notifs
devceline Mar 1, 2024
46b4731
chore: remove dappOrigin hooks
devceline Mar 1, 2024
7c9d11b
chore: remove auth provider
devceline Mar 4, 2024
f22198e
chore: fix address formatting
devceline Mar 4, 2024
83aa3ce
chore: remove w3iProxy
devceline Mar 4, 2024
1e97282
chore: fix prop errors
devceline Mar 4, 2024
4dcc931
chore: fix bug where appcard navigates to topic
devceline Mar 4, 2024
2293747
chore: log useNotificationInfiniteScroll
devceline Mar 5, 2024
407d6e0
chore: update packages and prep for echo registration
devceline Mar 6, 2024
86654c7
chore: remove unnecessary comment
devceline Mar 6, 2024
5c28b8a
chore: remove notify-client
devceline Mar 6, 2024
3921509
chore: remove ContactsModal
devceline Mar 6, 2024
71e54d3
chore: simplify function to enable notifications
devceline Mar 6, 2024
2f04162
chore: move activeSubscriptions out of w3iContext
devceline Mar 6, 2024
1918024
chore: remove console logs from login page
devceline Mar 6, 2024
ee7d1a4
chore: run prettier
devceline Mar 6, 2024
9249a02
chore: fix loading indicator
devceline Mar 6, 2024
5c7596b
feat: sync symkeys for subscriptions for PNs
devceline Mar 6, 2024
5d20d15
chore: dont overwrite notifications with loading
devceline Mar 6, 2024
88f83af
chore: change and op to ternary for rendering
devceline Mar 7, 2024
e9b7448
chore: rename app to subscription
devceline Mar 7, 2024
5380f0f
fix: authentication bugs
devceline Mar 7, 2024
1a6fbe6
chore: run prettier
devceline Mar 7, 2024
c5b02cd
chore: use navigate const
devceline Mar 7, 2024
5ba7a55
chore: run prettier
devceline Mar 7, 2024
28426fb
chore: update react canary
devceline Mar 7, 2024
a54e24d
chore: use navigation for src routes
devceline Mar 7, 2024
ff3533b
chore: remove logs
devceline Mar 7, 2024
6568cfd
chore: run prettier
devceline Mar 7, 2024
d4d6ed8
Update src/utils/hooks/useNotificationsInfiniteScroll.tsx
devceline Mar 7, 2024
4493733
Update src/utils/notifications.ts
devceline Mar 7, 2024
7a53085
Update src/utils/signature.ts
devceline Mar 7, 2024
88febb9
chore: remove sentry replay
devceline Mar 7, 2024
f41f973
chore: remove unused imports
devceline Mar 7, 2024
020855d
chore: revert notification batch size change
devceline Mar 7, 2024
8a011d9
chore: update web3modal
devceline Mar 7, 2024
4a790a3
chore: update canaries of web3inbox
devceline Mar 8, 2024
857e38b
chore: prevent default on show more click
devceline Mar 8, 2024
09d2905
chore: update event type to make ts happy
devceline Mar 8, 2024
32cafe7
chore: maintain token dev state
devceline Mar 8, 2024
5b94393
chore: register on web load
devceline Mar 8, 2024
ea2cdee
chore: put logs
devceline Mar 8, 2024
8d9e527
chore: run prettier
devceline Mar 8, 2024
0bb417f
chore: remove unused reference
devceline Mar 11, 2024
9bc9878
chore: remove unused import
devceline Mar 11, 2024
1f002cf
fix: preferences modal not updated
devceline Mar 11, 2024
9eb0322
fix: fix bug with not loading on iOS
devceline Mar 11, 2024
b770fef
chore: simplify app filtering and fix empty appSelector bug
devceline Mar 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions missing_in_hooks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Bugs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this kind of todos? Should we list them somewhere else or version in this markdown?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this is just for reviewers (you, ben) to see what needed to change in the hooks, will be deleted before merge

- ~~useSubscribe should update on domain param change~~
# Things missing in hooks

## `useSubscribe`
1. ~~useSubscribe -> subscribe should accept domain. useSubscribe should only take account~~

## `useSubscription`
1. ~~useSubscribtion should expose getSubscription which takes params.~~

## `registerWithEcho`
1. ~~Add hook to register with echo~~

# Things that would be nice

## `useSubscription`
1. `useSubscribtion` should expose `isSubscribed` for convenience.

## Fetch projects from cloud
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
"@tanstack/react-query": "^5.20.1",
"@walletconnect/core": "2.11.0",
devceline marked this conversation as resolved.
Show resolved Hide resolved
"@walletconnect/identity-keys": "^2.0.1",
"@walletconnect/notify-client": "^1.1.0",
"@walletconnect/notify-message-decrypter": "^0.1.0",
"@web3inbox/core": "^1.2.0-5bd35d2",
"@web3inbox/react": "^1.2.0-5fd9098",
"@web3modal/wagmi": "4.0.10",
"classnames": "^2.3.2",
"date-fns": "^2.29.3",
Expand All @@ -40,7 +41,6 @@
"react-qr-reader-es6": "^2.2.1-2",
"react-router-dom": "^6.4.4",
"react-select": "^5.7.0",
"rxjs": "^7.6.0",
"viem": "2.7.8",
"vite-plugin-pwa": "^0.16.7",
"wagmi": "^2.5.7"
Expand Down
2 changes: 1 addition & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default defineConfig({
{
name: 'firefox',
use: { ...devices['Desktop Firefox'] }
},
}
],

/* Run your local dev server before starting the tests */
Expand Down
6 changes: 2 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { Fragment, useContext } from 'react'
import { Fragment } from 'react'

import { AnimatePresence, LazyMotion, domAnimation, m } from 'framer-motion'
import { Outlet, useLocation } from 'react-router-dom'

import MobileFooter from '@/components/layout/MobileFooter'
import Sidebar from '@/components/layout/Sidebar'
import AuthProtectedPage from '@/components/utils/AuthProtectedPage'
import W3iContext from '@/contexts/W3iContext/context'
import { useMobileResponsiveGrid } from '@/utils/hooks'

import './App.scss'

const App = () => {
const { uiEnabled } = useContext(W3iContext)
const location = useLocation()

const ref = useMobileResponsiveGrid()
Expand All @@ -22,7 +20,7 @@ const App = () => {
<LazyMotion features={domAnimation}>
<m.div ref={ref} data-path={location.pathname} className="App">
<Fragment>
{uiEnabled.sidebar ? <Sidebar isLoggedIn={true} /> : null}
<Sidebar isLoggedIn={true} />
<Outlet />
<AnimatePresence mode="wait"></AnimatePresence>
</Fragment>
Expand Down
33 changes: 6 additions & 27 deletions src/Modals.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useContext, useEffect } from 'react'

import { useWeb3Modal, useWeb3ModalState } from '@web3modal/wagmi/react'
import { AnimatePresence } from 'framer-motion'

import { PreferencesModal } from '@/components/notifications/NotificationsLayout/PreferencesModal'
Expand All @@ -18,7 +17,7 @@ import {
notificationsAvailableInBrowser
} from '@/utils/notifications'
import { isAppleMobile, isMobileButNotInstalledOnHomeScreen, isNonSafari } from '@/utils/pwa'
import { notificationPwaModalService, signatureModalService } from '@/utils/store'
import { notificationPwaModalService } from '@/utils/store'
import { isMobile } from '@/utils/ui'

export const Modals = () => {
Expand All @@ -28,10 +27,8 @@ export const Modals = () => {
isSignatureModalOpen,
isNotificationPwaModalOpen
} = useModals()
const { close: closeWeb3Modal } = useWeb3Modal()
const { open: isWeb3ModalOpen } = useWeb3ModalState()

const { notifyRegisterMessage, notifyRegisteredKey, userPubkey } = useContext(W3iContext)
const { notifyRegisteredKey, userPubkey, clientReady } = useContext(W3iContext)

const notificationsEnabled = useNotificationPermissionState()

Expand All @@ -40,7 +37,9 @@ export const Modals = () => {
const explicitlyDeniedOnDesktop = !isMobile() && window.Notification?.permission === 'denied'
const shouldShowChangeBrowserModal = isAppleMobile ? isNonSafari : false
const shouldShowPWAModal = isMobileButNotInstalledOnHomeScreen && !shouldShowChangeBrowserModal
const shouldShowSignatureModal = isSignatureModalOpen && !shouldShowChangeBrowserModal
const shouldShowSignatureModal =
(isSignatureModalOpen || (userPubkey && clientReady && !notifyRegisteredKey)) &&
!shouldShowChangeBrowserModal
const shouldShowUnsubscribeModalOpen = isUnsubscribeModalOpen && !shouldShowChangeBrowserModal
const shouldShowPreferencesModalOpen = isPreferencesModalOpen && !shouldShowChangeBrowserModal

Expand All @@ -54,26 +53,6 @@ export const Modals = () => {
!notificationModalClosed &&
!shouldShowChangeBrowserModal

useEffect(() => {
devceline marked this conversation as resolved.
Show resolved Hide resolved
const notifySignatureRequired = Boolean(notifyRegisterMessage) && !notifyRegisteredKey
if (userPubkey && notifySignatureRequired) {
if (isWeb3ModalOpen) {
// Close web3modal in case user is switching accounts
// closeWeb3Modal()
}
signatureModalService.openModal()
} else {
signatureModalService.closeModal()
}
}, [
userPubkey,
closeWeb3Modal,
notifyRegisteredKey,
notifyRegisterMessage,
isWeb3ModalOpen,
signatureModalService
])

useEffect(() => {
// Create an artificial delay to prevent modals being spammed one after the other
if (shouldShowNotificationModal) {
Expand All @@ -91,7 +70,7 @@ export const Modals = () => {

{shouldShowPreferencesModalOpen && <PreferencesModal />}

{shouldShowSignatureModal && <SignatureModal message={notifyRegisterMessage ?? ''} />}
{shouldShowSignatureModal && <SignatureModal />}

{shouldShowPWAModal && <PwaModal />}

Expand Down
44 changes: 23 additions & 21 deletions src/components/dev/DevTimeStamp/index.tsx
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
import { useContext, useEffect, useState } from 'react';
import { useContext, useEffect, useState } from 'react'

import SettingsContext from '@/contexts/SettingsContext/context'

import './DevTimeStamp.scss'
import SettingsContext from '@/contexts/SettingsContext/context';

const getTimeStampFormatted = (rawTimestamp: number) => {

const timestamp = new Date(rawTimestamp)

const year = timestamp.getFullYear();
const year = timestamp.getFullYear()

// Months are zero-indexed
const month = (timestamp.getMonth() + 1).toString().padStart(2, '0');
const day = timestamp.getDate().toString().padStart(2, '0');
const hours = timestamp.getHours().toString().padStart(2, '0');
const minutes = timestamp.getMinutes().toString().padStart(2, '0');
const seconds = timestamp.getSeconds().toString().padStart(2, '0');

const timeZone = new Intl.DateTimeFormat('en', { timeZoneName: 'short' }).formatToParts(timestamp).find(part => part.type === 'timeZoneName')!.value;
const month = (timestamp.getMonth() + 1).toString().padStart(2, '0')
const day = timestamp.getDate().toString().padStart(2, '0')
const hours = timestamp.getHours().toString().padStart(2, '0')
const minutes = timestamp.getMinutes().toString().padStart(2, '0')
const seconds = timestamp.getSeconds().toString().padStart(2, '0')

const formattedDateTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds} ${timeZone}`;
const timeZone = new Intl.DateTimeFormat('en', { timeZoneName: 'short' })
.formatToParts(timestamp)
.find(part => part.type === 'timeZoneName')!.value

return formattedDateTime
const formattedDateTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds} ${timeZone}`

return formattedDateTime
}

const DevTimeStamp = () => {
const [timestamp, setTimestamp] = useState(Date.now())
const {isDevModeEnabled} = useContext(SettingsContext)
const { isDevModeEnabled } = useContext(SettingsContext)

useEffect(() => {
if(isDevModeEnabled) {
const intervalId = setInterval(() => {
setTimestamp(Date.now())
}, 250)
if (isDevModeEnabled) {
const intervalId = setInterval(() => {
setTimestamp(Date.now())
}, 250)

return () => clearInterval(intervalId)
return () => clearInterval(intervalId)
}
}, [setTimestamp, isDevModeEnabled])

if (!isDevModeEnabled) {
return null;
return null
}

return (
Expand All @@ -48,4 +50,4 @@ const DevTimeStamp = () => {
)
}

export default DevTimeStamp;
export default DevTimeStamp
6 changes: 3 additions & 3 deletions src/components/general/Icon/CrossIcon2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const CrossIcon2: React.FC = () => {
<path
d="M4 4L12 12M4 12L12 4"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
)
Expand Down
29 changes: 6 additions & 23 deletions src/components/layout/MobileFooter/index.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,20 @@
import React, { useContext, useMemo } from 'react'
import React, { useMemo, useState } from 'react'

import { Link, useLocation } from 'react-router-dom'

import NewAppIcon from '@/components/general/Icon/NewAppIcon'
import NotificationIcon from '@/components/general/Icon/NotificationIcon'
import SettingIcon from '@/components/general/Icon/SettingIcon'
import W3iContext from '@/contexts/W3iContext/context'

import './MobileFooter.scss'

const MobileFooter: React.FC = () => {
const { pathname } = useLocation()
const { uiEnabled } = useContext(W3iContext)
const navItems = useMemo(() => {
const items: [React.ReactNode, string][] = []

if (uiEnabled.notify) {
items.push([
<NotificationIcon isFilled={pathname.endsWith('/notifications')} />,
'notifications'
])
}

if (uiEnabled.notify) {
items.push([<NewAppIcon isFilled={pathname.includes('/new-app')} />, 'notifications/new-app'])
}

if (uiEnabled.settings) {
items.push([<SettingIcon isFilled={pathname.includes('/settings')} />, 'settings'])
}

return items
}, [pathname, uiEnabled])
const navItems = [
[<NotificationIcon isFilled={pathname.endsWith('/notifications')} />, 'notifications'],
[<NewAppIcon isFilled={pathname.includes('/new-app')} />, 'new-app'],
[<SettingIcon isFilled={pathname.includes('/settings')} />, 'settings']
] as const

return (
<div className="MobileFooter">
Expand Down
40 changes: 11 additions & 29 deletions src/components/layout/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Avatar from '@/components/account/Avatar'
import MessageIcon from '@/components/general/Icon/MessageIcon'
import NotificationIcon from '@/components/general/Icon/NotificationIcon'
import SettingIcon from '@/components/general/Icon/SettingIcon'
import WalletConnectIcon from '@/components/general/Icon/WalletConnectIcon'
import ConnectWalletButton from '@/components/login/ConnectWalletButton'
import W3iContext from '@/contexts/W3iContext/context'
import { getEthChainAddress } from '@/utils/address'
Expand All @@ -28,35 +27,18 @@ const SidebarItem: React.FC<{ children?: React.ReactNode; isDisabled?: boolean }
const Sidebar: React.FC<{ isLoggedIn: boolean }> = ({ isLoggedIn }) => {
const { pathname } = useLocation()
const navigationPaths = useMemo(() => pathname.split('/'), [pathname])
const { userPubkey, uiEnabled } = useContext(W3iContext)
const { userPubkey } = useContext(W3iContext)
const isMobile = useIsMobile()

const navItems = useMemo(() => {
const items: [React.ReactNode, string][] = []

if (uiEnabled.chat) {
items.push([
<MessageIcon isFilled={pathname.startsWith(NAVIGATION.messages.index)} />,
NAVIGATION.messages.index
])
}

if (uiEnabled.notify) {
items.push([
<NotificationIcon isFilled={pathname.startsWith(NAVIGATION.notifications.index)} />,
NAVIGATION.notifications.index
])
}

if (uiEnabled.settings) {
items.push([
<SettingIcon isFilled={pathname.startsWith(NAVIGATION.settings.index)} />,
NAVIGATION.settings.index
])
}

return items
}, [pathname, uiEnabled])
const navItems: [React.ReactNode, string][] = [
[
<NotificationIcon isFilled={pathname.startsWith(NAVIGATION.notifications.index)} />,
NAVIGATION.notifications.index
],
[
<SettingIcon isFilled={pathname.startsWith(NAVIGATION.settings.index)} />,
NAVIGATION.settings.index
]
]

// If pathname matches .*/.*/.*
// As per design, sidebar in mobile is hidden when on "Main" is viewed on messages
Expand Down
35 changes: 0 additions & 35 deletions src/components/messages/ChatInvites/ChatInvitesHeader.tsx

This file was deleted.

Loading
Loading