Skip to content

Commit

Permalink
Merge pull request #197 from tablelandnetwork/dtb/fix-action-and-wagmi
Browse files Browse the repository at this point in the history
  • Loading branch information
dtbuchholz authored May 9, 2024
2 parents 96d1b2b + 33666c4 commit b8fa975
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/algolia.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
name: Algolia # Reindex site search on Algolia

on:
workflow_dispatch:
push:
branches:
- main

workflow_dispatch:
deployment_status:

jobs:
reindex:
if: github.event.deployment_status.environment == 'production' && github.event.deployment_status.state == 'success'
runs-on: ubuntu-latest
steps:
- name: Reindex Algolia
Expand Down
35 changes: 17 additions & 18 deletions docs/playbooks/frameworks/wagmi.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,26 +261,26 @@ Since wagmi is not natively compatible with ethers, we'll need to create a hook

```js title="src/hooks/useSigner.js"
import { useMemo } from "react";
import { BrowserProvider } from "ethers";
import { useWalletClient } from "wagmi";
import { BrowserProvider, JsonRpcSigner } from "ethers";
import { useConnectorClient } from "wagmi";

function walletClientToSigner(walletClient) {
const { account, chain, transport } = walletClient;
function walletClientToSigner(client) {
const { account, chain, transport } = client;
const network = {
chainId: chain.id,
name: chain.name,
ensAddress: chain.contracts?.ensRegistry?.address,
};
const provider = new BrowserProvider(transport.url, network);
const signer = await provider.getSigner(account.address);
const provider = new BrowserProvider(transport, network);
const signer = new JsonRpcSigner(provider, account.address);
return signer;
}

export function useSigner({ chainId } = {}) {
const { data: walletClient } = useWalletClient({ chainId });
const { data: client } = useConnectorClient({ chainId });
return useMemo(
() => (walletClient ? walletClientToSigner(walletClient) : undefined),
[walletClient]
() => (client ? walletClientToSigner(client) : undefined),
[client]
);
}
```
Expand All @@ -289,28 +289,27 @@ export function useSigner({ chainId } = {}) {
<TabItem value="jsv1" label="wagmi v1">
```js title="src/hooks/useSigner.js"
// Convert wagmi/viem `WalletClient` to ethers `Signer`
import { useMemo } from "react";
import { BrowserProvider } from "ethers";
import { useWalletClient } from "wagmi";
import { BrowserProvider, JsonRpcSigner } from "ethers";
import { useConnectorClient } from "wagmi";

function walletClientToSigner(walletClient) {
const { account, chain, transport } = walletClient;
function walletClientToSigner(client) {
const { account, chain, transport } = client;
const network = {
chainId: chain.id,
name: chain.name,
ensAddress: chain.contracts?.ensRegistry?.address,
};
const provider = new BrowserProvider(transport, network);
const signer = await provider.getSigner(account.address);
const signer = new JsonRpcSigner(provider, account.address);
return signer;
}

export function useSigner({ chainId } = {}) {
const { data: walletClient } = useWalletClient({ chainId });
const { data: client } = useConnectorClient({ chainId });
return useMemo(
() => (walletClient ? walletClientToSigner(walletClient) : undefined),
[walletClient]
() => (client ? walletClientToSigner(client) : undefined),
[client]
);
}
```
Expand Down

0 comments on commit b8fa975

Please sign in to comment.