Skip to content

Commit 4420166

Browse files
authored
Merge pull request #238 from liteflow-labs/feature/replace-ethers-viem
Replace ethers Signer by viem
2 parents 7565354 + 2e83677 commit 4420166

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+10082
-13702
lines changed

.changeset/dirty-houses-shake.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@liteflow/react': major
3+
'@liteflow/core': major
4+
---
5+
6+
Replace Ethers.js by Viem

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
example
2+
**/dist

docs/pages/tools/sdk-react/index.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,19 @@ To authenticate your user you will need to have access to the `Signer` of their
3232

3333
```tsx
3434
import { useAuthenticate, useIsLoggedIn } from '@liteflow/react'
35-
import { useAccount, useSigner } from 'wagmi' // or your favorite web3 wallet
35+
import { useMemo } from 'react'
36+
import { publicActions } from 'viem'
37+
import { useWalletClient } from 'wagmi'
3638

3739
function Login() {
3840
const { address } = useAccount()
39-
const { data: signer } = useSigner()
41+
const { data: walletClient } = useWalletClient()
42+
const signer = useMemo(() => {
43+
return walletClient?.extend(publicActions)
44+
}, [walletClient])
45+
4046
const [authenticate, { resetAuthenticationToken }] = useAuthenticate()
41-
const loggedIn = useIsLoggedIn(address)
47+
const loggedIn = useIsLoggedIn(walletClient?.account.address)
4248

4349
if (!signer) return 'No wallet connected'
4450
if (loggedIn)
@@ -52,12 +58,18 @@ function Login() {
5258
Every component inside the `LiteflowProvider` is now set up to use the Liteflow hooks.
5359

5460
```tsx
61+
import { BigNumber } from '@ethersproject/bignumber'
5562
import { useCreateOffer } from '@liteflow/react'
56-
import { BigNumber } from 'ethers'
57-
import { useSigner } from 'wagmi' // or your favorite web3 wallet
63+
import { useMemo } from 'react'
64+
import { publicActions } from 'viem'
65+
import { useWalletClient } from 'wagmi'
5866

5967
function PlaceBid() {
60-
const { data: signer } = useSigner()
68+
const { data: walletClient } = useWalletClient()
69+
const signer = useMemo(() => {
70+
return walletClient?.extend(publicActions)
71+
}, [walletClient])
72+
6173
const [createOffer] = useCreateOffer(signer)
6274

6375
const handleClick = async () => {

docs/pages/tools/sdk-react/useAcceptOffer.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,16 @@ Can only be executed by an owner of the related NFT if it's a bid, or by anyone
1313
```tsx
1414
import { BigNumber } from '@ethersproject/bignumber'
1515
import { AcceptOfferStep, useAcceptOffer } from '@liteflow/react'
16+
import { useMemo } from 'react'
17+
import { publicActions } from 'viem'
18+
import { useWalletClient } from 'wagmi'
1619

1720
export default function Component() {
18-
const signer = undefined // type of "Signer & TypedDataSigner" Get the signer from the wallet. Need to be an Ethers Signer (https://docs.ethers.io/v5/api/signer/)
21+
const { data: walletClient } = useWalletClient()
22+
const signer = useMemo(() => {
23+
return walletClient?.extend(publicActions)
24+
}, [walletClient])
25+
1926
const [acceptOffer, { activeStep, transactionHash }] = useAcceptOffer(signer)
2027

2128
const handleClick = async () => {

docs/pages/tools/sdk-react/useAuthenticate.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@ Hook to authenticate a web3 wallet against the API. It returns a token that need
1010

1111
```tsx
1212
import { useAuthenticate } from '@liteflow/react'
13+
import { useMemo } from 'react'
14+
import { publicActions } from 'viem'
15+
import { useWalletClient } from 'wagmi'
1316

1417
export default function Component() {
15-
const signer = undefined // type of "Signer & TypedDataSigner" Get the signer from the wallet. Need to be an Ethers Signer (https://docs.ethers.io/v5/api/signer/)
18+
const { data: walletClient } = useWalletClient()
19+
const signer = useMemo(() => {
20+
return walletClient?.extend(publicActions)
21+
}, [walletClient])
22+
1623
const [authenticate, { loading }] = useAuthenticate()
1724

1825
const handleClick = async () => {

docs/pages/tools/sdk-react/useBatchPurchase.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,16 @@ Hook to accept multiple offers, accessing the active process step as well as the
1212
```tsx
1313
import { BigNumber } from '@ethersproject/bignumber'
1414
import { BatchPurchaseStep, useBatchPurchase } from '@liteflow/react'
15+
import { useMemo } from 'react'
16+
import { publicActions } from 'viem'
17+
import { useWalletClient } from 'wagmi'
1518

1619
export default function Component() {
17-
const signer = undefined // type of "Signer & TypedDataSigner" Get the signer from the wallet. Need to be an Ethers Signer (https://docs.ethers.io/v5/api/signer/)
20+
const { data: walletClient } = useWalletClient()
21+
const signer = useMemo(() => {
22+
return walletClient?.extend(publicActions)
23+
}, [walletClient])
24+
1825
const [batchPurchase, { activeStep, transactionHash }] =
1926
useBatchPurchase(signer)
2027

docs/pages/tools/sdk-react/useCancelOffer.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@ Hook to cancel an offer, accessing the active process step as well as the transa
1010

1111
```tsx
1212
import { CancelOfferStep, useCancelOffer } from '@liteflow/react'
13+
import { useMemo } from 'react'
14+
import { publicActions } from 'viem'
15+
import { useWalletClient } from 'wagmi'
1316

1417
export default function Component() {
15-
const signer = undefined // type of "Signer & TypedDataSigner" Get the signer from the wallet. Need to be an Ethers Signer (https://docs.ethers.io/v5/api/signer/)
18+
const { data: walletClient } = useWalletClient()
19+
const signer = useMemo(() => {
20+
return walletClient?.extend(publicActions)
21+
}, [walletClient])
22+
1623
const [cancelOffer, { activeStep, transactionHash }] = useCancelOffer(signer)
1724

1825
const handleClick = async () => {

docs/pages/tools/sdk-react/useCreateNFT.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@ Hook for creating an NFT, accessing the active process step as well as the trans
1010

1111
```tsx
1212
import { CreateNftStep, useCreateNFT } from '@liteflow/react'
13+
import { useMemo } from 'react'
14+
import { publicActions } from 'viem'
15+
import { useWalletClient } from 'wagmi'
1316

1417
export default function Component() {
15-
const signer = undefined // type of "Signer & TypedDataSigner" Get the signer from the wallet. Need to be an Ethers Signer (https://docs.ethers.io/v5/api/signer/)
18+
const { data: walletClient } = useWalletClient()
19+
const signer = useMemo(() => {
20+
return walletClient?.extend(publicActions)
21+
}, [walletClient])
22+
1623
const [createNFT, { activeStep, transactionHash }] = useCreateNFT(signer, {
1724
uploadUrl: 'Your liteflow upload URL',
1825
})

docs/pages/tools/sdk-react/useCreateOffer.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,18 @@ Hook for creating an offer, accessing the active process step as well as the tra
99
## Usage
1010

1111
```tsx
12+
import { BigNumber } from '@ethersproject/bignumber'
1213
import { CreateOfferStep, useCreateOffer } from '@liteflow/react'
13-
import { BigNumber } from 'ethers'
14+
import { useMemo } from 'react'
15+
import { publicActions } from 'viem'
16+
import { useWalletClient } from 'wagmi'
1417

1518
export default function Component() {
16-
const signer = undefined // type of "Signer & TypedDataSigner" Get the signer from the wallet. Need to be an Ethers Signer (https://docs.ethers.io/v5/api/signer/)
19+
const { data: walletClient } = useWalletClient()
20+
const signer = useMemo(() => {
21+
return walletClient?.extend(publicActions)
22+
}, [walletClient])
23+
1724
const [createOffer, { activeStep, transactionHash }] = useCreateOffer(signer)
1825

1926
const handleClick = async () => {

docs/pages/tools/sdk-react/useMintDrop.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@ Hook for minting a drop, accessing the active process step as well as the transa
1010

1111
```tsx
1212
import { MintDropStep, useMintDrop } from '@liteflow/react'
13+
import { useMemo } from 'react'
14+
import { publicActions } from 'viem'
15+
import { useWalletClient } from 'wagmi'
1316

1417
export default function Component() {
15-
const signer = undefined // type of "Signer & TypedDataSigner" Get the signer from the wallet. Need to be an Ethers Signer (https://docs.ethers.io/v5/api/signer/)
18+
const { data: walletClient } = useWalletClient()
19+
const signer = useMemo(() => {
20+
return walletClient?.extend(publicActions)
21+
}, [walletClient])
22+
1623
const [mintDrop, { activeStep, transactionHash }] = useMintDrop(signer)
1724

1825
const handleClick = async () => {

0 commit comments

Comments
 (0)