Skip to content

Commit

Permalink
Feat/sponsor donut call (#2923)
Browse files Browse the repository at this point in the history
  • Loading branch information
devceline authored Oct 3, 2024
1 parent b949143 commit a649a1c
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
getCapabilitySupportedChainInfo
} from '../../utils/EIP5792Utils'
import { W3mFrameProvider } from '@reown/appkit-wallet'
import { abi, address as donutAddress } from '../../utils/DonutContract'

export function Ethers5SendCallsWithPaymasterServiceTest() {
const [paymasterServiceUrl, setPaymasterServiceUrl] = useState<string>('')
Expand Down Expand Up @@ -54,7 +55,7 @@ export function Ethers5SendCallsWithPaymasterServiceTest() {
const currentChainsInfo = paymasterServiceSupportedChains.find(
chainInfo => chainInfo.chainId === Number(chainId)
)
async function onSendCalls() {
async function onSendCalls(donut?: boolean) {
try {
setLoading(true)
if (!walletProvider || !address) {
Expand All @@ -69,16 +70,27 @@ export function Ethers5SendCallsWithPaymasterServiceTest() {
}
const provider = new ethers.providers.Web3Provider(walletProvider, chainId)
const amountToSend = parseGwei('0.001').toString(16)
const calls = [
{
to: vitalikEthAddress,
value: `0x${amountToSend}`
},
{
to: vitalikEthAddress,
data: '0xdeadbeef'
}
]
const donutIntrerface = new ethers.utils.Interface(abi)
const encodedCallData = donutIntrerface.encodeFunctionData('getBalance', [address])

const calls = donut
? [
{
to: donutAddress,
data: encodedCallData
}
]
: [
{
to: vitalikEthAddress,
value: `0x${amountToSend}`
},
{
to: vitalikEthAddress,
data: '0xdeadbeef'
}
]

const sendCallsParams = {
version: '1.0',
chainId: `0x${BigInt(chainId).toString(16)}`,
Expand Down Expand Up @@ -159,11 +171,19 @@ export function Ethers5SendCallsWithPaymasterServiceTest() {
<Button
width={'fit-content'}
data-testid="send-calls-paymaster-service-button"
onClick={onSendCalls}
onClick={() => onSendCalls()}
isDisabled={isLoading || !paymasterServiceUrl}
>
SendCalls w/ Paymaster Service
</Button>
<Button
width={'fit-content'}
data-testid="send-calls-paymaster-service-button"
onClick={() => onSendCalls(true)}
isDisabled={isLoading || !paymasterServiceUrl}
>
Send Donut Calls w/ Paymaster Service
</Button>
</Stack>
) : (
<Text fontSize="md" color="yellow">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { Button, Stack, Text, Input, Tooltip } from '@chakra-ui/react'
import { Button, Stack, Text, Input, Tooltip, Flex } from '@chakra-ui/react'
import { useState, useEffect } from 'react'
import { useAppKitAccount, useAppKitNetwork, useAppKitProvider } from '@reown/appkit/react'
import { UniversalProvider } from '@walletconnect/universal-provider'
import { useChakraToast } from '../Toast'
import { parseGwei } from 'viem'
import { vitalikEthAddress } from '../../utils/DataUtil'
import { BrowserProvider, type Eip1193Provider } from 'ethers'
import { BrowserProvider, type Eip1193Provider, Interface } from 'ethers'
import {
EIP_5792_RPC_METHODS,
WALLET_CAPABILITIES,
getCapabilitySupportedChainInfo
} from '../../utils/EIP5792Utils'
import { W3mFrameProvider } from '@reown/appkit-wallet'
import { abi, address as donutAddress } from '../../utils/DonutContract'

export function EthersSendCallsWithPaymasterServiceTest() {
const [paymasterServiceUrl, setPaymasterServiceUrl] = useState<string>('')
Expand Down Expand Up @@ -49,7 +50,7 @@ export function EthersSendCallsWithPaymasterServiceTest() {
const currentChainsInfo = paymasterServiceSupportedChains.find(
chainInfo => chainInfo.chainId === Number(chainId)
)
async function onSendCalls() {
async function onSendCalls(donut?: boolean) {
try {
setLoading(true)
if (!walletProvider || !address) {
Expand All @@ -64,16 +65,27 @@ export function EthersSendCallsWithPaymasterServiceTest() {
}
const provider = new BrowserProvider(walletProvider, chainId)
const amountToSend = parseGwei('0.001').toString(16)
const calls = [
{
to: vitalikEthAddress,
value: `0x${amountToSend}`
},
{
to: vitalikEthAddress,
data: '0xdeadbeef'
}
]

const donutIntrerface = new Interface(abi)
const encodedCallData = donutIntrerface.encodeFunctionData('getBalance', [address])

const calls = donut
? [
{
to: donutAddress,
data: encodedCallData
}
]
: [
{
to: vitalikEthAddress,
value: `0x${amountToSend}`
},
{
to: vitalikEthAddress,
data: '0xdeadbeef'
}
]
const sendCallsParams = {
version: '1.0',
chainId: `0x${BigInt(chainId).toString(16)}`,
Expand All @@ -85,6 +97,7 @@ export function EthersSendCallsWithPaymasterServiceTest() {
}
}
}

const batchCallHash = await provider.send(EIP_5792_RPC_METHODS.WALLET_SEND_CALLS, [
sendCallsParams
])
Expand Down Expand Up @@ -151,14 +164,25 @@ export function EthersSendCallsWithPaymasterServiceTest() {
textOverflow="ellipsis"
/>
</Tooltip>
<Button
width={'fit-content'}
data-testid="send-calls-paymaster-service-button"
onClick={onSendCalls}
isDisabled={isLoading || !paymasterServiceUrl}
>
SendCalls w/ Paymaster Service
</Button>
<Flex dir="col">
<Button
width={'fit-content'}
data-testid="send-calls-paymaster-service-button"
onClick={() => onSendCalls()}
isDisabled={isLoading || !paymasterServiceUrl}
>
SendCalls w/ Paymaster Service
</Button>

<Button
width={'fit-content'}
data-testid="send-calls-paymaster-service-button"
onClick={() => onSendCalls(true)}
isDisabled={isLoading || !paymasterServiceUrl}
>
Send Donut Calls w/ Paymaster Service
</Button>
</Flex>
</Stack>
) : (
<Text fontSize="md" color="yellow">
Expand Down

0 comments on commit a649a1c

Please sign in to comment.