thirdweb 5.88.6-nightly-b182302f590e75c9881cebd0ca1cc8b1425d50b8-20250218000338 → 5.88.6

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 (32) hide show
  1. package/dist/cjs/adapters/viem.js +110 -0
  2. package/dist/cjs/adapters/viem.js.map +1 -1
  3. package/dist/cjs/chains/chain-definitions/arbitrum-nova.js +1 -1
  4. package/dist/cjs/chains/chain-definitions/arbitrum-nova.js.map +1 -1
  5. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +5 -14
  6. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
  7. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/TokenSelectorScreen.js +34 -3
  8. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/TokenSelectorScreen.js.map +1 -1
  9. package/dist/cjs/version.js +1 -1
  10. package/dist/cjs/version.js.map +1 -1
  11. package/dist/esm/adapters/viem.js +110 -0
  12. package/dist/esm/adapters/viem.js.map +1 -1
  13. package/dist/esm/chains/chain-definitions/arbitrum-nova.js +1 -1
  14. package/dist/esm/chains/chain-definitions/arbitrum-nova.js.map +1 -1
  15. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +5 -14
  16. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
  17. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/TokenSelectorScreen.js +34 -3
  18. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/TokenSelectorScreen.js.map +1 -1
  19. package/dist/esm/version.js +1 -1
  20. package/dist/esm/version.js.map +1 -1
  21. package/dist/types/adapters/viem.d.ts +65 -1
  22. package/dist/types/adapters/viem.d.ts.map +1 -1
  23. package/dist/types/version.d.ts +1 -1
  24. package/dist/types/version.d.ts.map +1 -1
  25. package/package.json +1 -1
  26. package/src/adapters/viem-legacy.test.ts +159 -0
  27. package/src/adapters/viem.test.ts +30 -14
  28. package/src/adapters/viem.ts +132 -1
  29. package/src/chains/chain-definitions/arbitrum-nova.ts +1 -1
  30. package/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx +6 -21
  31. package/src/react/web/ui/ConnectWallet/screens/Buy/swap/TokenSelectorScreen.tsx +71 -9
  32. package/src/version.ts +1 -1
@@ -6,27 +6,26 @@ import {
6
6
  USDT_CONTRACT_ADDRESS,
7
7
  USDT_CONTRACT_WITH_ABI,
8
8
  } from "~test/test-contracts.js";
9
- import { ANVIL_PKEY_A, TEST_ACCOUNT_B } from "~test/test-wallets.js";
9
+ import {
10
+ ANVIL_PKEY_A,
11
+ TEST_ACCOUNT_B,
12
+ TEST_IN_APP_WALLET_A,
13
+ } from "~test/test-wallets.js";
10
14
  import { typedData } from "~test/typed-data.js";
11
-
12
15
  import { ANVIL_CHAIN, FORKED_ETHEREUM_CHAIN } from "../../test/src/chains.js";
13
16
  import { TEST_CLIENT } from "../../test/src/test-clients.js";
14
17
  import { randomBytesBuffer } from "../utils/random.js";
15
- import { privateKeyToAccount } from "../wallets/private-key.js";
16
18
  import { toViemContract, viemAdapter } from "./viem.js";
17
19
 
18
- const account = privateKeyToAccount({
19
- privateKey: ANVIL_PKEY_A,
20
- client: TEST_CLIENT,
21
- });
20
+ const wallet = TEST_IN_APP_WALLET_A;
22
21
 
23
22
  describe("walletClient.toViem", () => {
24
- let walletClient: ReturnType<typeof viemAdapter.walletClient.toViem>;
23
+ let walletClient: ReturnType<typeof viemAdapter.wallet.toViem>;
25
24
 
26
25
  beforeAll(() => {
27
- walletClient = viemAdapter.walletClient.toViem({
26
+ walletClient = viemAdapter.wallet.toViem({
28
27
  client: TEST_CLIENT,
29
- account,
28
+ wallet,
30
29
  chain: ANVIL_CHAIN,
31
30
  });
32
31
  });
@@ -37,7 +36,8 @@ describe("walletClient.toViem", () => {
37
36
  });
38
37
 
39
38
  test("should sign message", async () => {
40
- if (!walletClient.account) {
39
+ const account = wallet.getAccount();
40
+ if (!walletClient.account || !account) {
41
41
  throw new Error("Account not found");
42
42
  }
43
43
  const expectedSig = await account.signMessage({ message: "hello world" });
@@ -49,7 +49,8 @@ describe("walletClient.toViem", () => {
49
49
  });
50
50
 
51
51
  test("should sign raw message", async () => {
52
- if (!walletClient.account) {
52
+ const account = wallet.getAccount();
53
+ if (!walletClient.account || !account) {
53
54
  throw new Error("Account not found");
54
55
  }
55
56
  const bytes = randomBytesBuffer(32);
@@ -110,12 +111,16 @@ describe("walletClient.toViem", () => {
110
111
  });
111
112
 
112
113
  test("should get address on live chain", async () => {
113
- walletClient = viemAdapter.walletClient.toViem({
114
+ walletClient = viemAdapter.wallet.toViem({
114
115
  client: TEST_CLIENT,
115
- account,
116
+ wallet,
116
117
  chain: FORKED_ETHEREUM_CHAIN,
117
118
  });
118
119
 
120
+ const account = wallet.getAccount();
121
+ if (!walletClient.account || !account) {
122
+ throw new Error("Account not found");
123
+ }
119
124
  const address = await walletClient.getAddresses();
120
125
  expect(address[0]).toBeDefined();
121
126
  expect(address[0]).toBe(account.address);
@@ -123,6 +128,10 @@ describe("walletClient.toViem", () => {
123
128
 
124
129
  test("should match thirdweb account signature", async () => {
125
130
  const message = "testing123";
131
+ const account = wallet.getAccount();
132
+ if (!walletClient.account || !account) {
133
+ throw new Error("Account not found");
134
+ }
126
135
 
127
136
  const rawViemAccount = viemPrivateKeyToAccount(ANVIL_PKEY_A);
128
137
  const twSignature = await account.signMessage({ message });
@@ -143,4 +152,11 @@ describe("walletClient.toViem", () => {
143
152
  expect(result.abi).toEqual(USDT_ABI);
144
153
  expect(result.address).toBe(USDT_CONTRACT_ADDRESS);
145
154
  });
155
+
156
+ test("should switch chain", async () => {
157
+ await walletClient.switchChain({
158
+ id: FORKED_ETHEREUM_CHAIN.id,
159
+ });
160
+ expect(await walletClient.getChainId()).toBe(FORKED_ETHEREUM_CHAIN.id);
161
+ });
146
162
  });
@@ -20,7 +20,9 @@ import { estimateGas } from "../transaction/actions/estimate-gas.js";
20
20
  import { sendTransaction } from "../transaction/actions/send-transaction.js";
21
21
  import { prepareTransaction } from "../transaction/prepare-transaction.js";
22
22
  import { getAddress } from "../utils/address.js";
23
- import type { Account } from "../wallets/interfaces/wallet.js";
23
+ import type { Account, Wallet } from "../wallets/interfaces/wallet.js";
24
+ import { fromProvider } from "./eip1193/from-eip1193.js";
25
+ import { toProvider } from "./eip1193/to-eip1193.js";
24
26
 
25
27
  /**
26
28
  * Converts thirdweb accounts and contracts to viem wallet clients and contract objects or the other way around.
@@ -149,6 +151,7 @@ export const viemAdapter = {
149
151
  * walletClient,
150
152
  * });
151
153
  * ```
154
+ * @deprecated use viemAdapter.wallet instead
152
155
  */
153
156
  walletClient: {
154
157
  /**
@@ -161,6 +164,7 @@ export const viemAdapter = {
161
164
  * import { viemAdapter } from "thirdweb/adapters";
162
165
  * const walletClient = viemAdapter.walletClient.toViem({ account, client, chain });
163
166
  * ```
167
+ * @deprecated use viemAdapter.wallet instead
164
168
  */
165
169
  toViem: toViemWalletClient,
166
170
  /**
@@ -173,9 +177,62 @@ export const viemAdapter = {
173
177
  * import { viemAdapter } from "thirdweb/adapters";
174
178
  * const account = viemAdapter.walletClient.fromViem({ walletClient });
175
179
  * ```
180
+ * @deprecated use viemAdapter.wallet instead
176
181
  */
177
182
  fromViem: fromViemWalletClient,
178
183
  },
184
+ /**
185
+ * Converts a thirdweb account to a Viem Wallet client or the other way around.
186
+ * @param options - The options for creating the Viem Wallet client.
187
+ * @returns The Viem Wallet client.
188
+ * @example
189
+ *
190
+ * ### toViem
191
+ * ```ts
192
+ * import { viemAdapter } from "thirdweb/adapters/viem";
193
+ *
194
+ * const walletClient = viemAdapter.wallet.toViem({
195
+ * wallet,
196
+ * client,
197
+ * chain: ethereum,
198
+ * });
199
+ * ```
200
+ *
201
+ * ### fromViem
202
+ * ```ts
203
+ * import { viemAdapter } from "thirdweb/adapters";
204
+ *
205
+ * const wallet = viemAdapter.wallet.fromViem({
206
+ * walletClient,
207
+ * });
208
+ * ```
209
+ */
210
+ wallet: {
211
+ /**
212
+ * Converts a Thirdweb wallet to a Viem wallet client.
213
+ * @param options - The options for converting a Thirdweb wallet to a Viem wallet client.
214
+ * @param options.wallet - The Thirdweb wallet to convert.
215
+ * @returns A Promise that resolves to a Viem wallet client.
216
+ * @example
217
+ * ```ts
218
+ * import { viemAdapter } from "thirdweb/adapters";
219
+ * const walletClient = viemAdapter.wallet.toViem({ wallet, client, chain });
220
+ * ```
221
+ */
222
+ toViem: walletToViem,
223
+ /**
224
+ * Converts a Viem wallet client to a Thirdweb wallet.
225
+ * @param options - The options for converting a Viem wallet client to a Thirdweb wallet.
226
+ * @param options.walletClient - The Viem wallet client to convert.
227
+ * @returns A Promise that resolves to a Thirdweb wallet.
228
+ * @example
229
+ * ```ts
230
+ * import { viemAdapter } from "thirdweb/adapters";
231
+ * const wallet = viemAdapter.wallet.fromViem({ walletClient });
232
+ * ```
233
+ */
234
+ fromViem: walletFromViem,
235
+ },
179
236
  };
180
237
 
181
238
  type FromViemContractOptions<TAbi extends Abi> = {
@@ -247,6 +304,7 @@ type ToViemWalletClientOptions = {
247
304
  chain: Chain;
248
305
  };
249
306
 
307
+ // DEPRECATED
250
308
  function toViemWalletClient(options: ToViemWalletClientOptions): WalletClient {
251
309
  const { account, chain, client } = options;
252
310
  if (!account) {
@@ -305,6 +363,14 @@ function toViemWalletClient(options: ToViemWalletClientOptions): WalletClient {
305
363
  if (request.method === "eth_accounts") {
306
364
  return [account.address];
307
365
  }
366
+ if (
367
+ request.method === "wallet_switchEthereumChain" ||
368
+ request.method === "wallet_addEthereumChain"
369
+ ) {
370
+ throw new Error(
371
+ "Can't switch chains because only an account was passed to 'viemAdapter.walletClient.toViem()', please pass a connected wallet instance instead.",
372
+ );
373
+ }
308
374
  return rpcClient(request);
309
375
  },
310
376
  });
@@ -317,6 +383,7 @@ function toViemWalletClient(options: ToViemWalletClientOptions): WalletClient {
317
383
  });
318
384
  }
319
385
 
386
+ // DEPRECATED
320
387
  function fromViemWalletClient(options: {
321
388
  walletClient: WalletClient;
322
389
  }): Account {
@@ -355,3 +422,67 @@ function fromViemWalletClient(options: {
355
422
  },
356
423
  };
357
424
  }
425
+
426
+ type WalletToViemOptions = {
427
+ client: ThirdwebClient;
428
+ chain: Chain;
429
+ wallet: Wallet;
430
+ };
431
+
432
+ function walletToViem(options: WalletToViemOptions): WalletClient {
433
+ const { wallet, chain, client } = options;
434
+
435
+ if (!wallet.getAccount()) {
436
+ throw new Error("Wallet is not connected.");
437
+ }
438
+
439
+ const rpcUrl = getRpcUrlForChain({ chain, client });
440
+ const viemChain: ViemChain = {
441
+ id: chain.id,
442
+ name: chain.name || "",
443
+ rpcUrls: {
444
+ default: { http: [rpcUrl] },
445
+ },
446
+ nativeCurrency: {
447
+ name: chain.nativeCurrency?.name || "Ether",
448
+ symbol: chain.nativeCurrency?.symbol || "ETH",
449
+ decimals: chain.nativeCurrency?.decimals || 18,
450
+ },
451
+ };
452
+
453
+ const eip1193Provider = toProvider({
454
+ chain,
455
+ client,
456
+ wallet,
457
+ });
458
+ return createWalletClient({
459
+ transport: custom({
460
+ request: (request) => eip1193Provider.request(request),
461
+ }),
462
+ account: wallet.getAccount()?.address,
463
+ chain: viemChain,
464
+ key: "thirdweb-wallet",
465
+ });
466
+ }
467
+
468
+ function walletFromViem(options: {
469
+ walletClient: WalletClient;
470
+ }): Wallet {
471
+ const viemAccount = options.walletClient.account;
472
+ if (!viemAccount) {
473
+ throw new Error(
474
+ "Account not found in walletClient, please pass it explicitly.",
475
+ );
476
+ }
477
+
478
+ const wallet = fromProvider({
479
+ provider: {
480
+ request: (request) => options.walletClient.request(request),
481
+ on: () => {},
482
+ removeListener: () => {},
483
+ },
484
+ walletId: "adapter",
485
+ });
486
+
487
+ return wallet;
488
+ }
@@ -10,7 +10,7 @@ export const arbitrumNova = /* @__PURE__ */ defineChain({
10
10
  blockExplorers: [
11
11
  {
12
12
  name: "Arbiscan",
13
- url: "https://nova-explorer.arbitrum.io/",
13
+ url: "https://nova.arbiscan.io/",
14
14
  },
15
15
  ],
16
16
  });
@@ -635,11 +635,7 @@ function SelectedTokenInfo(props: {
635
635
  placeholder="0"
636
636
  type="text"
637
637
  data-placeholder={props.tokenAmount === ""}
638
- value={
639
- props.tokenAmount
640
- ? formatNumber(Number(props.tokenAmount), 5)
641
- : "0"
642
- }
638
+ value={props.tokenAmount || "0"}
643
639
  disabled={props.disabled}
644
640
  onClick={(e) => {
645
641
  // put cursor at the end of the input
@@ -936,13 +932,15 @@ function createSupportedTokens(
936
932
  payOptions: PayUIOptions,
937
933
  supportedTokensOverrides?: SupportedTokens,
938
934
  ): SupportedTokens {
939
- const tokens: SupportedTokens = {};
935
+ // dev override
936
+ if (supportedTokensOverrides) {
937
+ return supportedTokensOverrides;
938
+ }
940
939
 
940
+ const tokens: SupportedTokens = {};
941
941
  const isBuyWithFiatDisabled = payOptions.buyWithFiat === false;
942
942
  const isBuyWithCryptoDisabled = payOptions.buyWithCrypto === false;
943
943
 
944
- // FIXME (pay) when buywithFiat is disabled, missing a bunch of tokens on base??
945
-
946
944
  for (const x of data) {
947
945
  tokens[x.chain.id] = x.tokens.filter((t) => {
948
946
  // for source tokens, data is not provided, so we include all of them
@@ -970,19 +968,6 @@ function createSupportedTokens(
970
968
  return true; // include the token
971
969
  });
972
970
  }
973
-
974
- // override with props.supportedTokens
975
- if (supportedTokensOverrides) {
976
- for (const k in supportedTokensOverrides) {
977
- const key = Number(k);
978
- const tokenList = supportedTokensOverrides[key];
979
-
980
- if (tokenList) {
981
- tokens[key] = tokenList;
982
- }
983
- }
984
- }
985
-
986
971
  return tokens;
987
972
  }
988
973
 
@@ -381,33 +381,90 @@ function TokenBalanceRow(props: {
381
381
  <StyledButton
382
382
  onClick={() => onClick(tokenBalance.token, wallet)}
383
383
  variant="secondary"
384
- style={style}
384
+ style={{
385
+ ...style,
386
+ display: "flex",
387
+ justifyContent: "space-between",
388
+ minWidth: 0, // Needed for text truncation to work
389
+ }}
385
390
  >
386
- <Container flex="row" center="y" gap="sm">
391
+ <Container
392
+ flex="row"
393
+ center="y"
394
+ gap="sm"
395
+ style={{
396
+ flex: "1 1 50%",
397
+ minWidth: 0,
398
+ maxWidth: "50%",
399
+ overflow: "hidden",
400
+ flexWrap: "nowrap",
401
+ }}
402
+ >
387
403
  <TokenIcon
388
404
  token={tokenBalance.token}
389
405
  chain={tokenBalance.chain}
390
406
  size="md"
391
407
  client={client}
392
408
  />
393
- <Container flex="column" gap="4xs">
394
- <Text size="xs" color="primaryText">
409
+ <Container flex="column" gap="4xs" style={{ minWidth: 0 }}>
410
+ <Text
411
+ size="xs"
412
+ color="primaryText"
413
+ style={{
414
+ overflow: "hidden",
415
+ textOverflow: "ellipsis",
416
+ whiteSpace: "nowrap",
417
+ }}
418
+ >
395
419
  {tokenBalance.token.symbol}
396
420
  </Text>
397
- {chainInfo && <Text size="xs">{chainInfo.name}</Text>}
421
+ {chainInfo && (
422
+ <Text
423
+ size="xs"
424
+ style={{
425
+ overflow: "hidden",
426
+ textOverflow: "ellipsis",
427
+ whiteSpace: "nowrap",
428
+ }}
429
+ >
430
+ {chainInfo.name}
431
+ </Text>
432
+ )}
398
433
  </Container>
399
434
  </Container>
400
- <Container flex="row" center="y" gap="4xs" color="secondaryText">
435
+
436
+ <Container
437
+ flex="row"
438
+ center="y"
439
+ gap="4xs"
440
+ color="secondaryText"
441
+ style={{
442
+ flex: "1 1 50%",
443
+ maxWidth: "50%",
444
+ minWidth: 0,
445
+ justifyContent: "flex-end",
446
+ flexWrap: "nowrap",
447
+ }}
448
+ >
401
449
  <Container
402
450
  flex="column"
403
451
  color="secondaryText"
404
452
  gap="4xs"
405
453
  style={{
406
- justifyContent: "flex-end",
407
454
  alignItems: "flex-end",
455
+ minWidth: 0,
456
+ overflow: "hidden",
408
457
  }}
409
458
  >
410
- <Text size="xs" color="primaryText">
459
+ <Text
460
+ size="xs"
461
+ color="primaryText"
462
+ style={{
463
+ overflow: "hidden",
464
+ textOverflow: "ellipsis",
465
+ whiteSpace: "nowrap",
466
+ }}
467
+ >
411
468
  {formatTokenBalance(tokenBalance.balance, true, 2)}
412
469
  </Text>
413
470
  <FiatValue
@@ -418,7 +475,11 @@ function TokenBalanceRow(props: {
418
475
  size="xs"
419
476
  />
420
477
  </Container>
421
- <ChevronRightIcon width={iconSize.md} height={iconSize.md} />
478
+ <ChevronRightIcon
479
+ width={iconSize.md}
480
+ height={iconSize.md}
481
+ style={{ flexShrink: 0 }}
482
+ />
422
483
  </Container>
423
484
  </StyledButton>
424
485
  );
@@ -429,6 +490,7 @@ const StyledButton = /* @__PURE__ */ styled(Button)((props) => {
429
490
  return {
430
491
  background: "transparent",
431
492
  justifyContent: "space-between",
493
+ flexWrap: "nowrap",
432
494
  flexDirection: "row",
433
495
  padding: spacing.sm,
434
496
  paddingRight: spacing.xs,
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = "5.88.6-nightly-b182302f590e75c9881cebd0ca1cc8b1425d50b8-20250218000338";
1
+ export const version = "5.88.6";