-
-
Notifications
You must be signed in to change notification settings - Fork 603
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: decorate clients with actions (#77)
* feat: fall back to getLogs if filters are not supported * Update src/actions/public/watchContractEvent.test.ts Co-authored-by: awkweb <tom@meagher.co> * pr review * feat: decode event log topics & data * wip: public * wip: add ens * docs: public actions * wip: wallet actions * docs: wallet actions * wip: test actions * wip: add utils to main entrypoint * tests: add tests * playgrounds: update * chore: changeset * test * refactor: wire up decorator generics * fix conflicts * format --------- Co-authored-by: awkweb <tom@meagher.co>
- Loading branch information
Showing
171 changed files
with
2,256 additions
and
1,099 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
"viem": patch | ||
--- | ||
|
||
Decorated Clients with their respective Actions. | ||
|
||
Example: | ||
|
||
```diff | ||
import { createPublicClient, http } from 'viem' | ||
import { mainnet } from 'viem/chains' | ||
-import { getBlockNumber } from 'viem/public' | ||
|
||
const client = createPublicClient({ | ||
chain: mainnet, | ||
transport: http(), | ||
}) | ||
|
||
- const blockNumber = await getBlockNumber(client) | ||
+ const blockNumber = await client.getBlockNumber() | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
playgrounds/browser/src/components/actions/RequestAccountAddresses.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
playgrounds/browser/src/components/actions/RequestPermissions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 3 additions & 4 deletions
7
playgrounds/browser/src/components/actions/SendTransaction.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
playgrounds/browser/src/components/actions/WatchBlockNumber.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 10 additions & 11 deletions
21
playgrounds/browser/src/components/actions/WatchPendingTransactions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,25 @@ | ||
import { useEffect, useState } from 'react'; | ||
import type { PublicClient } from 'viem'; | ||
import type { OnTransactionsResponse } from 'viem/public'; | ||
import { watchPendingTransactions } from 'viem/public'; | ||
import { useEffect, useState } from 'react' | ||
import type { PublicClient } from 'viem' | ||
import type { OnTransactionsResponse } from 'viem/public' | ||
|
||
export function WatchPendingTransactions({ client }: { client: PublicClient }) { | ||
const [transactions, setTransactions] = useState<OnTransactionsResponse>([]); | ||
const [transactions, setTransactions] = useState<OnTransactionsResponse>([]) | ||
useEffect(() => { | ||
try { | ||
const unwatch = watchPendingTransactions(client, { | ||
const unwatch = client.watchPendingTransactions({ | ||
onError: (err) => console.log(client.transport.url), | ||
onTransactions: setTransactions, | ||
}); | ||
return unwatch; | ||
}) | ||
return unwatch | ||
} catch (err) { | ||
console.log(err); | ||
console.log(err) | ||
} | ||
}, [client]); | ||
}, [client]) | ||
return ( | ||
<div style={{ maxHeight: 300, overflow: 'scroll' }}> | ||
{transactions.map((hash, i) => ( | ||
<div key={i}>{hash}</div> | ||
))} | ||
</div> | ||
); | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
d6a29f5
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.
Successfully deployed to the following URLs:
viem-site – ./site
viem-site-wagmi-dev.vercel.app
viem-site-git-main-wagmi-dev.vercel.app
viem-site.vercel.app
d6a29f5
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.
Successfully deployed to the following URLs:
viem-playground – ./playgrounds/browser
viem-playground-wagmi-dev.vercel.app
viem-playground-git-main-wagmi-dev.vercel.app
viem-playground.vercel.app