Skip to content

Commit ceff204

Browse files
authored
Merge pull request #438 from WalletConnect/feat/w3m-email-alpha
feat: initialize w3m email alpha
2 parents 4856a95 + ef6a250 commit ceff204

File tree

13 files changed

+928
-688
lines changed

13 files changed

+928
-688
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
},
2121
"dependencies": {
2222
"@sentry/react": "^7.93.0",
23+
"@tanstack/react-query": "^5.20.1",
2324
"@walletconnect/core": "2.11.0",
2425
"@walletconnect/identity-keys": "^1.0.1",
2526
"@walletconnect/notify-client": "^0.16.5",
2627
"@walletconnect/notify-message-decrypter": "^0.1.0",
27-
"@web3modal/wagmi": "^3.5.7",
28+
"@web3modal/wagmi": "4.0.4",
2829
"classnames": "^2.3.2",
2930
"date-fns": "^2.29.3",
3031
"detect-browser": "^5.3.0",
@@ -40,9 +41,9 @@
4041
"react-router-dom": "^6.4.4",
4142
"react-select": "^5.7.0",
4243
"rxjs": "^7.6.0",
43-
"viem": "^1.11.0",
44+
"viem": "2.7.8",
4445
"vite-plugin-pwa": "^0.16.7",
45-
"wagmi": "^1.4.13"
46+
"wagmi": "2.5.5"
4647
},
4748
"devDependencies": {
4849
"@playwright/test": "^1.40.1",

src/Modals.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const Modals = () => {
5959
if (userPubkey && notifySignatureRequired) {
6060
if (isWeb3ModalOpen) {
6161
// Close web3modal in case user is switching accounts
62-
closeWeb3Modal()
62+
// closeWeb3Modal()
6363
}
6464
signatureModalService.openModal()
6565
} else {
@@ -91,9 +91,7 @@ export const Modals = () => {
9191

9292
{shouldShowPreferencesModalOpen && <PreferencesModal />}
9393

94-
{shouldShowSignatureModal && (
95-
<SignatureModal message={notifyRegisterMessage ?? ''} sender={'notify'} />
96-
)}
94+
{shouldShowSignatureModal && <SignatureModal message={notifyRegisterMessage ?? ''} />}
9795

9896
{shouldShowPWAModal && <PwaModal />}
9997

src/components/account/Avatar/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const Avatar: React.FC<AvatarProps> = ({ address, width, height }) => {
1818

1919
const addressOrEnsDomain = address as `0x${string}` | undefined
2020
const { data: ensName } = useEnsName({ address: addressOrEnsDomain })
21-
const { data: ensAvatar } = useEnsAvatar({ name: ensName })
21+
const { data: ensAvatar } = useEnsAvatar({ name: ensName ?? '' })
2222

2323
return (
2424
<div

src/components/messages/NewChat/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { Fragment, useCallback, useContext, useEffect, useMemo, useState } from 'react'
22

3-
import { fetchEnsAddress } from '@wagmi/core'
3+
import { getEnsAddress } from '@wagmi/core'
44
import debounce from 'lodash.debounce'
55
import { NavLink, useNavigate } from 'react-router-dom'
66

@@ -16,6 +16,7 @@ import { isValidAddressOrEnsDomain, isValidEnsDomain } from '@/utils/address'
1616
import { useColorModeValue, useIsMobile } from '@/utils/hooks'
1717
import { truncate } from '@/utils/string'
1818
import { showErrorMessageToast } from '@/utils/toasts'
19+
import { wagmiConfig } from '@/utils/wagmiConfig'
1920

2021
import SearchSuggestions from './SearchSuggestions'
2122

@@ -46,7 +47,7 @@ const NewChat: React.FC = () => {
4647
const resolveAddress = async (inviteeAddress: string) => {
4748
// eslint-disable-next-line prefer-regex-literals
4849
if (isValidEnsDomain(inviteeAddress)) {
49-
const resolvedAddress = await fetchEnsAddress({
50+
const resolvedAddress = await getEnsAddress(wagmiConfig, {
5051
name: inviteeAddress
5152
})
5253

src/index.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,7 @@ video {
7878
padding-bottom: 1rem;
7979
}
8080
}
81+
82+
#w3m-iframe {
83+
border: none;
84+
}

src/main.tsx

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,57 @@
11
import React from 'react'
22

3-
import { createWeb3Modal, defaultWagmiConfig } from '@web3modal/wagmi/react'
3+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
4+
import { createWeb3Modal } from '@web3modal/wagmi/react'
45
import ReactDOM from 'react-dom/client'
56
import { BrowserRouter } from 'react-router-dom'
6-
import { WagmiConfig } from 'wagmi'
7-
import { arbitrum, avalanche, bsc, mainnet, polygon } from 'wagmi/chains'
7+
import { WagmiProvider } from 'wagmi'
88

99
import { PRIVACY_POLICY_URL, TERMS_OF_SERVICE_URL } from '@/constants/web3Modal'
1010
import SettingsContextProvider from '@/contexts/SettingsContext'
1111
import W3iContextProvider from '@/contexts/W3iContext'
1212
import ConfiguredRoutes from '@/routes'
1313
import { polyfill } from '@/utils/polyfill'
1414
import { initSentry } from '@/utils/sentry'
15+
import { metadata, wagmiConfig } from '@/utils/wagmiConfig'
1516

1617
import { Modals } from './Modals'
18+
import DevTimeStamp from './components/dev/DevTimeStamp'
1719

1820
import './index.css'
19-
import DevTimeStamp from './components/dev/DevTimeStamp'
2021

2122
polyfill()
2223
initSentry()
2324

2425
const projectId = import.meta.env.VITE_PROJECT_ID
25-
const chains = [mainnet, arbitrum, polygon, avalanche, bsc]
26-
27-
const metadata = {
28-
name: 'Web3Inbox',
29-
description: 'Notification Hub',
30-
url: 'https://app.web3inbox.com',
31-
icons: ['https://app.web3inbox.com/logo.png']
32-
}
33-
const wagmiConfig = defaultWagmiConfig({ chains, projectId, metadata })
3426

3527
createWeb3Modal({
3628
wagmiConfig,
3729
enableAnalytics: import.meta.env.PROD,
38-
chains,
3930
projectId,
31+
termsConditionsUrl: TERMS_OF_SERVICE_URL,
32+
privacyPolicyUrl: PRIVACY_POLICY_URL,
4033
themeMode: 'light',
4134
themeVariables: { '--w3m-z-index': 9999 },
42-
termsConditionsUrl: TERMS_OF_SERVICE_URL,
43-
privacyPolicyUrl: PRIVACY_POLICY_URL
35+
metadata
4436
})
4537

38+
const queryClient = new QueryClient()
39+
4640
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4741
ReactDOM.createRoot(document.getElementById('root')!).render(
4842
<React.StrictMode>
49-
<WagmiConfig config={wagmiConfig}>
50-
<SettingsContextProvider>
51-
<BrowserRouter>
52-
<W3iContextProvider>
53-
<ConfiguredRoutes />
54-
<DevTimeStamp />
55-
<Modals />
56-
</W3iContextProvider>
57-
</BrowserRouter>
58-
</SettingsContextProvider>
59-
</WagmiConfig>
43+
<WagmiProvider config={wagmiConfig}>
44+
<QueryClientProvider client={queryClient}>
45+
<SettingsContextProvider>
46+
<BrowserRouter>
47+
<W3iContextProvider>
48+
<ConfiguredRoutes />
49+
<DevTimeStamp />
50+
<Modals />
51+
</W3iContextProvider>
52+
</BrowserRouter>
53+
</SettingsContextProvider>
54+
</QueryClientProvider>
55+
</WagmiProvider>
6056
</React.StrictMode>
6157
)

src/pages/Login/SignatureModal/index.tsx

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import React, { useCallback } from 'react'
1+
import React from 'react'
22

33
import { formatJsonRpcRequest } from '@walletconnect/jsonrpc-utils'
4-
import { useDisconnect } from 'wagmi'
4+
import { useAccount, useDisconnect } from 'wagmi'
55

66
import Button from '@/components/general/Button'
77
import CrossIcon from '@/components/general/Icon/CrossIcon'
88
import SignatureIcon from '@/components/general/Icon/SignatureIcon'
99
import Wallet from '@/components/general/Icon/Wallet'
1010
import { Modal } from '@/components/general/Modal/Modal'
11+
import Spinner from '@/components/general/Spinner'
1112
import Text from '@/components/general/Text'
12-
import { logError } from '@/utils/error'
1313
import { useModals } from '@/utils/hooks'
1414
import { signatureModalService } from '@/utils/store'
1515

@@ -19,37 +19,31 @@ import './SignatureModal.scss'
1919

2020
export const SignatureModal: React.FC<{
2121
message: string
22-
sender: 'chat' | 'notify'
23-
}> = ({ message, sender }) => {
22+
}> = ({ message }) => {
23+
const { status } = useAccount()
24+
const connected = status === 'connected'
25+
2426
/*
2527
* If identity was already signed, and sync was requested then we are in the
2628
* final step.
2729
*/
2830
const { isSigning } = useModals()
2931
const { disconnect } = useDisconnect()
3032

31-
const onSign = useCallback(() => {
33+
const onSign = () => {
3234
signatureModalService.startSigning()
3335
window.web3inbox
3436
.signMessage(message)
3537
.then(signature => {
36-
switch (sender) {
37-
case 'chat':
38-
console.warn('[Web3Inbox] Signing messages for chat is not supported.')
39-
break
40-
case 'notify':
41-
window.web3inbox.notify.postMessage(
42-
formatJsonRpcRequest('notify_signature_delivered', { signature })
43-
)
44-
break
45-
default:
46-
logError(new Error(`No correct sender for signature modal, sender: ${sender}`))
47-
}
38+
window.web3inbox.notify.postMessage(
39+
formatJsonRpcRequest('notify_signature_delivered', { signature })
40+
)
4841
})
4942
.catch(() => {
43+
console.error('Failed to sign message')
5044
signatureModalService.stopSigning()
5145
})
52-
}, [message, sender])
46+
}
5347

5448
return (
5549
<Modal onCloseModal={signatureModalService.closeModal}>
@@ -77,9 +71,9 @@ export const SignatureModal: React.FC<{
7771
</Text>
7872
<div className="SignatureModal__button">
7973
<Button
80-
disabled={isSigning}
74+
disabled={isSigning || !connected}
8175
textVariant="paragraph-600"
82-
rightIcon={isSigning ? null : <Wallet />}
76+
rightIcon={!connected ? <Spinner /> : isSigning ? null : <Wallet />}
8377
onClick={onSign}
8478
>
8579
{isSigning ? 'Waiting for wallet...' : 'Sign in with wallet'}

src/utils/ens.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { PublicClient } from 'viem'
12
import { normalize } from 'viem/ens'
2-
import type { PublicClient } from 'wagmi'
33

44
declare const localStorage: Storage | undefined
55

src/utils/wagmiConfig.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { arbitrum, avalanche, bsc, mainnet, polygon } from '@wagmi/core/chains'
2+
import { defaultWagmiConfig } from '@web3modal/wagmi'
3+
4+
const projectId = import.meta.env.VITE_PROJECT_ID
5+
6+
export const metadata = {
7+
name: 'Web3Inbox',
8+
description: 'Web3Inbox App',
9+
url: 'https://web3inbox.com',
10+
icons: ['https://assets.web3inbox.com/images/w3i-app-logo.png']
11+
}
12+
13+
export const wagmiConfig = defaultWagmiConfig({
14+
chains: [mainnet, arbitrum, polygon, avalanche, bsc],
15+
projectId,
16+
metadata,
17+
enableEmail: true
18+
})

src/w3iProxy/authProviders/internalAuthProvider.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,35 @@
1-
import { getAccount, getNetwork, watchAccount, watchNetwork } from '@wagmi/core'
1+
import { getAccount, watchAccount } from '@wagmi/core'
22
import type { JsonRpcRequest } from '@walletconnect/jsonrpc-types'
33
import type { EventEmitter } from 'events'
44

55
import { getEIPChainString } from '@/utils/chain'
6+
import { wagmiConfig } from '@/utils/wagmiConfig'
67

78
export default class InternalAuthProvider {
89
private readonly methodsListenedTo = ['auth_set_account']
910
public providerName = 'InternalAuthProvider'
10-
public account?: string = getAccount().address
11-
public chain?: string = getEIPChainString(getNetwork().chain?.id)
11+
public account?: string = getAccount(wagmiConfig).address
12+
public chain?: string = getEIPChainString(getAccount(wagmiConfig).chain?.id)
1213
protected readonly emitter: EventEmitter
1314

1415
public constructor(emitter: EventEmitter, _name = 'InternalAuthProvider') {
1516
this.emitter = emitter
1617

17-
watchNetwork(network => {
18-
const caip10Chain = getEIPChainString(getNetwork().chain?.id)
19-
this.chain = caip10Chain
18+
watchAccount(wagmiConfig, {
19+
onChange: data => {
20+
const chainId = getAccount(wagmiConfig).chainId
2021

21-
this.emitter.emit('auth_set_account', { account: this.account, chain: caip10Chain })
22-
})
23-
24-
watchAccount(account => {
25-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
26-
if (!account.address) {
27-
this.emitter.emit('auth_set_account', { account: null, chain: null })
22+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
23+
if (!data.address) {
24+
this.emitter.emit('auth_set_account', { account: null, chain: null })
25+
return
26+
}
2827

29-
return
28+
const caip10Chain = getEIPChainString(chainId)
29+
this.emitter.emit('auth_set_account', { account: data.address, chain: caip10Chain })
30+
this.chain = caip10Chain
31+
this.account = data.address
3032
}
31-
32-
const caip10Chain = getEIPChainString(getNetwork().chain?.id)
33-
this.emitter.emit('auth_set_account', { account: account.address, chain: caip10Chain })
34-
this.chain = caip10Chain
35-
this.account = account.address
3633
})
3734
}
3835

@@ -52,7 +49,7 @@ export default class InternalAuthProvider {
5249
}
5350

5451
public async initState() {
55-
this.account = getAccount().address
52+
this.account = getAccount(wagmiConfig).address
5653
if (this.account) {
5754
this.emitter.emit('auth_set_account', { account: this.account, chain: this.chain })
5855
}

src/w3iProxy/chatProviders/internalChatProvider.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import type { ICore, IStore } from '@walletconnect/types'
1111
import type { EventEmitter } from 'events'
1212
import pino from 'pino'
1313

14+
import { wagmiConfig } from '@/utils/wagmiConfig'
15+
1416
import type { ChatClientTypes } from './types'
1517
import type { W3iChatProvider } from './types'
1618

@@ -89,7 +91,7 @@ export default class InternalChatProvider implements W3iChatProvider {
8991
}
9092

9193
private getRequiredInternalAddress(): string {
92-
const address = getAccount().address
94+
const address = getAccount(wagmiConfig).address
9395
if (!address) {
9496
throw new Error('No address registered')
9597
}

src/w3iProxy/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { Logger } from 'pino'
99

1010
import type { UiEnabled } from '@/contexts/W3iContext/context'
1111
import { identifyMixpanelUserAndInit } from '@/utils/mixpanel'
12+
import { wagmiConfig } from '@/utils/wagmiConfig'
1213
import W3iAuthFacade from '@/w3iProxy/w3iAuthFacade'
1314
import type W3iChatFacade from '@/w3iProxy/w3iChatFacade'
1415
import W3iNotifyFacade from '@/w3iProxy/w3iNotifyFacade'
@@ -101,7 +102,7 @@ class Web3InboxProxy {
101102
this.dappOrigin = dappOrigin
102103

103104
this.signMessage = async (message: string) => {
104-
return signMessage({ message })
105+
return signMessage(wagmiConfig, { message })
105106
}
106107
}
107108

0 commit comments

Comments
 (0)