thirdweb 5.48.0-nightly-cbd6fd87d0120c6013ef354fe8ff22293e4c08e2-20240820000346 → 5.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/dist/cjs/adapters/ethers5.js +87 -1
  2. package/dist/cjs/adapters/ethers5.js.map +1 -1
  3. package/dist/cjs/adapters/ethers6.js +85 -15
  4. package/dist/cjs/adapters/ethers6.js.map +1 -1
  5. package/dist/cjs/adapters/viem.js +117 -43
  6. package/dist/cjs/adapters/viem.js.map +1 -1
  7. package/dist/cjs/contract/actions/compiler-metadata.js.map +1 -1
  8. package/dist/cjs/react/core/design-system/index.js +1 -0
  9. package/dist/cjs/react/core/design-system/index.js.map +1 -1
  10. package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js +56 -8
  11. package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
  12. package/dist/cjs/react/web/ui/ConnectWallet/Details.js +61 -52
  13. package/dist/cjs/react/web/ui/ConnectWallet/Details.js.map +1 -1
  14. package/dist/cjs/react/web/ui/ConnectWallet/MenuButton.js +0 -1
  15. package/dist/cjs/react/web/ui/ConnectWallet/MenuButton.js.map +1 -1
  16. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/WalletSelectorButton.js +1 -2
  17. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/WalletSelectorButton.js.map +1 -1
  18. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatFlow.js +9 -9
  19. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatFlow.js.map +1 -1
  20. package/dist/cjs/react/web/ui/ConnectWallet/screens/Details/WalletManagerScreen.js +1 -1
  21. package/dist/cjs/react/web/ui/ConnectWallet/screens/Details/WalletManagerScreen.js.map +1 -1
  22. package/dist/cjs/react/web/ui/ConnectWallet/screens/LinkedProfilesScreen.js +7 -1
  23. package/dist/cjs/react/web/ui/ConnectWallet/screens/LinkedProfilesScreen.js.map +1 -1
  24. package/dist/cjs/react/web/ui/components/ChainIcon.js +3 -2
  25. package/dist/cjs/react/web/ui/components/ChainIcon.js.map +1 -1
  26. package/dist/cjs/react/web/ui/components/CopyAddress.js +22 -0
  27. package/dist/cjs/react/web/ui/components/CopyAddress.js.map +1 -0
  28. package/dist/cjs/react/web/ui/components/IconContainer.js +25 -0
  29. package/dist/cjs/react/web/ui/components/IconContainer.js.map +1 -0
  30. package/dist/cjs/react/web/ui/components/Modal.js +1 -1
  31. package/dist/cjs/react/web/ui/components/Modal.js.map +1 -1
  32. package/dist/cjs/react/web/ui/components/WalletImage.js +4 -11
  33. package/dist/cjs/react/web/ui/components/WalletImage.js.map +1 -1
  34. package/dist/cjs/react/web/ui/components/formElements.js +3 -3
  35. package/dist/cjs/react/web/ui/components/formElements.js.map +1 -1
  36. package/dist/cjs/react/web/wallets/in-app/CountrySelector.js +1 -3
  37. package/dist/cjs/react/web/wallets/in-app/CountrySelector.js.map +1 -1
  38. package/dist/cjs/version.js +1 -1
  39. package/dist/cjs/version.js.map +1 -1
  40. package/dist/cjs/wallets/custom/smart/image.js +1 -1
  41. package/dist/cjs/wallets/custom/smart/image.js.map +1 -1
  42. package/dist/esm/adapters/ethers5.js +87 -1
  43. package/dist/esm/adapters/ethers5.js.map +1 -1
  44. package/dist/esm/adapters/ethers6.js +85 -15
  45. package/dist/esm/adapters/ethers6.js.map +1 -1
  46. package/dist/esm/adapters/viem.js +117 -43
  47. package/dist/esm/adapters/viem.js.map +1 -1
  48. package/dist/esm/contract/actions/compiler-metadata.js.map +1 -1
  49. package/dist/esm/react/core/design-system/index.js +1 -0
  50. package/dist/esm/react/core/design-system/index.js.map +1 -1
  51. package/dist/esm/react/core/hooks/transaction/useSendTransaction.js +55 -8
  52. package/dist/esm/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
  53. package/dist/esm/react/web/ui/ConnectWallet/Details.js +63 -54
  54. package/dist/esm/react/web/ui/ConnectWallet/Details.js.map +1 -1
  55. package/dist/esm/react/web/ui/ConnectWallet/MenuButton.js +0 -1
  56. package/dist/esm/react/web/ui/ConnectWallet/MenuButton.js.map +1 -1
  57. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/WalletSelectorButton.js +1 -2
  58. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/WalletSelectorButton.js.map +1 -1
  59. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatFlow.js +9 -9
  60. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatFlow.js.map +1 -1
  61. package/dist/esm/react/web/ui/ConnectWallet/screens/Details/WalletManagerScreen.js +1 -1
  62. package/dist/esm/react/web/ui/ConnectWallet/screens/Details/WalletManagerScreen.js.map +1 -1
  63. package/dist/esm/react/web/ui/ConnectWallet/screens/LinkedProfilesScreen.js +7 -1
  64. package/dist/esm/react/web/ui/ConnectWallet/screens/LinkedProfilesScreen.js.map +1 -1
  65. package/dist/esm/react/web/ui/components/ChainIcon.js +3 -2
  66. package/dist/esm/react/web/ui/components/ChainIcon.js.map +1 -1
  67. package/dist/esm/react/web/ui/components/CopyAddress.js +18 -0
  68. package/dist/esm/react/web/ui/components/CopyAddress.js.map +1 -0
  69. package/dist/esm/react/web/ui/components/IconContainer.js +21 -0
  70. package/dist/esm/react/web/ui/components/IconContainer.js.map +1 -0
  71. package/dist/esm/react/web/ui/components/Modal.js +1 -1
  72. package/dist/esm/react/web/ui/components/Modal.js.map +1 -1
  73. package/dist/esm/react/web/ui/components/WalletImage.js +1 -8
  74. package/dist/esm/react/web/ui/components/WalletImage.js.map +1 -1
  75. package/dist/esm/react/web/ui/components/formElements.js +3 -3
  76. package/dist/esm/react/web/ui/components/formElements.js.map +1 -1
  77. package/dist/esm/react/web/wallets/in-app/CountrySelector.js +2 -4
  78. package/dist/esm/react/web/wallets/in-app/CountrySelector.js.map +1 -1
  79. package/dist/esm/version.js +1 -1
  80. package/dist/esm/version.js.map +1 -1
  81. package/dist/esm/wallets/custom/smart/image.js +1 -1
  82. package/dist/esm/wallets/custom/smart/image.js.map +1 -1
  83. package/dist/types/adapters/ethers5.d.ts +87 -1
  84. package/dist/types/adapters/ethers5.d.ts.map +1 -1
  85. package/dist/types/adapters/ethers6.d.ts +85 -15
  86. package/dist/types/adapters/ethers6.d.ts.map +1 -1
  87. package/dist/types/adapters/viem.d.ts +117 -43
  88. package/dist/types/adapters/viem.d.ts.map +1 -1
  89. package/dist/types/contract/actions/compiler-metadata.d.ts +7 -1
  90. package/dist/types/contract/actions/compiler-metadata.d.ts.map +1 -1
  91. package/dist/types/react/core/design-system/index.d.ts +1 -0
  92. package/dist/types/react/core/design-system/index.d.ts.map +1 -1
  93. package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts +1 -0
  94. package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts.map +1 -1
  95. package/dist/types/react/web/ui/ConnectWallet/Details.d.ts.map +1 -1
  96. package/dist/types/react/web/ui/ConnectWallet/MenuButton.d.ts.map +1 -1
  97. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/WalletSelectorButton.d.ts.map +1 -1
  98. package/dist/types/react/web/ui/ConnectWallet/screens/LinkedProfilesScreen.d.ts.map +1 -1
  99. package/dist/types/react/web/ui/components/ChainIcon.d.ts.map +1 -1
  100. package/dist/types/react/web/ui/components/CopyAddress.d.ts +7 -0
  101. package/dist/types/react/web/ui/components/CopyAddress.d.ts.map +1 -0
  102. package/dist/types/react/web/ui/components/IconContainer.d.ts +10 -0
  103. package/dist/types/react/web/ui/components/IconContainer.d.ts.map +1 -0
  104. package/dist/types/react/web/ui/components/WalletImage.d.ts.map +1 -1
  105. package/dist/types/react/web/wallets/in-app/CountrySelector.d.ts.map +1 -1
  106. package/dist/types/version.d.ts +1 -1
  107. package/dist/types/version.d.ts.map +1 -1
  108. package/dist/types/wallets/custom/smart/image.d.ts +1 -1
  109. package/dist/types/wallets/custom/smart/image.d.ts.map +1 -1
  110. package/dist/types/wallets/in-app/core/authentication/types.d.ts +1 -1
  111. package/dist/types/wallets/in-app/core/authentication/types.d.ts.map +1 -1
  112. package/package.json +1 -1
  113. package/src/adapters/ethers5.ts +87 -1
  114. package/src/adapters/ethers6.ts +85 -15
  115. package/src/adapters/viem.ts +117 -44
  116. package/src/contract/actions/compiler-metadata.ts +4 -2
  117. package/src/react/core/design-system/index.ts +1 -0
  118. package/src/react/core/hooks/transaction/useSendTransaction.ts +65 -8
  119. package/src/react/web/ui/ConnectWallet/Details.tsx +157 -157
  120. package/src/react/web/ui/ConnectWallet/MenuButton.tsx +0 -1
  121. package/src/react/web/ui/ConnectWallet/screens/Buy/WalletSelectorButton.tsx +0 -6
  122. package/src/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatFlow.tsx +10 -10
  123. package/src/react/web/ui/ConnectWallet/screens/Details/WalletManagerScreen.tsx +5 -6
  124. package/src/react/web/ui/ConnectWallet/screens/LinkedProfilesScreen.tsx +21 -7
  125. package/src/react/web/ui/components/ChainIcon.tsx +4 -3
  126. package/src/react/web/ui/components/CopyAddress.tsx +34 -0
  127. package/src/react/web/ui/components/IconContainer.tsx +31 -0
  128. package/src/react/web/ui/components/Modal.tsx +1 -1
  129. package/src/react/web/ui/components/WalletImage.tsx +1 -8
  130. package/src/react/web/ui/components/formElements.tsx +3 -3
  131. package/src/react/web/wallets/in-app/CountrySelector.tsx +2 -8
  132. package/src/version.ts +1 -1
  133. package/src/wallets/custom/smart/image.ts +1 -1
  134. package/src/wallets/in-app/core/authentication/types.ts +1 -1
@@ -45,10 +45,50 @@ function assertEthers6(
45
45
  }
46
46
  }
47
47
 
48
+ /**
49
+ * The ethers6 adapter provides a way to convert between Thirdweb contracts, accounts, and providers.
50
+ * @example
51
+ *
52
+ * ### Converting a Thirdweb account to an ethers.js signer
53
+ * ```ts
54
+ * import { ethers6Adapter } from "thirdweb/adapters/ethers6";
55
+ * const signer = await ethers6Adapter.signer.toEthers({ client, chain, account });
56
+ * ```
57
+ *
58
+ * ### Converting an ethers.js signer into a Thirdweb account
59
+ * ```ts
60
+ * import { ethers6Adapter } from "thirdweb/adapters/ethers6";
61
+ * const account = await ethers6Adapter.signer.fromEthers({ signer });
62
+ * ```
63
+ *
64
+ * ### Converting a Thirdweb contract to an ethers.js Contract
65
+ * ```ts
66
+ * import { ethers6Adapter } from "thirdweb/adapters/ethers6";
67
+ * const ethersContract = await ethers6Adapter.contract.toEthers({ thirdwebContract });
68
+ * ```
69
+ *
70
+ * ### Converting a Thirdweb client and chain ID into an ethers.js provider
71
+ * ```ts
72
+ * import { ethers6Adapter } from "thirdweb/adapters/ethers6";
73
+ * const provider = ethers6Adapter.provider.toEthers({ client, chain });
74
+ * ```
75
+ */
48
76
  export const ethers6Adapter = /* @__PURE__ */ (() => {
49
77
  const ethers = universalethers;
50
78
 
51
79
  return {
80
+ /**
81
+ * Converts a Thirdweb client and chain ID into an ethers.js provider.
82
+ * @param options - The options for converting the Thirdweb client and chain ID into an ethers.js provider.
83
+ * @param options.client - The Thirdweb client.
84
+ * @param options.chain - The chain.
85
+ * @returns The ethers.js provider.
86
+ * @example
87
+ * ```ts
88
+ * import { ethers6Adapter } from "thirdweb/adapters/ethers6";
89
+ * const provider = ethers6Adapter.provider.toEthers({ client, chain });
90
+ * ```
91
+ */
52
92
  provider: {
53
93
  /**
54
94
  * Converts a Thirdweb client and chain ID into an ethers.js provider.
@@ -67,12 +107,29 @@ export const ethers6Adapter = /* @__PURE__ */ (() => {
67
107
  return toEthersProvider(ethers, options.client, options.chain);
68
108
  },
69
109
  },
110
+ /**
111
+ * Converts a ThirdwebContract to an ethers.js Contract or the other way around.
112
+ * @example
113
+ *
114
+ * ### toEthers
115
+ * ```ts
116
+ * import { ethers6Adapter } from "thirdweb/adapters/ethers6";
117
+ * const ethersContract = await ethers6Adapter.contract.toEthers({ thirdwebContract, account });
118
+ * ```
119
+ *
120
+ * ### fromEthers
121
+ * ```ts
122
+ * import { ethers6Adapter } from "thirdweb/adapters";
123
+ * const contract = ethers6Adapter.contract.fromEthers({ client, chain, ethersContract });
124
+ * ```
125
+ */
70
126
  contract: {
71
127
  /**
72
128
  * Converts a ThirdwebContract to an ethers.js Contract.
73
- * @param options - The options for converting the ThirdwebContract to an ethers.js Contract.
129
+ * @param options - The options for converting a ThirdwebContract to an ethers.js Contract.
74
130
  * @param options.thirdwebContract - The ThirdwebContract to convert.
75
- * @returns A Promise that resolves to an ethers.js Contract.
131
+ * @param options.account - The account to use for signing the transaction.
132
+ * @returns The ethers.js Contract.
76
133
  * @example
77
134
  * ```ts
78
135
  * import { ethers6Adapter } from "thirdweb/adapters/ethers6";
@@ -91,18 +148,15 @@ export const ethers6Adapter = /* @__PURE__ */ (() => {
91
148
  );
92
149
  },
93
150
  /**
94
- * Creates a ThirdwebContract instance from an ethers.js contract.
95
- * @param options - The options for creating the ThirdwebContract instance.
96
- * @returns A promise that resolves to a ThirdwebContract instance.
151
+ * Creates a ThirdwebContract from an ethers.js Contract.
152
+ * @param options - The options for creating a ThirdwebContract from an ethers.js Contract.
153
+ * @param options.ethersContract - The ethers.js Contract to convert.
154
+ * @param options.chain - The chain.
155
+ * @returns The ThirdwebContract.
97
156
  * @example
98
157
  * ```ts
99
158
  * import { ethers6Adapter } from "thirdweb/adapters/ethers6";
100
- *
101
- * const twContract = await ethers6Adapter.contract.fromEthersContract({
102
- * client,
103
- * ethersContract,
104
- * chainId,
105
- * });
159
+ * const contract = ethers6Adapter.contract.fromEthers({ ethersContract, chain });
106
160
  * ```
107
161
  */
108
162
  fromEthers: (options: FromEthersContractOptions) => {
@@ -110,16 +164,32 @@ export const ethers6Adapter = /* @__PURE__ */ (() => {
110
164
  return fromEthersContract(options);
111
165
  },
112
166
  },
167
+ /**
168
+ * Converts an ethers6 Signer into an Wallet object or the other way around.
169
+ * @example
170
+ *
171
+ * ### fromEthersSigner
172
+ * ```ts
173
+ * import { ethers6Adapter } from "thirdweb/adapters/ethers6";
174
+ * const signer = ethers6Adapter.signer.fromEthersSigner({ signer });
175
+ * ```
176
+ *
177
+ * ### toEthersSigner
178
+ * ```ts
179
+ * import { ethers6Adapter } from "thirdweb/adapters/ethers6";
180
+ * const signer = await ethers6Adapter.signer.toEthers({ client, chain, account });
181
+ * ```
182
+ */
113
183
  signer: {
114
184
  /**
115
- * Converts an ethers6 Signer into an Wallet object.
116
- * @param options - The options for converting the ethers6 Signer into a Wallet object.
185
+ * Converts an ethers6 Signer into an thirdweb account.
186
+ * @param options - The options for converting the ethers6 Signer into a thirdweb account.
117
187
  * @param options.signer - The ethers6 Signer object.
118
- * @returns - A Promise that resolves to an Wallet object.
188
+ * @returns - A Promise that resolves to a thirdweb account.
119
189
  * @example
120
190
  * ```ts
121
191
  * import { ethers6Adapter } from "thirdweb/adapters/ethers6";
122
- * const wallet = await ethers6Adapter.signer.fromEthersSigner({ signer });
192
+ * const account = await ethers6Adapter.signer.fromEthers({ signer });
123
193
  * ```
124
194
  */
125
195
  fromEthers: (options: { signer: ethers6.Signer }) => {
@@ -21,34 +21,87 @@ import { sendTransaction } from "../transaction/actions/send-transaction.js";
21
21
  import { prepareTransaction } from "../transaction/prepare-transaction.js";
22
22
  import type { Account } from "../wallets/interfaces/wallet.js";
23
23
 
24
+ /**
25
+ * Converts thirdweb accounts and contracts to viem wallet clients and contract objects or the other way around.
26
+ * @example
27
+ *
28
+ * ### Converting a thirdweb account to a viem wallet client
29
+ *
30
+ * ```ts
31
+ * import { viemAdapter } from "thirdweb/adapters/viem";
32
+ *
33
+ * const walletClient = viemAdapter.walletClient.toViem({
34
+ * account,
35
+ * client,
36
+ * chain: ethereum,
37
+ * });
38
+ * ```
39
+ *
40
+ * ### Converting a viem wallet client to a thirdweb account
41
+ * ```ts
42
+ * import { viemAdapter } from "thirdweb/adapters";
43
+ *
44
+ * const account = viemAdapter.walletClient.fromViem({
45
+ * walletClient,
46
+ * });
47
+ * ```
48
+ *
49
+ * ### Converting a thirdweb contract to a viem contract
50
+ * ```ts
51
+ * import { viemAdapter } from "thirdweb/adapters";
52
+ * const viemContract = await viemAdapter.contract.toViem({ thirdwebContract });
53
+ * ```
54
+ *
55
+ * ### Converting a viem contract to a thirdweb contract
56
+ * ```ts
57
+ * import { viemAdapter } from "thirdweb/adapters/viem";
58
+ *
59
+ * const contract = viemAdapter.contract.fromViem({
60
+ * viemContract: viemContract,
61
+ * chain: ethereum,
62
+ * client,
63
+ * });
64
+ * ```
65
+ *
66
+ * ### Converting a thirdweb client to a public viem client
67
+ * ```ts
68
+ * import { viemAdapter } from "thirdweb/adapters";
69
+ *
70
+ * const publicClient = viemAdapter.publicClient.toViem({
71
+ * chain: ethereum,
72
+ * client,
73
+ * });
74
+ * ```
75
+ *
76
+ */
24
77
  export const viemAdapter = {
78
+ /**
79
+ * Creates a ThirdwebContract from a Viem contract or the other way around.
80
+ * @param options - The options for creating the contract.
81
+ * @returns The ThirdwebContract.
82
+ * @example
83
+ *
84
+ * ### fromViem
85
+ *
86
+ * ```ts
87
+ * import { viemAdapter } from "thirdweb/adapters/viem";
88
+ *
89
+ * const contract = viemAdapter.contract.fromViem({
90
+ * viemContract: viemContract,
91
+ * chain: ethereum,
92
+ * client,
93
+ * });
94
+ * ```
95
+ *
96
+ * ### toViem
97
+ *
98
+ * ```ts
99
+ * import { viemAdapter } from "thirdweb/adapters";
100
+ * const viemContract = await viemAdapter.contract.toViem({ thirdwebContract });
101
+ * ```
102
+ */
25
103
  contract: {
26
- /**
27
- * Creates a ThirdwebContract from a Viem contract.
28
- * @param options - The options for creating the contract.
29
- * @returns The ThirdwebContract.
30
- * @example
31
- * ```ts
32
- * import { viemAdapter } from "thirdweb/adapters/viem";
33
- *
34
- * const contract = viemAdapter.contract.fromViem({
35
- * viemContract: viemContract,
36
- * chain: ethereum,
37
- * client,
38
- * });
39
- * ```
40
- */
41
104
  fromViem: fromViemContract,
42
- /**
43
- * Converts a ThirdwebContract instance to a Viem contract representation.
44
- * @param contract The ThirdwebContract instance to convert.
45
- * @returns A promise that resolves to the Viem contract representation.
46
- * @example
47
- * ```ts
48
- * import { viemAdapter } from "thirdweb/adapters";
49
- * const viemContract = await viemAdapter.contract.toViem({ thirdwebContract });
50
- * ```
51
- */
52
105
  toViem: toViemContract,
53
106
  },
54
107
 
@@ -70,35 +123,55 @@ export const viemAdapter = {
70
123
  toViem: toViemPublicClient,
71
124
  },
72
125
 
126
+ /**
127
+ * Converts a thirdweb account to a Viem Wallet client or the other way around.
128
+ * @param options - The options for creating the Viem Wallet client.
129
+ * @returns The Viem Wallet client.
130
+ * @example
131
+ *
132
+ * ### toViem
133
+ * ```ts
134
+ * import { viemAdapter } from "thirdweb/adapters/viem";
135
+ *
136
+ * const walletClient = viemAdapter.walletClient.toViem({
137
+ * account,
138
+ * client,
139
+ * chain: ethereum,
140
+ * });
141
+ * ```
142
+ *
143
+ * ### fromViem
144
+ * ```ts
145
+ * import { viemAdapter } from "thirdweb/adapters";
146
+ *
147
+ * const account = viemAdapter.walletClient.fromViem({
148
+ * walletClient,
149
+ * });
150
+ * ```
151
+ */
73
152
  walletClient: {
74
153
  /**
75
- * Converts options to a Viem Wallet client.
76
- * @param options - The options for creating the Viem Wallet client.
77
- * @returns The Viem Wallet client.
154
+ * Converts a Thirdweb wallet to a Viem wallet client.
155
+ * @param options - The options for converting a Thirdweb wallet to a Viem wallet client.
156
+ * @param options.account - The Thirdweb wallet to convert.
157
+ * @returns A Promise that resolves to a Viem wallet client.
78
158
  * @example
79
159
  * ```ts
80
- * import { viemAdapter } from "thirdweb/adapters/viem";
81
- *
82
- * const walletClient = viemAdapter.walletClient.toViem({
83
- * account,
84
- * client,
85
- * chain: ethereum,
86
- * });
160
+ * import { viemAdapter } from "thirdweb/adapters";
161
+ * const walletClient = viemAdapter.walletClient.toViem({ account, client, chain });
87
162
  * ```
88
163
  */
89
164
  toViem: toViemWalletClient,
90
-
91
165
  /**
92
- * Converts a Viem Wallet client to an Account.
93
- * @param options - The options for creating the Account.
94
- * @returns The Account.
166
+ * Converts a Viem wallet client to a Thirdweb wallet.
167
+ * @param options - The options for converting a Viem wallet client to a Thirdweb wallet.
168
+ * @param options.walletClient - The Viem wallet client to convert.
169
+ * @returns A Promise that resolves to a Thirdweb wallet.
95
170
  * @example
96
171
  * ```ts
97
- * import { viemAdapter } from "thirdweb/adapters/viem";
98
- *
99
- * const account = viemAdapter.walletClient.fromViem({
100
- * walletClient,
101
- * });
172
+ * import { viemAdapter } from "thirdweb/adapters";
173
+ * const account = viemAdapter.walletClient.fromViem({ walletClient });
174
+ * ```
102
175
  */
103
176
  fromViem: fromViemWalletClient,
104
177
  },
@@ -6,8 +6,10 @@ import type { Abi } from "abitype";
6
6
  export type PublishedMetadata = {
7
7
  name: string;
8
8
  abi: Abi;
9
- // biome-ignore lint/suspicious/noExplicitAny: TODO: fix later
10
- metadata: Record<string, any>;
9
+ // biome-ignore lint/suspicious/noExplicitAny: TODO: fix later by updating this type to match the specs here: https://docs.soliditylang.org/en/latest/metadata.html
10
+ metadata: Record<string, any> & {
11
+ sources: Record<string, { content: string } | { urls: string[] }>;
12
+ };
11
13
  info: {
12
14
  title?: string;
13
15
  author?: string;
@@ -170,6 +170,7 @@ export const fontSize = {
170
170
  };
171
171
 
172
172
  export const spacing = {
173
+ "4xs": "2px",
173
174
  "3xs": "4px",
174
175
  xxs: "6px",
175
176
  xs: "8px",
@@ -1,7 +1,9 @@
1
1
  import { type UseMutationResult, useMutation } from "@tanstack/react-query";
2
2
  import type { Chain } from "../../../../chains/types.js";
3
+ import { getGasPrice } from "../../../../gas/get-gas-price.js";
3
4
  import type { BuyWithCryptoStatus } from "../../../../pay/buyWithCrypto/getStatus.js";
4
5
  import type { BuyWithFiatStatus } from "../../../../pay/buyWithFiat/getStatus.js";
6
+ import { estimateGasCost } from "../../../../transaction/actions/estimate-gas-cost.js";
5
7
  import type { GaslessOptions } from "../../../../transaction/actions/gasless/types.js";
6
8
  import { sendTransaction } from "../../../../transaction/actions/send-transaction.js";
7
9
  import type { WaitForReceiptOptions } from "../../../../transaction/actions/wait-for-tx-receipt.js";
@@ -12,6 +14,7 @@ import { getWalletBalance } from "../../../../wallets/utils/getWalletBalance.js"
12
14
  import type { LocaleId } from "../../../web/ui/types.js";
13
15
  import type { Theme } from "../../design-system/index.js";
14
16
  import type { SupportedTokens } from "../../utils/defaultTokens.js";
17
+ import { hasSponsoredTransactionsEnabled } from "../../utils/wallet.js";
15
18
 
16
19
  /**
17
20
  * Configuration for the "Pay Modal" that opens when the user doesn't have enough funds to send a transaction.
@@ -158,16 +161,31 @@ export function useSendTransactionCore(args: {
158
161
  const nativeValue = _nativeValue || 0n;
159
162
  const erc20Value = _erc20Value?.amountWei || 0n;
160
163
 
161
- const balance = await getWalletBalance({
162
- client: tx.client,
163
- address: account.address,
164
- chain: tx.chain,
165
- tokenAddress: _erc20Value?.tokenAddress,
166
- });
164
+ const [nativeBalance, erc20Balance, gasCost] = await Promise.all([
165
+ getWalletBalance({
166
+ client: tx.client,
167
+ address: account.address,
168
+ chain: tx.chain,
169
+ }),
170
+ _erc20Value?.tokenAddress
171
+ ? getWalletBalance({
172
+ client: tx.client,
173
+ address: account.address,
174
+ chain: tx.chain,
175
+ })
176
+ : undefined,
177
+ getTotalTxCostForBuy(tx, account.address),
178
+ ]);
179
+
180
+ const gasSponsored = hasSponsoredTransactionsEnabled(wallet);
181
+ const txGasCost = gasSponsored ? 0n : gasCost;
182
+ const nativeCost = nativeValue + txGasCost;
167
183
 
168
184
  const shouldShowModal =
169
- (erc20Value > 0n && balance.value < erc20Value) ||
170
- (nativeValue > 0n && balance.value < nativeValue);
185
+ (erc20Value > 0n &&
186
+ erc20Balance &&
187
+ erc20Balance.value < erc20Value) ||
188
+ (nativeCost > 0n && nativeBalance.value < nativeCost);
171
189
 
172
190
  if (shouldShowModal) {
173
191
  showPayModal({
@@ -189,3 +207,42 @@ export function useSendTransactionCore(args: {
189
207
  },
190
208
  });
191
209
  }
210
+
211
+ export async function getTotalTxCostForBuy(
212
+ tx: PreparedTransaction,
213
+ from?: string,
214
+ ) {
215
+ try {
216
+ const gasCost = await estimateGasCost({
217
+ transaction: tx,
218
+ from,
219
+ });
220
+
221
+ const bufferCost = gasCost.wei / 10n;
222
+
223
+ // Note: get tx.value AFTER estimateGasCost
224
+ const txValue = await resolvePromisedValue(tx.value);
225
+
226
+ // add 10% extra gas cost to the estimate to ensure user buys enough to cover the tx cost
227
+ return gasCost.wei + bufferCost + (txValue || 0n);
228
+ } catch (e) {
229
+ if (from) {
230
+ // try again without passing from
231
+ return await getTotalTxCostForBuy(tx);
232
+ }
233
+ // fallback if both fail, use the tx value + 2M * gas price
234
+ const value = await resolvePromisedValue(tx.value);
235
+
236
+ const gasPrice = await getGasPrice({
237
+ client: tx.client,
238
+ chain: tx.chain,
239
+ });
240
+
241
+ const buffer = 2_000_000n * gasPrice;
242
+
243
+ if (!value) {
244
+ return 0n + buffer;
245
+ }
246
+ return value + buffer;
247
+ }
248
+ }