Skip to content

Commit

Permalink
refactor: remove viem/actions entrypoint; add viem/public, viem/walle…
Browse files Browse the repository at this point in the history
…t, viem/test
  • Loading branch information
jxom committed Feb 2, 2023
1 parent 878a037 commit a74d643
Show file tree
Hide file tree
Showing 119 changed files with 319 additions and 163 deletions.
5 changes: 5 additions & 0 deletions .changeset/cyan-berries-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

**Breaking**: Removed the `viem/actions` export in favor of `viem/public`, `viem/test` & `viem/wallet` exports.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ bench
actions/**
chains/**
clients/**
public/**
test/**
utils/**
wallet/**
window/**
20 changes: 15 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
"module": "./dist/index.mjs",
"default": "./dist/index.js"
},
"./actions": {
"types": "./dist/actions/index.d.ts",
"module": "./dist/actions/index.mjs",
"default": "./dist/actions/index.js"
},
"./chains": {
"types": "./dist/chains.d.ts",
"module": "./dist/chains.mjs",
Expand All @@ -57,11 +52,26 @@
"module": "./dist/clients/index.mjs",
"default": "./dist/clients/index.js"
},
"./public": {
"types": "./dist/public.d.ts",
"module": "./dist/public.mjs",
"default": "./dist/public.js"
},
"./test": {
"types": "./dist/test.d.ts",
"module": "./dist/test.mjs",
"default": "./dist/test.js"
},
"./utils": {
"types": "./dist/utils/index.d.ts",
"module": "./dist/utils/index.mjs",
"default": "./dist/utils/index.js"
},
"./wallet": {
"types": "./dist/wallet.d.ts",
"module": "./dist/wallet.mjs",
"default": "./dist/wallet.js"
},
"./window": {
"types": "./dist/window.d.ts",
"module": "./dist/window.mjs",
Expand Down
5 changes: 3 additions & 2 deletions playgrounds/benchmark/suite.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { ethers, providers } from 'ethers'
import {
createClient,
getBalance,
getBlock,
getBlockNumber,
getTransaction,
getTransactionReceipt,
http,
sendTransaction,
} from 'viem/actions'
import { createClient, http } from 'viem/clients'
} from 'viem'
import { mainnet } from 'viem/chains'
import { formatBlock, parseEther } from 'viem/utils'
import type { RpcBlock } from 'viem'
Expand Down
4 changes: 2 additions & 2 deletions playgrounds/dev/components/actions/AddChain.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { addChain } from 'viem/actions'
import type { WalletClient } from 'viem/clients'
import type { WalletClient } from 'viem'
import { celo } from 'viem/chains'
import { addChain } from 'viem/wallet'

export function AddChain({ client }: { client: WalletClient }) {
return (
Expand Down
2 changes: 1 addition & 1 deletion playgrounds/dev/components/actions/GetBalance.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react'
import { getBalance } from 'viem/actions'
import type { PublicClient } from 'viem/clients'
import { getBalance } from 'viem/public'

export function GetBalance({
address = '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
Expand Down
6 changes: 3 additions & 3 deletions playgrounds/dev/components/actions/GetBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from 'react'
import type { GetBlockResponse } from 'viem/actions'
import { getBlock } from 'viem/actions'
import type { PublicClient } from 'viem/clients'
import type { PublicClient } from 'viem'
import type { GetBlockResponse } from 'viem/public'
import { getBlock } from 'viem/public'

export function GetBlock({ client }: { client: PublicClient }) {
const [latestBlock, setLatestBlock] = useState<GetBlockResponse>()
Expand Down
6 changes: 3 additions & 3 deletions playgrounds/dev/components/actions/GetBlockNumber.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from 'react'
import type { GetBlockNumberResponse } from 'viem/actions'
import { getBlockNumber } from 'viem/actions'
import type { PublicClient } from 'viem/clients'
import type { PublicClient } from 'viem'
import type { GetBlockNumberResponse } from 'viem/public'
import { getBlockNumber } from 'viem/public'

export function GetBlockNumber({ client }: { client: PublicClient }) {
const [blockNumber, setBlockNumber] = useState<GetBlockNumberResponse>()
Expand Down
4 changes: 2 additions & 2 deletions playgrounds/dev/components/actions/GetPermissions.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getPermissions } from 'viem/actions'
import type { WalletClient } from 'viem/clients'
import type { WalletClient } from 'viem'
import { getPermissions } from 'viem/wallet'

export function GetPermissions({ client }: { client: WalletClient }) {
return (
Expand Down
6 changes: 3 additions & 3 deletions playgrounds/dev/components/actions/GetTransaction.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from 'react'
import type { GetTransactionArgs, GetTransactionResponse } from 'viem/actions'
import { getTransaction } from 'viem/actions'
import type { PublicClient } from 'viem/clients'
import type { PublicClient } from 'viem'
import type { GetTransactionArgs, GetTransactionResponse } from 'viem/public'
import { getTransaction } from 'viem/public'
import type { Address } from 'viem'

export function GetTransaction({ client }: { client: PublicClient }) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from 'react'
import { requestAccounts } from 'viem/actions'
import type { WalletClient } from 'viem/clients'
import type { WalletClient } from 'viem'
import { requestAccounts } from 'viem/wallet'

export function RequestAccountAddresses({ client }: { client: WalletClient }) {
const [addresses, setAddresses] = useState<`0x${string}`[]>()
Expand Down
4 changes: 2 additions & 2 deletions playgrounds/dev/components/actions/RequestPermissions.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { requestPermissions } from 'viem/actions'
import type { WalletClient } from 'viem/clients'
import type { WalletClient } from 'viem'
import { requestPermissions } from 'viem/wallet'

export function RequestPermissions({ client }: { client: WalletClient }) {
return (
Expand Down
6 changes: 3 additions & 3 deletions playgrounds/dev/components/actions/SendTransaction.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { sendTransaction } from 'viem/actions'
import type { WalletClient } from 'viem/clients'
import { parseEther } from 'viem/utils'
import type { WalletClient } from 'viem'
import { parseEther } from 'viem'
import { sendTransaction } from 'viem/wallet'

export function SendTransaction({ client }: { client: WalletClient }) {
return (
Expand Down
4 changes: 2 additions & 2 deletions playgrounds/dev/components/actions/SwitchChain.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { switchChain } from 'viem/actions'
import type { WalletClient } from 'viem/clients'
import type { WalletClient } from 'viem'
import { mainnet } from 'viem/chains'
import { switchChain } from 'viem/wallet'

export function SwitchChain({ client }: { client: WalletClient }) {
return (
Expand Down
6 changes: 3 additions & 3 deletions playgrounds/dev/components/actions/WatchBlockNumber.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from 'react'
import type { OnBlockNumberResponse } from 'viem/actions'
import { watchBlockNumber } from 'viem/actions'
import type { PublicClient } from 'viem/clients'
import type { PublicClient } from 'viem'
import type { OnBlockNumberResponse } from 'viem/public'
import { watchBlockNumber } from 'viem/public'

export function WatchBlockNumber({ client }: { client: PublicClient }) {
const [blockNumber, setBlockNumber] = useState<OnBlockNumberResponse>()
Expand Down
6 changes: 3 additions & 3 deletions playgrounds/dev/components/actions/WatchBlocks.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from 'react'
import type { OnBlockResponse } from 'viem/actions'
import { watchBlocks } from 'viem/actions'
import type { PublicClient } from 'viem/clients'
import type { PublicClient } from 'viem'
import type { OnBlockResponse } from 'viem/public'
import { watchBlocks } from 'viem/public'

export function WatchBlocks({ client }: { client: PublicClient }) {
const [block, setBlock] = useState<OnBlockResponse>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from 'react'
import type { OnTransactionsResponse } from 'viem/actions'
import { watchPendingTransactions } from 'viem/actions'
import type { PublicClient } from 'viem/clients'
import type { PublicClient } from 'viem'
import type { OnTransactionsResponse } from 'viem/public'
import { watchPendingTransactions } from 'viem/public'

export function WatchPendingTransactions({ client }: { client: PublicClient }) {
const [transactions, setTransactions] = useState<OnTransactionsResponse>([])
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/bench.ts → src/_test/bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { providers } from 'ethers'
import Web3 from 'web3'
import { JsonRpcProvider } from 'essential-eth'

import { localhost } from '../src/chains'
import { localhost } from '../chains'

export const ethersProvider = new providers.JsonRpcProvider(
localhost.rpcUrls.default.http[0],
Expand Down
2 changes: 1 addition & 1 deletion test/constants.ts → src/_test/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Hex } from '../src/types'
import type { Hex } from '../types'

export const accounts = [
{
Expand Down
2 changes: 1 addition & 1 deletion test/globalSetup.ts → src/_test/globalSetup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { testClient } from './utils'
import { reset, setAutomine, setIntervalMining } from '../src'
import { reset, setAutomine, setIntervalMining } from '../actions'

export async function setup() {
await reset(testClient, {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/setup.ts → src/_test/setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { beforeEach } from 'vitest'

import { promiseCache, responseCache } from '../src/utils/promise/withCache'
import { promiseCache, responseCache } from '../utils/promise/withCache'

beforeEach(() => {
promiseCache.clear()
Expand Down
8 changes: 4 additions & 4 deletions test/utils.ts → src/_test/utils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* c8 ignore start */
import { localhost } from '../src/chains'
import { localhost } from '../chains'
import {
createPublicClient,
createTestClient,
createWalletClient,
custom,
http,
webSocket,
} from '../src/clients'
import { rpc } from '../src/utils'
import { RpcError } from '../src/types/eip1193'
} from '../clients'
import { rpc } from '../utils'
import { RpcError } from '../types/eip1193'
import { accounts, localWsUrl } from './constants'

import type { RequestListener } from 'http'
Expand Down
2 changes: 1 addition & 1 deletion src/actions/public/call.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ethersProvider,
publicClient,
web3Provider,
} from '../../../test'
} from '../../_test'

import { call } from './call'

Expand Down
2 changes: 1 addition & 1 deletion src/actions/public/call.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from 'vitest'

import { accounts, publicClient } from '../../../test'
import { accounts, publicClient } from '../../_test'
import { celo } from '../../chains'
import { createPublicClient, http } from '../../clients'
import { numberToHex, parseGwei } from '../../utils'
Expand Down
6 changes: 1 addition & 5 deletions src/actions/public/callContract.bench.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { Contract } from 'ethers'
import { bench, describe } from 'vitest'

import {
ethersProvider,
publicClient,
wagmiContractConfig,
} from '../../../test'
import { ethersProvider, publicClient, wagmiContractConfig } from '../../_test'

import { callContract } from './callContract'

Expand Down
4 changes: 2 additions & 2 deletions src/actions/public/callContract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import {
testClient,
wagmiContractConfig,
walletClient,
} from '../../../test'
import { baycContractConfig } from '../../../test/abis'
} from '../../_test'
import { baycContractConfig } from '../../_test/abis'
import { BaseError } from '../../errors'
import { encodeFunctionData, getContractError } from '../../utils'
import { mine } from '../test'
Expand Down
2 changes: 1 addition & 1 deletion src/actions/public/createBlockFilter.bench.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { bench, describe } from 'vitest'

import { publicClient } from '../../../test'
import { publicClient } from '../../_test'

import { createBlockFilter } from './createBlockFilter'

Expand Down
2 changes: 1 addition & 1 deletion src/actions/public/createBlockFilter.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from 'vitest'

import { publicClient } from '../../../test'
import { publicClient } from '../../_test'

import { createBlockFilter } from './createBlockFilter'

Expand Down
2 changes: 1 addition & 1 deletion src/actions/public/createEventFilter.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, test } from 'vitest'

import { accounts, initialBlockNumber, publicClient } from '../../../test'
import { accounts, initialBlockNumber, publicClient } from '../../_test'

import { numberToHex, pad } from '../../utils'
import { buildFilterTopics, createEventFilter } from './createEventFilter'
Expand Down
2 changes: 1 addition & 1 deletion src/actions/public/createPendingTransactionFilter.bench.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { bench, describe } from 'vitest'

import { publicClient } from '../../../test'
import { publicClient } from '../../_test'

import { createPendingTransactionFilter } from './createPendingTransactionFilter'

Expand Down
2 changes: 1 addition & 1 deletion src/actions/public/createPendingTransactionFilter.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from 'vitest'

import { publicClient } from '../../../test'
import { publicClient } from '../../_test'

import { createPendingTransactionFilter } from './createPendingTransactionFilter'

Expand Down
4 changes: 2 additions & 2 deletions src/actions/public/deployContract.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from 'vitest'
import { accounts, publicClient, testClient, walletClient } from '../../../test'
import { baycContractConfig } from '../../../test/abis'
import { accounts, publicClient, testClient, walletClient } from '../../_test'
import { baycContractConfig } from '../../_test/abis'
import { parseEther } from '../../utils'
import { mine, setBalance } from '../test'
import { callContract } from './callContract'
Expand Down
2 changes: 1 addition & 1 deletion src/actions/public/estimateGas.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ethersProvider,
publicClient,
web3Provider,
} from '../../../test'
} from '../../_test'
import { parseEther } from '../../utils'

import { estimateGas } from './estimateGas'
Expand Down
2 changes: 1 addition & 1 deletion src/actions/public/estimateGas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
initialBlockNumber,
publicClient,
testClient,
} from '../../../test'
} from '../../_test'
import { parseEther, parseGwei } from '../../utils'
import { reset } from '../test'
import { estimateGas } from './estimateGas'
Expand Down
2 changes: 1 addition & 1 deletion src/actions/public/getBalance.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from 'vitest'

import { accounts, publicClient, testClient, walletClient } from '../../../test'
import { accounts, publicClient, testClient, walletClient } from '../../_test'
import { parseEther } from '../../utils'
import { getBlockNumber, sendTransaction } from '..'
import { mine, setBalance } from '../test'
Expand Down
2 changes: 1 addition & 1 deletion src/actions/public/getBlock.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ethersProvider,
publicClient,
web3Provider,
} from '../../../test'
} from '../../_test'

import { getBlock } from './getBlock'

Expand Down
2 changes: 1 addition & 1 deletion src/actions/public/getBlock.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assertType, describe, expect, test } from 'vitest'

import { initialBlockNumber, publicClient } from '../../../test'
import { initialBlockNumber, publicClient } from '../../_test'
import { celo } from '../../chains'
import { createPublicClient, http } from '../../clients'
import type { Block, Hex } from '../../types'
Expand Down
2 changes: 1 addition & 1 deletion src/actions/public/getBlockNumber.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ethersProvider,
publicClient,
web3Provider,
} from '../../../test'
} from '../../_test'

import { getBlockNumber } from './getBlockNumber'

Expand Down
2 changes: 1 addition & 1 deletion src/actions/public/getBlockNumber.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { beforeEach, expect, test, vi } from 'vitest'

import { publicClient } from '../../../test'
import { publicClient } from '../../_test'

import { getBlockNumber, getBlockNumberCache } from './getBlockNumber'

Expand Down
Loading

3 comments on commit a74d643

@vercel
Copy link

@vercel vercel bot commented on a74d643 Feb 2, 2023

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.vercel.app
viem-site-git-main-wagmi-dev.vercel.app
viem-site-wagmi-dev.vercel.app

@vercel
Copy link

@vercel vercel bot commented on a74d643 Feb 2, 2023

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-benchmark – ./playgrounds/benchmark

viem-benchmark.vercel.app
viem-benchmark-wagmi-dev.vercel.app
viem-benchmark-git-main-wagmi-dev.vercel.app

@vercel
Copy link

@vercel vercel bot commented on a74d643 Feb 2, 2023

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/dev

viem-playground.vercel.app
viem-playground-git-main-wagmi-dev.vercel.app
viem-playground-wagmi-dev.vercel.app

Please sign in to comment.