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 49 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
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,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 @@ -50,6 +50,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 {
// Replace with capability check
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it a todo?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added a proper comment for following prs

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
58 changes: 45 additions & 13 deletions apps/laboratory/src/components/Ethers/EthersSendCallsTest.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
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'

export function EthersSendCallsTest() {
const [loading, setLoading] = useState(false)
Expand All @@ -19,12 +20,28 @@ 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 atomicBatchSupportedChainNames = atomicBatchSupportedChains
const [lastCallsBatchId, setLastCallsBatchId] = useState<string | null>(null)

useEffect(() => {
if (
address &&
(walletProvider instanceof EthereumProvider || walletProvider instanceof W3mFrameProvider)
) {
Copy link
Contributor

Choose a reason for hiding this comment

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

does this checking through instanceof may be problematic through different versions of the @walletconnect/ethereum-provider? We got this issue before

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

const atomicBatchSupportedChainsNames = atomicBatchSupportedChains
.map(ci => ci.chainName)
.join(', ')
const currentChainsInfo = atomicBatchSupportedChains.find(
Expand All @@ -41,12 +58,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 +79,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 +97,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 +134,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 @@ -98,6 +112,11 @@ export function EthersSendCallsWithPaymasterServiceTest() {
)
}

// Replace with capability check
Copy link
Contributor

Choose a reason for hiding this comment

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

Same, is it a todo? Should be replaced with something else?

Copy link
Contributor

Choose a reason for hiding this comment

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

If it requires more polishing or would be handled in another PR etc, would it be better to give more context to devs?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually a todo yes. Ty

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually there's a typing issue. I'll change this in a different PR 🙏
Would like to get this merged

if (walletProvider instanceof W3mFrameProvider) {
return Boolean(true)
}

return false
tomiir marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down Expand Up @@ -137,7 +156,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 @@ -46,7 +46,7 @@ export function EthersTransactionTest() {
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 @@ -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 @@ -144,15 +144,15 @@ 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}
>
Sign and Send Transaction
</Button>
{supportV0Transactions ? (
<Button
data-test-id="sign-transaction-button"
data-testid="sign-transaction-button"
onClick={onSendVersionedTransaction}
isDisabled={loading}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ 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}
>
Sign Transaction
</Button>
{supportV0Transactions ? (
<Button
data-test-id="sign-transaction-button"
data-testid="sign-transaction-button"
onClick={onSignVersionedTransaction}
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