Skip to content

Commit

Permalink
chore: fix more build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
devceline committed Feb 29, 2024
1 parent 02db34b commit 7504239
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 120 deletions.
6 changes: 6 additions & 0 deletions missing_in_hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@
1. `useSubscribtion` should expose `getSubscription` which takes params.
2. `useSubscribtion` should expose `isSubscribed` for convenience.

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

# Things that would be nice

## Fetch projects from cloud
8 changes: 1 addition & 7 deletions src/components/settings/ContactsModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useContext } from 'react'
import React, { useCallback } from 'react'

import capitalize from 'lodash/capitalize'

Expand All @@ -7,9 +7,6 @@ import Button from '@/components/general/Button'
import CrossIcon from '@/components/general/Icon/CrossIcon'
import Input from '@/components/general/Input'
import { Modal } from '@/components/general/Modal/Modal'
import PeerAndMessage from '@/components/messages/PeerAndMessage'
import SettingsContext from '@/contexts/SettingsContext/context'
import { useColorModeValue } from '@/utils/hooks'
import { contactsModalService } from '@/utils/store'

import './ContactsModal.scss'
Expand All @@ -32,8 +29,6 @@ const ContactsModal: React.FC<ContactsModalProps> = ({
mutedContacts,
setMutedContacts
}) => {
const { mode } = useContext(SettingsContext)
const themeColors = useColorModeValue(mode)

const handleContactAction = useCallback(
(topic: string) => {
Expand Down Expand Up @@ -68,7 +63,6 @@ const ContactsModal: React.FC<ContactsModalProps> = ({
/>
{mutedContacts.map(contact => (
<div key={contact.topic} className="ContactsModal__content__contact">
<PeerAndMessage peer={contact.address} message="" withAvatar={true} />
<Button customType="action" onClick={() => handleContactAction(contact.topic)}>
{status === 'muted' ? 'Unmute' : 'Unblock'}
</Button>
Expand Down
10 changes: 3 additions & 7 deletions src/components/settings/NotificationsSettings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import PrivacyIcon from '@/components/general/Icon/Privacy'
import Input from '@/components/general/Input'
import MobileHeader from '@/components/layout/MobileHeader'
import SettingsContext from '@/contexts/SettingsContext/context'
import W3iContext from '@/contexts/W3iContext/context'
import { useNotificationPermissionState } from '@/utils/hooks/notificationHooks'
import { getDbEchoRegistrations } from '@/utils/idb'
import { notificationsAvailableInBrowser, requireNotifyPermission } from '@/utils/notifications'
Expand All @@ -22,6 +21,8 @@ import SettingsToggle from '../SettingsToggle/Index'

import './NotificationsSettings.scss'

const { useRegisterWithEcho } from '@web3inbox/react'

const getHelperTooltip = () => {
switch (window.Notification?.permission) {
case 'denied':
Expand All @@ -35,7 +36,6 @@ const getHelperTooltip = () => {

const NotificationsSettings: React.FC = () => {
const { isDevModeEnabled, updateSettings, filterAppDomain } = useContext(SettingsContext)
const { notifyClientProxy } = useContext(W3iContext)
const [domain, setDomain] = useState(filterAppDomain)

const canSave = domain !== filterAppDomain
Expand All @@ -56,12 +56,8 @@ const NotificationsSettings: React.FC = () => {
}, [])

const handleEnableNotifications = async () => {
if (!notifyClientProxy) {
return
}

if (await requireNotifyPermission()) {
await notifyClientProxy.registerWithEcho()
await registerWithEcho()
}
}

Expand Down
87 changes: 3 additions & 84 deletions src/components/settings/Settings/index.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import React, { useCallback, useContext, useEffect, useState } from 'react'
import React, { useCallback, useContext, useState } from 'react'

import { useWeb3ModalTheme } from '@web3modal/wagmi/react'
import cn from 'classnames'
import { useLocation } from 'react-router-dom'

import ArtistPalette from '@/assets/ArtistPalette.png'
import ColoredNotificationBell from '@/assets/ColoredNotificationBell.png'
import DarkCity from '@/assets/DarkCity.png'
import HalfHalfCity from '@/assets/HalfHalfCity.png'
import Handshake from '@/assets/Handshake.png'
import LightCity from '@/assets/LightCity.png'
import IconWrapper from '@/components/general/Icon/IconWrapper/IconWrapper'
import type { SettingsContextSimpleState } from '@/contexts/SettingsContext/context'
// eslint-disable-next-line no-duplicate-imports
import SettingsContext from '@/contexts/SettingsContext/context'
import W3iContext from '@/contexts/W3iContext/context'
import { useIsMobile, useModals } from '@/utils/hooks'
import { useModals } from '@/utils/hooks'

import ContactsModal from '../ContactsModal'

Expand All @@ -27,12 +23,6 @@ const themeModes: { id: SettingsContextSimpleState['mode']; icon: string }[] = [
{ id: 'system', icon: HalfHalfCity }
]

const newContactModes: { id: SettingsContextSimpleState['newContacts']; label: string }[] = [
{ id: 'require-invite', label: 'Require new contacts to send me a chat invite' },
{ id: 'reject-new', label: 'Decline all chat invites from new contacts' },
{ id: 'accept-new', label: 'Accept all chat invites from new contacts' }
]

/*
* Const currencyOptions = [
* {
Expand All @@ -47,13 +37,9 @@ const newContactModes: { id: SettingsContextSimpleState['newContacts']; label: s
*/

const Settings: React.FC = () => {
const { mode, newContacts, isDevModeEnabled, updateSettings } = useContext(SettingsContext)
const { mode, updateSettings } = useContext(SettingsContext)
const { isContactModalOpen } = useModals()
const { uiEnabled } = useContext(W3iContext)
const [mutedContacts, setMutedContacts] = useState<{ topic: string; address: string }[]>([])
const { pathname } = useLocation()
const { setThemeMode } = useWeb3ModalTheme()
const isMobile = useIsMobile()

const handleThemeChange = useCallback(
(modeId: SettingsContextSimpleState['mode']) => {
Expand Down Expand Up @@ -134,73 +120,6 @@ const Settings: React.FC = () => {
</div>
</div>

{uiEnabled.chat ? (
<div className="Settings__section Settings__contacts">
<div className="Settings__section-title">
<IconWrapper shape="square" bgColor="purple">
<img src={Handshake} alt="contacts-icon" />
</IconWrapper>
<span>Contacts</span>
</div>
<div className="Settings__section-settings">
<div className="Settings__section-subtitle">New Contacts</div>
{/* {newContactModes.map(({ id, label }) => (
<Radio
name="new-contacts"
id={id}
key={id}
label={label}
checked={newContacts === id}
onCheck={() => updateSettings({ newContacts: id })}
/>
))} */}
<div className="Settings__section-helper-text">
People that want to message you will need to send an invite first that you can accept
or decline. Think of it as a polite handshake to start the conversation.
</div>
{/*
<div className="Settings__setting">
<div className="Settings__toggle-label">
Decline new contacts without any transactions onchain
</div>
<Toggle name="decline-new-contacts" id="decline-new-contacts" />
</div>
<div className="Settings__section-helper-text">
People with no transaction history will be blocked from contacting you. Enabling this
can help weed out spam.
</div>
*/}
{/*
<div
className="Settings__setting"
onClick={() => {
chatClientProxy?.getMutedContacts().then(({ length }) => {
if (length) {
contactsModalService.openModal()
}
})
}}
>
<div>Muted contacts</div>
<div className="Settings__toggle-dropdown">
<CircleBadge>{mutedContacts.length}</CircleBadge>
<ArrowRightIcon />
</div>
</div>
*/}
{/*
<div className="Settings__setting">
<div>Blocked contacts</div>
<div className="Settings__toggle-dropdown">
<CircleBadge>0</CircleBadge>
<ArrowRightIcon />
</div>
</div>
*/}
</div>
</div>
) : null}
{/*
<div className="Settings__section Settings_crypto">
<div className="Settings__section-title">
Expand Down
4 changes: 2 additions & 2 deletions src/components/utils/AuthProtectedPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ interface AuthProtectedPageProps {
}

const AuthProtectedPage: React.FC<AuthProtectedPageProps> = ({ children }) => {
const { userPubkey, authProvider } = useContext(W3iContext)
const { userPubkey } = useContext(W3iContext)
const loc = useLocation()
const next = `${loc.pathname}${loc.search}`

if (!userPubkey && authProvider === 'internal') {
if (!userPubkey) {
const query = next.length > 1 ? `?next=${encodeURIComponent(next)}` : ''

return <Navigate to={`/login${query}`} />
Expand Down
10 changes: 2 additions & 8 deletions src/components/utils/NotificationPwaModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,20 @@ import Button from '@/components/general/Button'
import CrossIcon from '@/components/general/Icon/CrossIcon'
import { Modal } from '@/components/general/Modal/Modal'
import Text from '@/components/general/Text'
import W3iContext from '@/contexts/W3iContext/context'
import { closeNotificationModal, requireNotifyPermission } from '@/utils/notifications'
import { pwaModalService } from '@/utils/store'
import { useRegisterWithEcho } from '@web3inbox/react'

import './NotificationPwaModal.scss'

export const NotificationPwaModal: React.FC = () => {
const { notifyClientProxy } = useContext(W3iContext)

const explicitlyDeniedPermissionForNotifications = window.Notification?.permission === 'denied'

const handleEnableNotifications = async () => {
const notificationPermissionGranted = await requireNotifyPermission()

if (!notifyClientProxy) {
return
}

if (notificationPermissionGranted) {
await notifyClientProxy.registerWithEcho()
await registerWithEcho()
}
}

Expand Down
12 changes: 5 additions & 7 deletions src/contexts/W3iContext/hooks/w3iProxyHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,20 @@ import { logError } from '@/utils/error'

import Web3InboxProxy from '../../../w3iProxy'
import { useDappOrigin } from './dappOrigin'
import { useProviderQueries } from './providerQueryHooks'
import { useUiState } from './uiHooks'

export const useW3iProxy = () => {
const relayUrl = import.meta.env.VITE_RELAY_URL
const projectId = import.meta.env.VITE_PROJECT_ID

const { uiEnabled } = useUiState()
const [ready, setReady] = useState(false)
const { dappOrigin } = useDappOrigin()
const { notifyProvider, authProvider } = useProviderQueries()

const [w3iProxy] = useState(
Web3InboxProxy.getProxy(notifyProvider, authProvider, dappOrigin, projectId, relayUrl, {
...uiEnabled,
chat: false
Web3InboxProxy.getProxy('internal', 'internal', dappOrigin, projectId, relayUrl, {
chat: true,
notify: true,
settings: true,
sidebar: true
})
)

Expand Down
8 changes: 3 additions & 5 deletions src/pages/Login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import W3iContext from '@/contexts/W3iContext/context'
import './Login.scss'

const Login: React.FC = () => {
const { userPubkey, uiEnabled, notifyRegisteredKey } = useContext(W3iContext)
const { userPubkey, notifyRegisteredKey } = useContext(W3iContext)
const { search } = useLocation()
const next = new URLSearchParams(search).get('next')
const nav = useNavigate()
Expand All @@ -26,15 +26,13 @@ const Login: React.FC = () => {
const path = next ? decodeURIComponent(next) : '/'

if (userPubkey) {
const notifyConditionsPass = Boolean(
(!uiEnabled.chat || uiEnabled.notify) && notifyRegisteredKey
)
const notifyConditionsPass = Boolean(notifyRegisteredKey)

if (notifyConditionsPass) {
nav(path)
}
}
}, [userPubkey, next, notifyRegisteredKey, uiEnabled])
}, [userPubkey, next, notifyRegisteredKey])

return (
<TransitionDiv className="Login">
Expand Down

0 comments on commit 7504239

Please sign in to comment.