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: wagmi v2 #1588

Merged
merged 53 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
f31e182
feat: kickoff. clone wagmi package
tomiir Dec 18, 2023
3638b29
feat: first refactor of client and defaultWagmiConfig. No connectors yet
tomiir Dec 19, 2023
dc0ba8c
feat: client compiles without Email and 6963 connectors
tomiir Dec 19, 2023
2cb19e4
feat: added email connector. package compiles without eip6963
tomiir Dec 19, 2023
1dc61f7
fix: loose wagmi connector dependency
tomiir Dec 19, 2023
d0765ee
fix: typing issues in client
tomiir Dec 19, 2023
8764a52
fix: syncAccount
tomiir Dec 19, 2023
d79344c
feat: rename wagmi -> wagmi1
tomiir Dec 20, 2023
09f024d
feat: rename wagmi-v2 -> wagmi
tomiir Dec 20, 2023
bf454b9
chore: made wagmi.tsx use wagmiv2
tomiir Dec 20, 2023
867b320
feat: fix wagmi siwe and email in lab
tomiir Dec 20, 2023
ec64d51
fix: WC connector integration
tomiir Dec 20, 2023
e1c73fd
fix: WagmiConnect Button
tomiir Dec 20, 2023
ae5cbf0
chore: update to latest v of wagmi and viem
tomiir Dec 20, 2023
f11425a
fix: email connector not recognized
tomiir Dec 20, 2023
b83aa15
fix: data serialization for connectors
tomiir Dec 20, 2023
7de429f
fix: scaffold eip6963 discovery with wagmiv2
tomiir Dec 20, 2023
a20825a
fix: issue with coinbase icon
tomiir Dec 20, 2023
f198e10
chore: rename EmailConnectorV2. Remove unused commented code
tomiir Dec 20, 2023
c5e748b
chore: remove WC transport
tomiir Dec 20, 2023
4b97788
fix: conflicts after rebase
tomiir Dec 20, 2023
5d6ba98
fix: remove log
tomiir Dec 20, 2023
c296c31
fix: sync lock after rebase
tomiir Dec 20, 2023
75faf2d
fix: loose dependency in laboratory
tomiir Dec 20, 2023
f4527c4
fix: update tanstack
tomiir Dec 20, 2023
698212c
fix: wagmi dependencies. coinbase connector duplication
tomiir Dec 21, 2023
c936225
chore: improve provider setting in emailConnector
tomiir Dec 22, 2023
8e45879
chore: move dependencies to peerDependencies
tomiir Dec 22, 2023
1a8dcb9
fix: update versioning, typing and package imports on wagmi1
tomiir Jan 4, 2024
9b4765a
fix: useNetwork migration to wagmiv2 in lab
tomiir Jan 4, 2024
2b7bf27
fix: coinbase name mapping. installed tag and duplicate filtering
tomiir Jan 4, 2024
95f4491
fix: react and vue examples
tomiir Jan 4, 2024
a2e3277
fix: lock after rebase
tomiir Jan 11, 2024
b3e83c7
fix: add tanstack provider to all screens in wagmi lab
tomiir Jan 11, 2024
70e8803
fix: apply wagmiv2 changes to new lab refactor
tomiir Jan 11, 2024
eea1786
fix: insufficient funds error
tomiir Jan 11, 2024
94ecc79
fix: laboratory siwe and wagmi provider and verify url
tomiir Jan 11, 2024
5855f6d
fix: approved caip networks on wagmi2
tomiir Jan 12, 2024
eb2e4d8
Merge branch 'V4' into feat/wagmi-v2
tomiir Jan 15, 2024
9282980
fix: broken siwe optional deps versions and update to latest official…
tomiir Jan 15, 2024
8a003af
fix: write contract test for wagmi v2
tomiir Jan 15, 2024
ca37609
fix: update lerna with wagmi1 and removed comments from tsconfig
tomiir Jan 15, 2024
85ad39c
chore: use constants instead of string literals
tomiir Jan 15, 2024
4439c31
fix: remove gas literals from wagmi send transaction
tomiir Jan 15, 2024
a10eccb
chore: update tx amount
tomiir Jan 16, 2024
6d65264
chore: rebuild lock
tomiir Jan 16, 2024
544a28f
fix: remove log
tomiir Jan 16, 2024
ef98452
chore: bump versions
tomiir Jan 16, 2024
650431d
fix: chains typing in wagmi
tomiir Jan 17, 2024
7257c7d
chore: update types on wagmi v2 to allow users to pass in extra param…
tomiir Jan 17, 2024
2e56a70
chore: bump version to 4.0.0-alpha.1
tomiir Jan 17, 2024
9fd4d77
Merge branch 'V4' into feat/wagmi-v2
tomiir Jan 17, 2024
832dcdc
fix: version to alpha.0
tomiir Jan 17, 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: 3 additions & 3 deletions apps/gallery/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@apps/gallery",
"version": "3.6.0-1f872ccc",
"version": "4.0.0-alpha.0",
"private": true,
"main": "index.js",
"scripts": {
Expand All @@ -9,8 +9,8 @@
"lint": "eslint . --ext .js,.jsx,.ts,.tsx"
},
"dependencies": {
"@web3modal/common": "3.6.0-1f872ccc",
"@web3modal/ui": "3.6.0-1f872ccc",
"@web3modal/common": "4.0.0-alpha.0",
"@web3modal/ui": "4.0.0-alpha.0",
"lit": "3.1.0",
"storybook": "7.6.7"
},
Expand Down
13 changes: 8 additions & 5 deletions apps/laboratory/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@apps/laboratory",
"version": "3.6.0-1f872ccc",
"version": "4.0.0-alpha.0",
"private": true,
"scripts": {
"dev:laboratory": "next dev",
Expand All @@ -19,15 +19,18 @@
"@emotion/styled": "11.11.0",
"@sentry/browser": "7.92.0",
"@sentry/react": "7.92.0",
"@web3modal/ethers": "3.6.0-1f872ccc",
"@web3modal/ethers5": "3.6.0-1f872ccc",
"@web3modal/wagmi": "3.6.0-1f872ccc",
"@tanstack/react-query": "5.14.1",
"@web3modal/ethers": "4.0.0-alpha.0",
"@web3modal/ethers5": "4.0.0-alpha.0",
"@web3modal/wagmi": "4.0.0-alpha.0",
"framer-motion": "10.17.9",
"next": "14.0.4",
"next-auth": "4.24.5",
"react-icons": "4.12.0",
"siwe": "2.1.4",
"valtio": "1.11.2"
"valtio": "1.11.2",
"viem": "2.0.10",
"wagmi": "2.2.1"
},
"devDependencies": {
"@mailsac/api": "1.0.5",
Expand Down
4 changes: 2 additions & 2 deletions apps/laboratory/src/components/Wagmi/WagmiSignMessageTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { ConstantsUtil } from '../../utils/ConstantsUtil'

export function WagmiSignMessageTest() {
const toast = useToast()
const { signMessageAsync } = useSignMessage({ message: 'Hello Web3Modal!' })
const { signMessageAsync } = useSignMessage()

async function onSignMessage() {
try {
const signature = await signMessageAsync()
const signature = await signMessageAsync({ message: 'Hello Web3Modal!' })
toast({
title: ConstantsUtil.SigningSucceededToastTitle,
description: signature,
Expand Down
11 changes: 3 additions & 8 deletions apps/laboratory/src/components/Wagmi/WagmiSignTypedDataTest.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, useToast } from '@chakra-ui/react'
import { useNetwork, useSignTypedData } from 'wagmi'
import { useAccount, useSignTypedData } from 'wagmi'

// Example data
const types = {
Expand Down Expand Up @@ -28,20 +28,15 @@ const message = {

export function WagmiSignTypedDataTest() {
const toast = useToast()
const { chain } = useNetwork()
const { chain } = useAccount()
const domain = {
name: 'Ether Mail',
version: '1',
chainId: chain?.id,
verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC'
} as const

const { signTypedDataAsync } = useSignTypedData({
domain,
message,
primaryType: 'Mail',
types
})
const { signTypedDataAsync } = useSignTypedData()

async function onSignTypedData() {
try {
Expand Down
70 changes: 38 additions & 32 deletions apps/laboratory/src/components/Wagmi/WagmiTransactionTest.tsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,59 @@
import { Button, useToast, Stack, Link, Text, Spacer } from '@chakra-ui/react'
import { parseEther, parseGwei } from 'viem'
import { usePrepareSendTransaction, useSendTransaction, useNetwork, useAccount } from 'wagmi'
import { parseGwei, type Address } from 'viem'
import { useEstimateGas, useSendTransaction, useAccount } from 'wagmi'
import { vitalikEthAddress } from '../../utils/DataUtil'
import { useCallback, useEffect } from 'react'
import { useCallback, useState } from 'react'
import { sepolia } from 'wagmi/chains'

const TEST_TX = {
to: vitalikEthAddress as Address,
value: parseGwei('0.0002')
}

export function WagmiTransactionTest() {
const toast = useToast()
const { chain } = useNetwork()
const { status } = useAccount()
const { config, error: prepareError } = usePrepareSendTransaction({
to: vitalikEthAddress,
value: parseEther('0.0001'),
maxFeePerGas: parseGwei('200'),
maxPriorityFeePerGas: parseGwei('200')
const { status, chain } = useAccount()
const { data: gas, error: prepareError } = useEstimateGas(TEST_TX)
const [isLoading, setLoading] = useState(false)
const { sendTransaction } = useSendTransaction({
mutation: {
onSuccess: hash => {
setLoading(false)
toast({
title: 'Transaction Success',
description: hash,
status: 'success',
isClosable: true
})
},
onError: () => {
setLoading(false)
toast({
title: 'Error',
description: 'Failed to send transaction',
status: 'error',
isClosable: true
})
}
}
})
const { sendTransaction, data, error, reset, isLoading } = useSendTransaction(config)

const onSendTransaction = useCallback(() => {
if (prepareError) {
toast({
title: 'Error',
description: 'Not enough funds to send transaction',
description: 'Not enough funds for transaction',
status: 'error',
isClosable: true
})
} else {
sendTransaction?.()
}
}, [sendTransaction, prepareError])

useEffect(() => {
if (data) {
toast({
title: 'Transaction Success',
description: data.hash,
status: 'success',
isClosable: true
})
} else if (error) {
toast({
title: 'Error',
description: 'Failed to send transaction',
status: 'error',
isClosable: true
setLoading(true)
sendTransaction({
...TEST_TX,
gas
})
}
reset()
}, [data, error])
}, [sendTransaction, prepareError])

return chain?.id === sepolia.id && status === 'connected' ? (
<Stack direction={['column', 'column', 'row']}>
Expand Down
35 changes: 14 additions & 21 deletions apps/laboratory/src/components/Wagmi/WagmiWriteContractTest.tsx
Original file line number Diff line number Diff line change
@@ -1,58 +1,51 @@
import { Button, useToast, Stack, Link, Text, Spacer, Flex } from '@chakra-ui/react'
import { parseEther } from 'viem'
import {
useContractWrite,
useNetwork,
useAccount,
usePrepareContractWrite,
useContractRead
} from 'wagmi'
import { useAccount, useSimulateContract, useWriteContract, useReadContract } from 'wagmi'
import { useCallback, useEffect } from 'react'
import { sepolia } from 'wagmi/chains'
import { abi, address } from '../../utils/DonutContract'

export function WagmiWriteContractTest() {
const toast = useToast()
const { chain } = useNetwork()
const { status } = useAccount()
const { status, chain } = useAccount()
const {
data: donutsOwned,
refetch: fetchDonutsOwned,
isLoading: donutsQueryLoading,
isRefetching: donutsQueryRefetching
} = useContractRead({
} = useReadContract({
abi,
address,
functionName: 'getBalance'
})
const { config, error: prepareError } = usePrepareContractWrite({
const { data: simulateData, error: simulateError } = useSimulateContract({
abi,
address,
functionName: 'purchase',
value: parseEther('0.0003'),
args: [1]
})
const { error, data, isLoading, write, reset } = useContractWrite(config)
const { writeContract, reset, data, error, isPending } = useWriteContract()

const onSendTransaction = useCallback(async () => {
if (prepareError) {
if (simulateError || !simulateData?.request) {
toast({
title: 'Error',
description: 'Not enough funds to purchase donut',
description: 'Not able to execute this transaction. Check your balance.',
status: 'error',
isClosable: true
})
} else {
write?.()
writeContract(simulateData?.request)
await fetchDonutsOwned()
}
}, [write, prepareError])
}, [writeContract, simulateError, simulateData?.request])

useEffect(() => {
if (data) {
toast({
title: 'Donut Purchase Success!',
description: data.hash,
description: data,
status: 'success',
isClosable: true
})
Expand All @@ -72,8 +65,8 @@ export function WagmiWriteContractTest() {
<Button
data-test-id="sign-transaction-button"
onClick={onSendTransaction}
disabled={!write}
isDisabled={isLoading}
disabled={!simulateData?.request}
isDisabled={isPending}
>
Purchase crypto donut
</Button>
Expand All @@ -88,13 +81,13 @@ export function WagmiWriteContractTest() {
<Spacer />

<Link isExternal href="https://sepoliafaucet.com">
<Button variant="outline" colorScheme="blue" isDisabled={isLoading}>
<Button variant="outline" colorScheme="blue" isDisabled={isPending}>
Sepolia Faucet 1
</Button>
</Link>

<Link isExternal href="https://www.infura.io/faucet/sepolia">
<Button variant="outline" colorScheme="orange" isDisabled={isLoading}>
<Button variant="outline" colorScheme="orange" isDisabled={isPending}>
Sepolia Faucet 2
</Button>
</Link>
Expand Down
15 changes: 10 additions & 5 deletions apps/laboratory/src/pages/library/wagmi-email.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { createWeb3Modal, defaultWagmiConfig } from '@web3modal/wagmi/react'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { useEffect, useState } from 'react'
import { WagmiConfig } from 'wagmi'
import { WagmiProvider } from 'wagmi'
import { Web3ModalButtons } from '../../components/Web3ModalButtons'
import { WagmiTests } from '../../components/Wagmi/WagmiTests'
import { ThemeStore } from '../../utils/StoreUtil'
import { WagmiConstantsUtil } from '../../utils/WagmiConstants'
import { ConstantsUtil } from '../../utils/ConstantsUtil'

const queryClient = new QueryClient()

export const wagmiConfig = defaultWagmiConfig({
chains: WagmiConstantsUtil.chains,
projectId: ConstantsUtil.ProjectId,
Expand Down Expand Up @@ -34,9 +37,11 @@ export default function Wagmi() {
}, [])

return ready ? (
<WagmiConfig config={wagmiConfig}>
<Web3ModalButtons />
<WagmiTests />
</WagmiConfig>
<WagmiProvider config={wagmiConfig}>
<QueryClientProvider client={queryClient}>
<Web3ModalButtons />
<WagmiTests />
</QueryClientProvider>
</WagmiProvider>
) : null
}
17 changes: 11 additions & 6 deletions apps/laboratory/src/pages/library/wagmi-siwe.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createWeb3Modal, defaultWagmiConfig } from '@web3modal/wagmi/react'
import { WagmiConfig } from 'wagmi'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { WagmiProvider } from 'wagmi'
import { Web3ModalButtons } from '../../components/Web3ModalButtons'
import { WagmiTests } from '../../components/Wagmi/WagmiTests'
import { ThemeStore } from '../../utils/StoreUtil'
Expand All @@ -8,6 +9,8 @@ import { SiweData } from '../../components/Siwe/SiweData'
import { ConstantsUtil } from '../../utils/ConstantsUtil'
import { siweConfig } from '../../utils/SiweUtils'

const queryClient = new QueryClient()

export const wagmiConfig = defaultWagmiConfig({
chains: WagmiConstantsUtil.chains,
projectId: ConstantsUtil.ProjectId,
Expand All @@ -27,10 +30,12 @@ ThemeStore.setModal(modal)

export default function Wagmi() {
return (
<WagmiConfig config={wagmiConfig}>
<Web3ModalButtons />
<SiweData />
<WagmiTests />
</WagmiConfig>
<WagmiProvider config={wagmiConfig}>
<QueryClientProvider client={queryClient}>
<Web3ModalButtons />
<SiweData />
<WagmiTests />
</QueryClientProvider>
</WagmiProvider>
)
}
15 changes: 10 additions & 5 deletions apps/laboratory/src/pages/library/wagmi.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { createWeb3Modal, defaultWagmiConfig } from '@web3modal/wagmi/react'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { useEffect, useState } from 'react'
import { WagmiConfig } from 'wagmi'
import { WagmiProvider } from 'wagmi'
import { Web3ModalButtons } from '../../components/Web3ModalButtons'
import { WagmiTests } from '../../components/Wagmi/WagmiTests'
import { ThemeStore } from '../../utils/StoreUtil'
import { WagmiConstantsUtil } from '../../utils/WagmiConstants'
import { ConstantsUtil } from '../../utils/ConstantsUtil'

const queryClient = new QueryClient()

export const wagmiConfig = defaultWagmiConfig({
chains: WagmiConstantsUtil.chains,
projectId: ConstantsUtil.ProjectId,
Expand Down Expand Up @@ -43,9 +46,11 @@ export default function Wagmi() {
}, [])

return ready ? (
<WagmiConfig config={wagmiConfig}>
<Web3ModalButtons />
<WagmiTests />
</WagmiConfig>
<WagmiProvider config={wagmiConfig}>
<QueryClientProvider client={queryClient}>
<Web3ModalButtons />
<WagmiTests />
</QueryClientProvider>
</WagmiProvider>
) : null
}
3 changes: 2 additions & 1 deletion apps/laboratory/src/utils/ConstantsUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export const ConstantsUtil = {
name: 'Web3Modal',
description: 'Web3Modal Laboratory',
url: 'https://web3modal.com',
icons: ['https://avatars.githubusercontent.com/u/37784886']
icons: ['https://avatars.githubusercontent.com/u/37784886'],
verifyUrl: ''
},
ProjectId: projectId
}
Loading