viem 2.21.27 → 2.21.28

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/_cjs/actions/wallet/sendTransaction.js +35 -11
  3. package/_cjs/actions/wallet/sendTransaction.js.map +1 -1
  4. package/_cjs/actions/wallet/writeContract.js +3 -3
  5. package/_cjs/actions/wallet/writeContract.js.map +1 -1
  6. package/_cjs/chains/definitions/kakarotStarknetSepolia.js +1 -1
  7. package/_cjs/chains/definitions/kakarotStarknetSepolia.js.map +1 -1
  8. package/_cjs/chains/index.js.map +1 -1
  9. package/_cjs/errors/version.js +1 -1
  10. package/_cjs/experimental/eip5792/actions/getCapabilities.js +2 -3
  11. package/_cjs/experimental/eip5792/actions/getCapabilities.js.map +1 -1
  12. package/_cjs/experimental/eip5792/decorators/eip5792.js.map +1 -1
  13. package/_esm/actions/wallet/sendTransaction.js +37 -11
  14. package/_esm/actions/wallet/sendTransaction.js.map +1 -1
  15. package/_esm/actions/wallet/writeContract.js +3 -3
  16. package/_esm/actions/wallet/writeContract.js.map +1 -1
  17. package/_esm/chains/definitions/kakarotStarknetSepolia.js +1 -1
  18. package/_esm/chains/definitions/kakarotStarknetSepolia.js.map +1 -1
  19. package/_esm/chains/index.js +1 -0
  20. package/_esm/chains/index.js.map +1 -1
  21. package/_esm/errors/version.js +1 -1
  22. package/_esm/experimental/eip5792/actions/getCapabilities.js +2 -3
  23. package/_esm/experimental/eip5792/actions/getCapabilities.js.map +1 -1
  24. package/_esm/experimental/eip5792/decorators/eip5792.js.map +1 -1
  25. package/_types/actions/wallet/prepareTransactionRequest.d.ts +1 -1
  26. package/_types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -1
  27. package/_types/actions/wallet/sendTransaction.d.ts +2 -1
  28. package/_types/actions/wallet/sendTransaction.d.ts.map +1 -1
  29. package/_types/actions/wallet/writeContract.d.ts +2 -2
  30. package/_types/actions/wallet/writeContract.d.ts.map +1 -1
  31. package/_types/chains/definitions/kakarotStarknetSepolia.d.ts +1 -1
  32. package/_types/chains/definitions/kakarotStarknetSepolia.d.ts.map +1 -1
  33. package/_types/chains/index.d.ts +1 -0
  34. package/_types/chains/index.d.ts.map +1 -1
  35. package/_types/errors/transaction.d.ts +1 -1
  36. package/_types/errors/transaction.d.ts.map +1 -1
  37. package/_types/errors/version.d.ts +1 -1
  38. package/_types/experimental/eip5792/actions/getCapabilities.d.ts +6 -9
  39. package/_types/experimental/eip5792/actions/getCapabilities.d.ts.map +1 -1
  40. package/_types/experimental/eip5792/decorators/eip5792.d.ts +1 -1
  41. package/_types/experimental/eip5792/decorators/eip5792.d.ts.map +1 -1
  42. package/_types/types/account.d.ts +4 -8
  43. package/_types/types/account.d.ts.map +1 -1
  44. package/_types/utils/errors/getTransactionError.d.ts +1 -1
  45. package/_types/utils/errors/getTransactionError.d.ts.map +1 -1
  46. package/actions/wallet/prepareTransactionRequest.ts +1 -1
  47. package/actions/wallet/sendTransaction.ts +50 -15
  48. package/actions/wallet/writeContract.ts +5 -5
  49. package/chains/definitions/kakarotStarknetSepolia.ts +1 -1
  50. package/chains/index.ts +1 -0
  51. package/errors/transaction.ts +1 -1
  52. package/errors/version.ts +1 -1
  53. package/experimental/eip5792/actions/getCapabilities.ts +10 -21
  54. package/experimental/eip5792/decorators/eip5792.ts +1 -3
  55. package/package.json +1 -1
  56. package/types/account.ts +17 -6
  57. package/utils/errors/getTransactionError.ts +1 -1
@@ -1,9 +1,11 @@
1
+ import type { Address } from 'abitype'
2
+
1
3
  import { parseAccount } from '../../../accounts/utils/parseAccount.js'
2
4
  import type { Client } from '../../../clients/createClient.js'
3
5
  import type { Transport } from '../../../clients/transports/createTransport.js'
4
6
  import { AccountNotFoundError } from '../../../errors/account.js'
5
7
  import type { ErrorType } from '../../../errors/utils.js'
6
- import type { Account, GetAccountParameter } from '../../../types/account.js'
8
+ import type { Account } from '../../../types/account.js'
7
9
  import type { Chain } from '../../../types/chain.js'
8
10
  import type {
9
11
  WalletCapabilities,
@@ -12,9 +14,9 @@ import type {
12
14
  import type { Prettify } from '../../../types/utils.js'
13
15
  import type { RequestErrorType } from '../../../utils/buildRequest.js'
14
16
 
15
- export type GetCapabilitiesParameters<
16
- account extends Account | undefined = Account | undefined,
17
- > = GetAccountParameter<account>
17
+ export type GetCapabilitiesParameters = {
18
+ account?: Account | Address | undefined
19
+ }
18
20
 
19
21
  export type GetCapabilitiesReturnType = Prettify<
20
22
  WalletCapabilitiesRecord<WalletCapabilities, number>
@@ -42,24 +44,11 @@ export type GetCapabilitiesErrorType = RequestErrorType | ErrorType
42
44
  * })
43
45
  * const capabilities = await getCapabilities(client)
44
46
  */
45
- export async function getCapabilities<
46
- chain extends Chain | undefined,
47
- account extends Account | undefined = undefined,
48
- >(
49
- ...parameters: account extends Account
50
- ?
51
- | [client: Client<Transport, chain, account>]
52
- | [
53
- client: Client<Transport, chain, account>,
54
- parameters: GetCapabilitiesParameters<account>,
55
- ]
56
- : [
57
- client: Client<Transport, chain, account>,
58
- parameters: GetCapabilitiesParameters<account>,
59
- ]
47
+ export async function getCapabilities<chain extends Chain | undefined>(
48
+ client: Client<Transport, chain>,
49
+ parameters: GetCapabilitiesParameters = {},
60
50
  ): Promise<GetCapabilitiesReturnType> {
61
- const [client, args] = parameters
62
- const account_raw = args?.account ?? client.account
51
+ const account_raw = parameters?.account ?? client.account
63
52
 
64
53
  if (!account_raw) throw new AccountNotFoundError()
65
54
  const account = parseAccount(account_raw)
@@ -80,9 +80,7 @@ export type Eip5792Actions<
80
80
  * })
81
81
  */
82
82
  getCapabilities: (
83
- ...parameters: account extends Account
84
- ? [] | [parameters: GetCapabilitiesParameters<account>]
85
- : [parameters: GetCapabilitiesParameters<undefined>]
83
+ parameters?: GetCapabilitiesParameters,
86
84
  ) => Promise<GetCapabilitiesReturnType>
87
85
  /**
88
86
  * Requests the connected wallet to send a batch of calls.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "2.21.27",
4
+ "version": "2.21.28",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
package/types/account.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { Address } from 'abitype'
2
2
 
3
3
  import type { Account, JsonRpcAccount } from '../accounts/types.js'
4
- import type { IsUndefined, Prettify } from './utils.js'
4
+ import type { IsUndefined, MaybeRequired, Prettify } from './utils.js'
5
5
 
6
6
  export type DeriveAccount<
7
7
  account extends Account | undefined,
@@ -12,11 +12,22 @@ export type GetAccountParameter<
12
12
  account extends Account | undefined = Account | undefined,
13
13
  accountOverride extends Account | Address | undefined = Account | Address,
14
14
  required extends boolean = true,
15
- > = IsUndefined<account> extends true
16
- ? required extends true
17
- ? { account: accountOverride | Account | Address }
18
- : { account?: accountOverride | Account | Address | undefined }
19
- : { account?: accountOverride | Account | Address | undefined }
15
+ nullish extends boolean = false,
16
+ > = MaybeRequired<
17
+ {
18
+ account?:
19
+ | accountOverride
20
+ | Account
21
+ | Address
22
+ | (nullish extends true ? null : never)
23
+ | undefined
24
+ },
25
+ IsUndefined<account> extends true
26
+ ? required extends true
27
+ ? true
28
+ : false
29
+ : false
30
+ >
20
31
 
21
32
  export type ParseAccount<
22
33
  accountOrAddress extends Account | Address | undefined =
@@ -19,7 +19,7 @@ export type GetTransactionErrorParameters = Omit<
19
19
  SendTransactionParameters,
20
20
  'account' | 'chain'
21
21
  > & {
22
- account: Account
22
+ account: Account | null
23
23
  chain?: Chain | undefined
24
24
  docsPath?: string | undefined
25
25
  }