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

feat: add support for eip5792 getCapabilities and sendCalls #2576

Merged
merged 61 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
195855f
chore: add required listeners
devceline May 23, 2024
2d45778
feat: successful getCapabilities call
devceline May 23, 2024
85919a8
feat: successful getCapabilities call
devceline May 23, 2024
34e4a86
feat: support wallet_getCalls
devceline May 24, 2024
fda468e
chore: format
devceline May 24, 2024
6ab8122
chore: format
devceline May 24, 2024
f77df04
chore: fix build errors
devceline May 24, 2024
980497c
chore: format
devceline May 24, 2024
ee7c48a
chore: recover service test
devceline May 24, 2024
a576a24
chore: remove unused console log
devceline May 24, 2024
0c98ebf
chore: resurrect utils
devceline May 24, 2024
b8b9499
chore: prettier format
devceline May 24, 2024
36cb863
chore: add paymaster capabilities
devceline May 30, 2024
4c65e0f
feat: refactor W3mFrameProvider to remove event handlers for direct w…
tomiir Jul 10, 2024
06305e1
Merge branch 'main' of github.com:WalletConnect/web3modal into feat/w…
tomiir Jul 16, 2024
894715f
chore: remove logs
tomiir Jul 16, 2024
6fa8735
chore: remove unnecessary function call
tomiir Jul 16, 2024
285424f
fix: type issue
tomiir Jul 16, 2024
68f1630
fix: lint fixes
tomiir Jul 16, 2024
47a5422
chore: remove unused comment
tomiir Jul 16, 2024
be601aa
Merge branch 'main' of github.com:WalletConnect/web3modal into chore/…
tomiir Jul 16, 2024
b733eeb
chore: add logger to appEvents
tomiir Jul 16, 2024
66d99b1
feat: add abort controllers to remove listeners and reject rpc requests
tomiir Jul 16, 2024
1d75098
chore: add happy path tests
tomiir Jul 16, 2024
e0f5dc7
chore: improve tests
tomiir Jul 16, 2024
1e6c8cf
chore: remove unused import
tomiir Jul 16, 2024
ce8bf2b
chore: add strict vitest version
tomiir Jul 16, 2024
c622501
chore: add SecureSiteMock
tomiir Jul 16, 2024
f092de3
chore: improve test by checking storage
tomiir Jul 16, 2024
9c3a0b6
chore: remove logs
tomiir Jul 16, 2024
d5ab204
chore: remove comments, logs and use Promise instead of setTimeout
tomiir Jul 17, 2024
aab1d7c
fix: only handle RPC open RPC requests
tomiir Jul 17, 2024
c1bc4a7
chore: disable Array rule as obj[] will not consider empty arrays
tomiir Jul 17, 2024
5ac735f
Merge branch 'main' of github.com:WalletConnect/web3modal into feat/w…
tomiir Jul 21, 2024
c92d110
Merge branch 'chore/rpc-refactor' of github.com:WalletConnect/web3mod…
tomiir Jul 21, 2024
88e759f
fix: rpc response handler
tomiir Jul 22, 2024
65f90d5
feat: refactor ethers to use rpc response and error handlers
tomiir Jul 22, 2024
e90884f
feat: working properly on ethers
tomiir Jul 22, 2024
e5b7819
chore: remove any
tomiir Jul 22, 2024
408f4c1
Merge branch 'main' of github.com:WalletConnect/web3modal into feat/e…
tomiir Jul 24, 2024
3d10166
chore: add skipped test for sendcalls and getcallsstatus
tomiir Jul 24, 2024
9312712
chore: remove unused import
tomiir Jul 25, 2024
30b3bd6
Merge branch 'main' into feat/eip-5792
tomiir Jul 25, 2024
eb3ae4c
Merge branch 'main' of github.com:WalletConnect/web3modal into feat/e…
tomiir Jul 25, 2024
28bc815
Merge branch 'feat/eip-5792' of github.com:WalletConnect/web3modal in…
tomiir Jul 25, 2024
4a7c7f5
fix: WAgmiSendCallsWithPM integration in lab
tomiir Jul 25, 2024
d8c1b0c
fix: loose dependency
tomiir Jul 25, 2024
e791dd4
fix: lock for loose dependency
tomiir Jul 25, 2024
667b737
Merge branch 'main' of github.com:WalletConnect/web3modal into feat/e…
tomiir Jul 29, 2024
119837e
Merge branch 'main' of github.com:WalletConnect/web3modal into feat/e…
tomiir Aug 5, 2024
8b32d8b
Update apps/laboratory/src/components/Ethers/EthersSendCallsWithPayma…
tomiir Aug 5, 2024
93ebbdc
Merge branch 'main' of github.com:WalletConnect/web3modal into feat/e…
tomiir Aug 5, 2024
22462c1
chore: remove type check, improve code
tomiir Aug 5, 2024
a2f690e
Merge branch 'main' into feat/eip-5792
tomiir Aug 6, 2024
2e915da
chore: remove log
tomiir Aug 6, 2024
af3df11
fix: ethers test type issues
tomiir Aug 6, 2024
2c8d14b
chore: ignore lint in test
tomiir Aug 6, 2024
c29098d
fix: logger typo
tomiir Aug 6, 2024
030586a
chore: fix tpye issues in tests, remove unused test
tomiir Aug 6, 2024
a859400
chore: add dev comments on capability checks
tomiir Aug 6, 2024
d9b9d61
fix: issue where modal was not closing after RPC requests
tomiir Aug 6, 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
6 changes: 5 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"ignorePatterns": [
"node_modules",
"*.config.js",
"*.config.ts",
"next-env.d.ts",
"out",
"dist",
Expand All @@ -22,7 +23,9 @@
"examples",
"coverage",
".changeset",
"playwright-report"
"playwright-report",
"*.mock.ts",
"*.test.ts"
],
"rules": {
// Core
Expand Down Expand Up @@ -65,6 +68,7 @@
],

// Typescript
"@typescript-eslint/array-type": "off",
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
"@typescript-eslint/dot-notation": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
Expand Down
1 change: 1 addition & 0 deletions apps/laboratory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"@web3modal/siwe": "workspace:*",
"@web3modal/solana": "workspace:*",
"@web3modal/wagmi": "workspace:*",
"@web3modal/wallet": "workspace:*",
"bs58": "6.0.0",
"ethers": "6.13.0",
"framer-motion": "10.17.9",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useWeb3ModalAccount, useWeb3ModalProvider } from '@web3modal/ethers/rea
import { EthereumProvider } from '@walletconnect/ethereum-provider'
import { useChakraToast } from '../Toast'
import { BrowserProvider } from 'ethers'
import { W3mFrameProvider } from '@web3modal/wallet'
import { type GetCallsStatusParams } from '../../types/EIP5792'
import { EIP_5792_RPC_METHODS } from '../../utils/EIP5792Utils'

Expand Down Expand Up @@ -47,6 +48,10 @@ export function EthersGetCallsStatusTest() {
}
}
function isGetCallsStatusSupported(): boolean {
// We are currently checking capabilities above. We should use those capabilities instead of this check.
if (walletProvider instanceof W3mFrameProvider) {
return true
}
if (walletProvider instanceof EthereumProvider) {
return Boolean(
walletProvider?.signer?.session?.namespaces?.['eip155']?.methods?.includes(
Expand Down Expand Up @@ -82,7 +87,7 @@ export function EthersGetCallsStatusTest() {
isDisabled={isLoading}
/>
<Button
data-test-id="get-calls-status-button"
data-testid="get-calls-status-button"
onClick={onGetCallsStatus}
isDisabled={isLoading}
>
Expand Down
57 changes: 44 additions & 13 deletions apps/laboratory/src/components/Ethers/EthersSendCallsTest.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { Button, Stack, Text, Spacer } from '@chakra-ui/react'
import { useState } from 'react'
import { Button, Stack, Text, Spacer, Heading } from '@chakra-ui/react'
import { useState, useEffect } from 'react'
import { useWeb3ModalAccount, useWeb3ModalProvider } from '@web3modal/ethers/react'
import { EthereumProvider } from '@walletconnect/ethereum-provider'
import { useChakraToast } from '../Toast'
import { parseGwei, type Address } from 'viem'
import type { Address } from 'viem'
import { vitalikEthAddress } from '../../utils/DataUtil'
import { BrowserProvider } from 'ethers'
import {
EIP_5792_RPC_METHODS,
WALLET_CAPABILITIES,
getCapabilitySupportedChainInfo
} from '../../utils/EIP5792Utils'
import { W3mFrameProvider } from '@web3modal/wallet'

type Provider = W3mFrameProvider | Awaited<ReturnType<(typeof EthereumProvider)['init']>>

export function EthersSendCallsTest() {
const [loading, setLoading] = useState(false)
Expand All @@ -19,12 +22,25 @@ export function EthersSendCallsTest() {
const { walletProvider } = useWeb3ModalProvider()
const toast = useChakraToast()

const atomicBatchSupportedChains =
address && walletProvider instanceof EthereumProvider
? getCapabilitySupportedChainInfo(WALLET_CAPABILITIES.ATOMIC_BATCH, walletProvider, address)
: []
const [atomicBatchSupportedChains, setAtomicBatchSupportedChains] = useState<
Awaited<ReturnType<typeof getCapabilitySupportedChainInfo>>
>([])

const [lastCallsBatchId, setLastCallsBatchId] = useState<string | null>(null)

useEffect(() => {
if (address && walletProvider) {
getCapabilitySupportedChainInfo(
WALLET_CAPABILITIES.ATOMIC_BATCH,
walletProvider as Provider,
address
).then(capabilities => setAtomicBatchSupportedChains(capabilities))
} else {
setAtomicBatchSupportedChains([])
}
}, [address, walletProvider, isConnected])

const atomicBatchSupportedChainNames = atomicBatchSupportedChains
const atomicBatchSupportedChainsNames = atomicBatchSupportedChains
.map(ci => ci.chainName)
.join(', ')
const currentChainsInfo = atomicBatchSupportedChains.find(
Expand All @@ -41,12 +57,11 @@ export function EthersSendCallsTest() {
throw Error('chain not selected')
}
const provider = new BrowserProvider(walletProvider, chainId)
const amountToSend = parseGwei('0.001').toString(16)
const calls = [
{
to: vitalikEthAddress as `0x${string}`,
data: '0x' as `0x${string}`,
value: `0x${amountToSend}`
value: `0x0`
},
{
to: vitalikEthAddress as Address,
Expand All @@ -63,6 +78,8 @@ export function EthersSendCallsTest() {
const batchCallHash = await provider.send(EIP_5792_RPC_METHODS.WALLET_SEND_CALLS, [
sendCallsParams
])

setLastCallsBatchId(batchCallHash)
toast({
title: 'Success',
description: batchCallHash,
Expand All @@ -79,6 +96,9 @@ export function EthersSendCallsTest() {
}
}
function isSendCallsSupported(): boolean {
if (walletProvider instanceof W3mFrameProvider) {
return true
}
if (walletProvider instanceof EthereumProvider) {
return Boolean(
walletProvider?.signer?.session?.namespaces?.['eip155']?.methods?.includes(
Expand Down Expand Up @@ -113,15 +133,26 @@ export function EthersSendCallsTest() {
}

return currentChainsInfo ? (
<Stack direction={['column', 'column', 'row']}>
<Button data-test-id="send-calls-button" onClick={onSendCalls} isDisabled={loading}>
<Stack direction={['column', 'column']}>
<Button
data-testid="send-calls-button"
onClick={onSendCalls}
isDisabled={loading}
maxWidth={'50%'}
>
Send Batch Calls to Vitalik
</Button>
<Spacer />
{lastCallsBatchId && (
<>
<Heading size="xs">Last batch call ID:</Heading>
<Text data-testid="send-calls-id">{lastCallsBatchId}</Text>
</>
)}
</Stack>
) : (
<Text fontSize="md" color="yellow">
Switch to {atomicBatchSupportedChainNames} to test atomic batch feature
Switch to {atomicBatchSupportedChainsNames} to test atomic batch feature
</Text>
)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, Stack, Text, Input, Tooltip } from '@chakra-ui/react'
import { useState } from 'react'
import { useState, useEffect } from 'react'
import { useWeb3ModalAccount, useWeb3ModalProvider } from '@web3modal/ethers/react'
import { EthereumProvider } from '@walletconnect/ethereum-provider'
import { useChakraToast } from '../Toast'
Expand All @@ -11,6 +11,7 @@ import {
WALLET_CAPABILITIES,
getCapabilitySupportedChainInfo
} from '../../utils/EIP5792Utils'
import { W3mFrameProvider } from '@web3modal/wallet'

export function EthersSendCallsWithPaymasterServiceTest() {
const [paymasterServiceUrl, setPaymasterServiceUrl] = useState<string>('')
Expand All @@ -20,14 +21,27 @@ export function EthersSendCallsWithPaymasterServiceTest() {
const { walletProvider } = useWeb3ModalProvider()
const toast = useChakraToast()

const paymasterServiceSupportedChains =
address && walletProvider instanceof EthereumProvider
? getCapabilitySupportedChainInfo(
WALLET_CAPABILITIES.PAYMASTER_SERVICE,
walletProvider,
address
)
: []
const [paymasterServiceSupportedChains, setPaymasterServiceSupportedChains] = useState<
Awaited<ReturnType<typeof getCapabilitySupportedChainInfo>>
>([])

useEffect(() => {
if (
address &&
(walletProvider instanceof EthereumProvider || walletProvider instanceof W3mFrameProvider)
) {
getCapabilitySupportedChainInfo(
WALLET_CAPABILITIES.PAYMASTER_SERVICE,
walletProvider,
address
).then(capabilities => {
setPaymasterServiceSupportedChains(capabilities)
})
} else {
setPaymasterServiceSupportedChains([])
}
}, [address, walletProvider])

const paymasterServiceSupportedChainNames = paymasterServiceSupportedChains
.map(ci => ci.chainName)
.join(', ')
Expand Down Expand Up @@ -90,6 +104,7 @@ export function EthersSendCallsWithPaymasterServiceTest() {
}

function isSendCallsSupported(): boolean {
// We are currently checking capabilities above. We should use those capabilities instead of this check.
if (walletProvider instanceof EthereumProvider) {
return Boolean(
walletProvider?.signer?.session?.namespaces?.['eip155']?.methods?.includes(
Expand All @@ -98,7 +113,7 @@ export function EthersSendCallsWithPaymasterServiceTest() {
)
}

return false
return walletProvider instanceof W3mFrameProvider
}

if (!isConnected || !walletProvider || !address) {
Expand Down Expand Up @@ -137,7 +152,7 @@ export function EthersSendCallsWithPaymasterServiceTest() {
</Tooltip>
<Button
width={'fit-content'}
data-test-id="send-calls-paymaster-service-button"
data-testid="send-calls-paymaster-service-button"
onClick={onSendCalls}
isDisabled={isLoading || !paymasterServiceUrl}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function EthersTransactionTest() {
return Number(chainId) !== mainnet.chainId && address ? (
<Stack direction={['column', 'column', 'row']}>
<Button
data-test-id="sign-transaction-button"
data-testid="sign-transaction-button"
onClick={onSendTransaction}
isDisabled={loading}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function EthersWriteContractTest() {
return allowedChains.includes(Number(chainId)) && address ? (
<Stack direction={['column', 'column', 'row']}>
<Button
data-test-id="sign-transaction-button"
data-testid="sign-transaction-button"
onClick={onSendTransaction}
isDisabled={loading}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export function SolanaSendTransactionTest() {
return (
<Stack direction={['column', 'column', 'row']}>
<Button
data-test-id="sign-transaction-button"
data-testid="sign-transaction-button"
onClick={onSendTransaction}
isDisabled={loading}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export function SolanaSignTransactionTest() {
return (
<Stack direction={['column', 'column', 'row']}>
<Button
data-test-id="sign-transaction-button"
data-testid="sign-transaction-button"
onClick={onSignTransaction}
isDisabled={loading}
>
Expand Down
14 changes: 7 additions & 7 deletions apps/laboratory/src/components/Wagmi/WagmiGetCallsStatusTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,23 @@ import { useCallsStatus } from 'wagmi/experimental'
import { useWagmiAvailableCapabilities } from '../../hooks/useWagmiActiveCapabilities'

export function WagmiGetCallsStatusTest() {
const { ethereumProvider, isMethodSupported: isGetCallsStatusSupported } =
useWagmiAvailableCapabilities({
method: EIP_5792_RPC_METHODS.WALLET_GET_CALLS_STATUS
})
const { supported } = useWagmiAvailableCapabilities({
method: EIP_5792_RPC_METHODS.WALLET_GET_CALLS_STATUS
})

const { status, address } = useAccount()

const isConnected = status === 'connected'

if (!isConnected || !ethereumProvider || !address) {
if (!isConnected || !address) {
return (
<Text fontSize="md" color="yellow">
Wallet not connected
</Text>
)
}

if (!isGetCallsStatusSupported()) {
if (!supported) {
return (
<Text fontSize="md" color="yellow">
Wallet does not support the "wallet_getCallsStatus" RPC method
Expand Down Expand Up @@ -74,9 +73,10 @@ function AvailableTestContent() {
onChange={e => setBatchCallId(e.target.value)}
value={batchCallId}
isDisabled={isLoading}
data-testid="get-calls-id-input"
/>
<Button
data-test-id="get-calls-status-button"
data-testid="get-calls-status-button"
onClick={onGetCallsStatus}
isDisabled={isLoading || !batchCallId}
isLoading={isLoading}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export function WagmiRequestPermissionsTest() {
return (
<Stack direction={['column', 'column', 'row']}>
<Button
data-test-id="request-permissions-button"
data-testid="request-permissions-button"
onClick={onRequestPermissions}
isDisabled={Boolean(
isRequestPermissionLoading || Boolean(grantedPermissions) || !isConnected
Expand All @@ -151,7 +151,7 @@ export function WagmiRequestPermissionsTest() {
Request Permissions
</Button>
<Button
data-test-id="clear-permissions-button"
data-testid="clear-permissions-button"
onClick={onClearPermissions}
isDisabled={!grantedPermissions}
>
Expand Down
Loading
Loading