-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Changes from 49 commits
195855f
2d45778
85919a8
34e4a86
fda468e
6ab8122
f77df04
980497c
ee7c48a
a576a24
0c98ebf
b8b9499
36cb863
4c65e0f
06305e1
894715f
6fa8735
285424f
68f1630
47a5422
be601aa
b733eeb
66d99b1
1d75098
e0f5dc7
1e6c8cf
ce8bf2b
c622501
f092de3
9c3a0b6
d5ab204
aab1d7c
c1bc4a7
5ac735f
c92d110
88e759f
65f90d5
e90884f
e5b7819
408f4c1
3d10166
9312712
30b3bd6
eb3ae4c
28bc815
4a7c7f5
d8c1b0c
e791dd4
667b737
119837e
8b32d8b
93ebbdc
22462c1
a2f690e
2e915da
af3df11
2c8d14b
c29098d
030586a
a859400
d9b9d61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
|
@@ -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) | ||
) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this checking through |
||
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( | ||
|
@@ -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, | ||
|
@@ -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, | ||
|
@@ -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( | ||
|
@@ -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' | ||
|
@@ -11,6 +11,7 @@ import { | |
WALLET_CAPABILITIES, | ||
getCapabilitySupportedChainInfo | ||
} from '../../utils/EIP5792Utils' | ||
import { W3mFrameProvider } from '@web3modal/wallet' | ||
|
||
export function EthersSendCallsWithPaymasterServiceTest() { | ||
const [paymasterServiceUrl, setPaymasterServiceUrl] = useState<string>('') | ||
|
@@ -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(', ') | ||
|
@@ -98,6 +112,11 @@ export function EthersSendCallsWithPaymasterServiceTest() { | |
) | ||
} | ||
|
||
// Replace with capability check | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same, is it a todo? Should be replaced with something else? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually a todo yes. Ty There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 🙏 |
||
if (walletProvider instanceof W3mFrameProvider) { | ||
return Boolean(true) | ||
} | ||
|
||
return false | ||
tomiir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
|
@@ -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} | ||
> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it a todo?
There was a problem hiding this comment.
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