thirdweb 5.86.7-nightly-f5f8a40320d5d768d5866813f53ee4880bdf7851-20250129000319 → 5.87.1

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 (197) hide show
  1. package/dist/cjs/exports/react.js +4 -3
  2. package/dist/cjs/exports/react.js.map +1 -1
  3. package/dist/cjs/exports/react.native.js +27 -1
  4. package/dist/cjs/exports/react.native.js.map +1 -1
  5. package/dist/cjs/react/{web/ui/prebuilt/Account → core/account}/provider.js +1 -1
  6. package/dist/cjs/react/core/account/provider.js.map +1 -0
  7. package/dist/cjs/react/core/utils/account.js +105 -0
  8. package/dist/cjs/react/core/utils/account.js.map +1 -0
  9. package/dist/cjs/react/core/utils/walletIcon.js +23 -0
  10. package/dist/cjs/react/core/utils/walletIcon.js.map +1 -1
  11. package/dist/cjs/react/core/utils/walletname.js +45 -0
  12. package/dist/cjs/react/core/utils/walletname.js.map +1 -0
  13. package/dist/cjs/react/core/wallet/provider.js.map +1 -0
  14. package/dist/cjs/react/native/ui/prebuilt/Account/address.js +50 -0
  15. package/dist/cjs/react/native/ui/prebuilt/Account/address.js.map +1 -0
  16. package/dist/cjs/react/native/ui/prebuilt/Account/avatar.js +151 -0
  17. package/dist/cjs/react/native/ui/prebuilt/Account/avatar.js.map +1 -0
  18. package/dist/cjs/react/native/ui/prebuilt/Account/balance.js +130 -0
  19. package/dist/cjs/react/native/ui/prebuilt/Account/balance.js.map +1 -0
  20. package/dist/cjs/react/native/ui/prebuilt/Account/blobbie.js +58 -0
  21. package/dist/cjs/react/native/ui/prebuilt/Account/blobbie.js.map +1 -0
  22. package/dist/cjs/react/native/ui/prebuilt/Account/name.js +113 -0
  23. package/dist/cjs/react/native/ui/prebuilt/Account/name.js.map +1 -0
  24. package/dist/cjs/react/native/ui/prebuilt/Wallet/icon.js +85 -0
  25. package/dist/cjs/react/native/ui/prebuilt/Wallet/icon.js.map +1 -0
  26. package/dist/cjs/react/native/ui/prebuilt/Wallet/name.js +66 -0
  27. package/dist/cjs/react/native/ui/prebuilt/Wallet/name.js.map +1 -0
  28. package/dist/cjs/react/web/ui/ConnectWallet/Blobbie.js +2 -18
  29. package/dist/cjs/react/web/ui/ConnectWallet/Blobbie.js.map +1 -1
  30. package/dist/cjs/react/web/ui/ConnectWallet/ConnectButton.js +1 -1
  31. package/dist/cjs/react/web/ui/ConnectWallet/ConnectButton.js.map +1 -1
  32. package/dist/cjs/react/web/ui/ConnectWallet/Details.js +5 -4
  33. package/dist/cjs/react/web/ui/ConnectWallet/Details.js.map +1 -1
  34. package/dist/cjs/react/web/ui/prebuilt/Account/address.js +1 -1
  35. package/dist/cjs/react/web/ui/prebuilt/Account/address.js.map +1 -1
  36. package/dist/cjs/react/web/ui/prebuilt/Account/avatar.js +1 -1
  37. package/dist/cjs/react/web/ui/prebuilt/Account/avatar.js.map +1 -1
  38. package/dist/cjs/react/web/ui/prebuilt/Account/balance.js +8 -90
  39. package/dist/cjs/react/web/ui/prebuilt/Account/balance.js.map +1 -1
  40. package/dist/cjs/react/web/ui/prebuilt/Account/blobbie.js +1 -1
  41. package/dist/cjs/react/web/ui/prebuilt/Account/blobbie.js.map +1 -1
  42. package/dist/cjs/react/web/ui/prebuilt/Account/name.js +1 -1
  43. package/dist/cjs/react/web/ui/prebuilt/Account/name.js.map +1 -1
  44. package/dist/cjs/react/web/ui/prebuilt/Wallet/icon.js +1 -23
  45. package/dist/cjs/react/web/ui/prebuilt/Wallet/icon.js.map +1 -1
  46. package/dist/cjs/react/web/ui/prebuilt/Wallet/name.js +2 -42
  47. package/dist/cjs/react/web/ui/prebuilt/Wallet/name.js.map +1 -1
  48. package/dist/cjs/utils/shortenLargeNumber.js +3 -0
  49. package/dist/cjs/utils/shortenLargeNumber.js.map +1 -1
  50. package/dist/cjs/version.js +1 -1
  51. package/dist/cjs/version.js.map +1 -1
  52. package/dist/cjs/wallets/manager/index.js +3 -1
  53. package/dist/cjs/wallets/manager/index.js.map +1 -1
  54. package/dist/esm/exports/react.js +3 -3
  55. package/dist/esm/exports/react.js.map +1 -1
  56. package/dist/esm/exports/react.native.js +15 -0
  57. package/dist/esm/exports/react.native.js.map +1 -1
  58. package/dist/esm/react/{web/ui/prebuilt/Account → core/account}/provider.js +1 -1
  59. package/dist/esm/react/core/account/provider.js.map +1 -0
  60. package/dist/esm/react/core/utils/account.js +99 -0
  61. package/dist/esm/react/core/utils/account.js.map +1 -0
  62. package/dist/esm/react/core/utils/walletIcon.js +21 -0
  63. package/dist/esm/react/core/utils/walletIcon.js.map +1 -1
  64. package/dist/esm/react/core/utils/walletname.js +40 -0
  65. package/dist/esm/react/core/utils/walletname.js.map +1 -0
  66. package/dist/esm/react/core/wallet/provider.js.map +1 -0
  67. package/dist/esm/react/native/ui/prebuilt/Account/address.js +47 -0
  68. package/dist/esm/react/native/ui/prebuilt/Account/address.js.map +1 -0
  69. package/dist/esm/react/native/ui/prebuilt/Account/avatar.js +148 -0
  70. package/dist/esm/react/native/ui/prebuilt/Account/avatar.js.map +1 -0
  71. package/dist/esm/react/native/ui/prebuilt/Account/balance.js +127 -0
  72. package/dist/esm/react/native/ui/prebuilt/Account/balance.js.map +1 -0
  73. package/dist/esm/react/native/ui/prebuilt/Account/blobbie.js +54 -0
  74. package/dist/esm/react/native/ui/prebuilt/Account/blobbie.js.map +1 -0
  75. package/dist/esm/react/native/ui/prebuilt/Account/name.js +110 -0
  76. package/dist/esm/react/native/ui/prebuilt/Account/name.js.map +1 -0
  77. package/dist/esm/react/native/ui/prebuilt/Wallet/icon.js +81 -0
  78. package/dist/esm/react/native/ui/prebuilt/Wallet/icon.js.map +1 -0
  79. package/dist/esm/react/native/ui/prebuilt/Wallet/name.js +63 -0
  80. package/dist/esm/react/native/ui/prebuilt/Wallet/name.js.map +1 -0
  81. package/dist/esm/react/web/ui/ConnectWallet/Blobbie.js +1 -17
  82. package/dist/esm/react/web/ui/ConnectWallet/Blobbie.js.map +1 -1
  83. package/dist/esm/react/web/ui/ConnectWallet/ConnectButton.js +1 -1
  84. package/dist/esm/react/web/ui/ConnectWallet/ConnectButton.js.map +1 -1
  85. package/dist/esm/react/web/ui/ConnectWallet/Details.js +3 -2
  86. package/dist/esm/react/web/ui/ConnectWallet/Details.js.map +1 -1
  87. package/dist/esm/react/web/ui/prebuilt/Account/address.js +1 -1
  88. package/dist/esm/react/web/ui/prebuilt/Account/address.js.map +1 -1
  89. package/dist/esm/react/web/ui/prebuilt/Account/avatar.js +1 -1
  90. package/dist/esm/react/web/ui/prebuilt/Account/avatar.js.map +1 -1
  91. package/dist/esm/react/web/ui/prebuilt/Account/balance.js +6 -85
  92. package/dist/esm/react/web/ui/prebuilt/Account/balance.js.map +1 -1
  93. package/dist/esm/react/web/ui/prebuilt/Account/blobbie.js +1 -1
  94. package/dist/esm/react/web/ui/prebuilt/Account/blobbie.js.map +1 -1
  95. package/dist/esm/react/web/ui/prebuilt/Account/name.js +1 -1
  96. package/dist/esm/react/web/ui/prebuilt/Account/name.js.map +1 -1
  97. package/dist/esm/react/web/ui/prebuilt/Wallet/icon.js +1 -22
  98. package/dist/esm/react/web/ui/prebuilt/Wallet/icon.js.map +1 -1
  99. package/dist/esm/react/web/ui/prebuilt/Wallet/name.js +1 -39
  100. package/dist/esm/react/web/ui/prebuilt/Wallet/name.js.map +1 -1
  101. package/dist/esm/utils/shortenLargeNumber.js +3 -0
  102. package/dist/esm/utils/shortenLargeNumber.js.map +1 -1
  103. package/dist/esm/version.js +1 -1
  104. package/dist/esm/version.js.map +1 -1
  105. package/dist/esm/wallets/manager/index.js +3 -1
  106. package/dist/esm/wallets/manager/index.js.map +1 -1
  107. package/dist/types/exports/react.d.ts +5 -4
  108. package/dist/types/exports/react.d.ts.map +1 -1
  109. package/dist/types/exports/react.native.d.ts +15 -0
  110. package/dist/types/exports/react.native.d.ts.map +1 -1
  111. package/dist/types/react/{web/ui/prebuilt/Account → core/account}/provider.d.ts +3 -4
  112. package/dist/types/react/core/account/provider.d.ts.map +1 -0
  113. package/dist/types/react/core/utils/account.d.ts +46 -0
  114. package/dist/types/react/core/utils/account.d.ts.map +1 -0
  115. package/dist/types/react/core/utils/walletIcon.d.ts +14 -0
  116. package/dist/types/react/core/utils/walletIcon.d.ts.map +1 -1
  117. package/dist/types/react/core/utils/walletname.d.ts +26 -0
  118. package/dist/types/react/core/utils/walletname.d.ts.map +1 -0
  119. package/dist/types/react/{web/ui/prebuilt/Wallet → core/wallet}/provider.d.ts +1 -1
  120. package/dist/types/react/core/wallet/provider.d.ts.map +1 -0
  121. package/dist/types/react/native/ui/prebuilt/Account/address.d.ts +54 -0
  122. package/dist/types/react/native/ui/prebuilt/Account/address.d.ts.map +1 -0
  123. package/dist/types/react/native/ui/prebuilt/Account/avatar.d.ts +141 -0
  124. package/dist/types/react/native/ui/prebuilt/Account/avatar.d.ts.map +1 -0
  125. package/dist/types/react/native/ui/prebuilt/Account/balance.d.ts +144 -0
  126. package/dist/types/react/native/ui/prebuilt/Account/balance.d.ts.map +1 -0
  127. package/dist/types/react/native/ui/prebuilt/Account/blobbie.d.ts +34 -0
  128. package/dist/types/react/native/ui/prebuilt/Account/blobbie.d.ts.map +1 -0
  129. package/dist/types/react/native/ui/prebuilt/Account/name.d.ts +118 -0
  130. package/dist/types/react/native/ui/prebuilt/Account/name.d.ts.map +1 -0
  131. package/dist/types/react/native/ui/prebuilt/Wallet/icon.d.ts +100 -0
  132. package/dist/types/react/native/ui/prebuilt/Wallet/icon.d.ts.map +1 -0
  133. package/dist/types/react/native/ui/prebuilt/Wallet/name.d.ts +94 -0
  134. package/dist/types/react/native/ui/prebuilt/Wallet/name.d.ts.map +1 -0
  135. package/dist/types/react/web/ui/ConnectWallet/Blobbie.d.ts +1 -1
  136. package/dist/types/react/web/ui/ConnectWallet/Blobbie.d.ts.map +1 -1
  137. package/dist/types/react/web/ui/ConnectWallet/ConnectButton.d.ts.map +1 -1
  138. package/dist/types/react/web/ui/ConnectWallet/Details.d.ts +1 -1
  139. package/dist/types/react/web/ui/ConnectWallet/Details.d.ts.map +1 -1
  140. package/dist/types/react/web/ui/prebuilt/Account/avatar.d.ts.map +1 -1
  141. package/dist/types/react/web/ui/prebuilt/Account/balance.d.ts +1 -42
  142. package/dist/types/react/web/ui/prebuilt/Account/balance.d.ts.map +1 -1
  143. package/dist/types/react/web/ui/prebuilt/Account/blobbie.d.ts.map +1 -1
  144. package/dist/types/react/web/ui/prebuilt/Wallet/icon.d.ts +2 -10
  145. package/dist/types/react/web/ui/prebuilt/Wallet/icon.d.ts.map +1 -1
  146. package/dist/types/react/web/ui/prebuilt/Wallet/name.d.ts +1 -18
  147. package/dist/types/react/web/ui/prebuilt/Wallet/name.d.ts.map +1 -1
  148. package/dist/types/utils/shortenLargeNumber.d.ts.map +1 -1
  149. package/dist/types/version.d.ts +1 -1
  150. package/dist/types/version.d.ts.map +1 -1
  151. package/dist/types/wallets/manager/index.d.ts +1 -0
  152. package/dist/types/wallets/manager/index.d.ts.map +1 -1
  153. package/package.json +4 -4
  154. package/src/exports/react.native.ts +47 -0
  155. package/src/exports/react.ts +5 -3
  156. package/src/react/{web/ui/prebuilt/Account → core/account}/provider.test.tsx +1 -1
  157. package/src/react/{web/ui/prebuilt/Account → core/account}/provider.tsx +3 -5
  158. package/src/react/core/utils/account.ts +146 -0
  159. package/src/react/core/utils/walletIcon.ts +28 -0
  160. package/src/react/core/utils/walletname.ts +53 -0
  161. package/src/react/{web/ui/prebuilt/Wallet → core/wallet}/provider.tsx +1 -1
  162. package/src/react/native/ui/prebuilt/Account/address.tsx +65 -0
  163. package/src/react/native/ui/prebuilt/Account/avatar.tsx +225 -0
  164. package/src/react/native/ui/prebuilt/Account/balance.tsx +221 -0
  165. package/src/react/native/ui/prebuilt/Account/blobbie.tsx +94 -0
  166. package/src/react/native/ui/prebuilt/Account/name.tsx +180 -0
  167. package/src/react/native/ui/prebuilt/Wallet/icon.tsx +124 -0
  168. package/src/react/native/ui/prebuilt/Wallet/name.tsx +112 -0
  169. package/src/react/web/ui/ConnectWallet/Blobbie.tsx +1 -18
  170. package/src/react/web/ui/ConnectWallet/ConnectButton.tsx +1 -1
  171. package/src/react/web/ui/ConnectWallet/Details.test.tsx +1 -1
  172. package/src/react/web/ui/ConnectWallet/Details.tsx +7 -7
  173. package/src/react/web/ui/prebuilt/Account/address.test.tsx +1 -1
  174. package/src/react/web/ui/prebuilt/Account/address.tsx +1 -1
  175. package/src/react/web/ui/prebuilt/Account/avatar.test.tsx +1 -1
  176. package/src/react/web/ui/prebuilt/Account/avatar.tsx +1 -2
  177. package/src/react/web/ui/prebuilt/Account/balance.test.tsx +7 -5
  178. package/src/react/web/ui/prebuilt/Account/balance.tsx +10 -130
  179. package/src/react/web/ui/prebuilt/Account/blobbie.tsx +1 -1
  180. package/src/react/web/ui/prebuilt/Account/name.test.tsx +1 -1
  181. package/src/react/web/ui/prebuilt/Account/name.tsx +1 -1
  182. package/src/react/web/ui/prebuilt/Wallet/icon.test.tsx +3 -2
  183. package/src/react/web/ui/prebuilt/Wallet/icon.tsx +6 -30
  184. package/src/react/web/ui/prebuilt/Wallet/name.test.tsx +6 -2
  185. package/src/react/web/ui/prebuilt/Wallet/name.tsx +2 -52
  186. package/src/utils/shortenLargeNumber.ts +3 -0
  187. package/src/version.ts +1 -1
  188. package/src/wallets/manager/index.ts +4 -1
  189. package/dist/cjs/react/web/ui/prebuilt/Account/provider.js.map +0 -1
  190. package/dist/cjs/react/web/ui/prebuilt/Wallet/provider.js.map +0 -1
  191. package/dist/esm/react/web/ui/prebuilt/Account/provider.js.map +0 -1
  192. package/dist/esm/react/web/ui/prebuilt/Wallet/provider.js.map +0 -1
  193. package/dist/types/react/web/ui/prebuilt/Account/provider.d.ts.map +0 -1
  194. package/dist/types/react/web/ui/prebuilt/Wallet/provider.d.ts.map +0 -1
  195. /package/dist/cjs/react/{web/ui/prebuilt/Wallet → core/wallet}/provider.js +0 -0
  196. /package/dist/esm/react/{web/ui/prebuilt/Wallet → core/wallet}/provider.js +0 -0
  197. /package/src/react/{web/ui/prebuilt/Wallet → core/wallet}/provider.test.tsx +0 -0
@@ -0,0 +1,112 @@
1
+ "use client";
2
+
3
+ import type { UseQueryOptions } from "@tanstack/react-query";
4
+ import { Text, type TextProps } from "react-native";
5
+ import { useWalletName } from "../../../../core/utils/walletname.js";
6
+ /**
7
+ * Props for the WalletName component
8
+ * @component
9
+ * @wallet
10
+ */
11
+ export interface WalletNameProps extends Omit<TextProps, "children"> {
12
+ /**
13
+ * This component will be shown while the name of the wallet name is being fetched
14
+ * If not passed, the component will return `null`.
15
+ *
16
+ * You can/should pass a loading sign or spinner to this prop.
17
+ * @example
18
+ * ```tsx
19
+ * <WalletName loadingComponent={<Spinner />} />
20
+ * ```
21
+ */
22
+ loadingComponent?: React.ComponentType;
23
+ /**
24
+ * This component will be shown if the name fails to be retreived
25
+ * If not passed, the component will return `null`.
26
+ *
27
+ * You can/should pass a descriptive text/component to this prop, indicating that the
28
+ * name was not fetched succesfully
29
+ * @example
30
+ * ```tsx
31
+ * <WalletName fallbackComponent={<span>Failed to load</span>}
32
+ * />
33
+ * ```
34
+ */
35
+ fallbackComponent?: React.ComponentType;
36
+ /**
37
+ * Optional `useQuery` params
38
+ */
39
+ queryOptions?: Omit<UseQueryOptions<string>, "queryFn" | "queryKey">;
40
+ /**
41
+ * A function to format the name's display value
42
+ * ```tsx
43
+ * <WalletName formatFn={(str: string) => doSomething()} />
44
+ * ```
45
+ */
46
+ formatFn?: (str: string) => string;
47
+ }
48
+
49
+ /**
50
+ * This component fetches then shows the name of a wallet.
51
+ * It inherits all the attributes of a HTML <span> component, hence you can style it just like how you would style a normal <span>
52
+ *
53
+ * @example
54
+ * ### Basic usage
55
+ * ```tsx
56
+ * import { WalletProvider, WalletName } from "thirdweb/react";
57
+ *
58
+ * <WalletProvider id="io.metamask">
59
+ * <WalletName />
60
+ * </WalletProvider>
61
+ * ```
62
+ * Result:
63
+ * ```html
64
+ * <span>MetaMask</span>
65
+ * ```
66
+ *
67
+ * ### Show a loading sign when the name is being fetched
68
+ * ```tsx
69
+ * import { WalletProvider, WalletName } from "thirdweb/react";
70
+ *
71
+ * <WalletProvider {...props}>
72
+ * <WalletName loadingComponent={<Spinner />} />
73
+ * </WalletProvider>
74
+ * ```
75
+ *
76
+ * ### Fallback to something when the name fails to resolve
77
+ * ```tsx
78
+ * <WalletProvider {...props}>
79
+ * <WalletName fallbackComponent={<span>Failed to load</span>} />
80
+ * </WalletProvider>
81
+ * ```
82
+ *
83
+ * ### Custom query options for useQuery
84
+ * This component uses `@tanstack-query`'s useQuery internally.
85
+ * You can use the `queryOptions` prop for more fine-grained control
86
+ * ```tsx
87
+ * <WalletName
88
+ * queryOptions={{
89
+ * enabled: isEnabled,
90
+ * retry: 4,
91
+ * }}
92
+ * />
93
+ * @component
94
+ * @beta
95
+ * @wallet
96
+ */
97
+ export function WalletName({
98
+ loadingComponent,
99
+ fallbackComponent,
100
+ queryOptions,
101
+ formatFn,
102
+ ...restProps
103
+ }: WalletNameProps) {
104
+ const nameQuery = useWalletName({ queryOptions, formatFn });
105
+ if (nameQuery.isLoading) {
106
+ return loadingComponent || null;
107
+ }
108
+ if (!nameQuery.data) {
109
+ return fallbackComponent || null;
110
+ }
111
+ return <Text {...restProps}>{nameQuery.data}</Text>;
112
+ }
@@ -1,24 +1,7 @@
1
1
  "use client";
2
2
  import { hexToNumber } from "@noble/curves/abstract/utils";
3
3
  import { useId, useMemo } from "react";
4
-
5
- const COLOR_OPTIONS = [
6
- ["#fca5a5", "#b91c1c"],
7
- ["#fdba74", "#c2410c"],
8
- ["#fcd34d", "#b45309"],
9
- ["#fde047", "#a16207"],
10
- ["#a3e635", "#4d7c0f"],
11
- ["#86efac", "#15803d"],
12
- ["#67e8f9", "#0e7490"],
13
- ["#7dd3fc", "#0369a1"],
14
- ["#93c5fd", "#1d4ed8"],
15
- ["#a5b4fc", "#4338ca"],
16
- ["#c4b5fd", "#6d28d9"],
17
- ["#d8b4fe", "#7e22ce"],
18
- ["#f0abfc", "#a21caf"],
19
- ["#f9a8d4", "#be185d"],
20
- ["#fda4af", "#be123c"],
21
- ];
4
+ import { COLOR_OPTIONS } from "../../../core/utils/account.js";
22
5
 
23
6
  /**
24
7
  * Props for the Blobbie component
@@ -3,6 +3,7 @@
3
3
  import styled from "@emotion/styled";
4
4
  import { useEffect, useMemo, useState } from "react";
5
5
  import { getDefaultWallets } from "../../../../wallets/defaultWallets.js";
6
+ import { AccountProvider } from "../../../core/account/provider.js";
6
7
  import { iconSize } from "../../../core/design-system/index.js";
7
8
  import { useSiweAuth } from "../../../core/hooks/auth/useSiweAuth.js";
8
9
  import type { ConnectButtonProps } from "../../../core/hooks/connection/ConnectButtonProps.js";
@@ -23,7 +24,6 @@ import { Spinner } from "../components/Spinner.js";
23
24
  import { Container } from "../components/basic.js";
24
25
  import { Button } from "../components/buttons.js";
25
26
  import { fadeInAnimation } from "../design-system/animations.js";
26
- import { AccountProvider } from "../prebuilt/Account/provider.js";
27
27
  import { ConnectedWalletDetails } from "./Details.js";
28
28
  import ConnectModal from "./Modal/ConnectModal.js";
29
29
  import { LockIcon } from "./icons/LockIcon.js";
@@ -14,8 +14,8 @@ import { base } from "../../../../chains/chain-definitions/base.js";
14
14
  import { ethereum } from "../../../../chains/chain-definitions/ethereum.js";
15
15
  import { useActiveAccount } from "../../../../react/core/hooks/wallets/useActiveAccount.js";
16
16
  import { useActiveWalletChain } from "../../../../react/core/hooks/wallets/useActiveWalletChain.js";
17
+ import { AccountProvider } from "../../../core/account/provider.js";
17
18
  import { ThirdwebProvider } from "../../providers/thirdweb-provider.js";
18
- import { AccountProvider } from "../prebuilt/Account/provider.js";
19
19
  import {
20
20
  ConnectedToSmartWallet,
21
21
  ConnectedWalletDetails,
@@ -40,6 +40,7 @@ import type {
40
40
  EcosystemWalletId,
41
41
  WalletId,
42
42
  } from "../../../../wallets/wallet-types.js";
43
+ import { AccountProvider } from "../../../core/account/provider.js";
43
44
  import {
44
45
  CustomThemeProvider,
45
46
  parseTheme,
@@ -67,6 +68,11 @@ import { useAdminWallet } from "../../../core/hooks/wallets/useAdminWallet.js";
67
68
  import { useDisconnect } from "../../../core/hooks/wallets/useDisconnect.js";
68
69
  import { useSwitchActiveWalletChain } from "../../../core/hooks/wallets/useSwitchActiveWalletChain.js";
69
70
  import { SetRootElementContext } from "../../../core/providers/RootElementContext.js";
71
+ import {
72
+ type AccountBalanceInfo,
73
+ formatAccountFiatBalance,
74
+ formatAccountTokenBalance,
75
+ } from "../../../core/utils/account.js";
70
76
  import type {
71
77
  SupportedNFTs,
72
78
  SupportedTokens,
@@ -91,15 +97,9 @@ import { fadeInAnimation } from "../design-system/animations.js";
91
97
  import { StyledButton } from "../design-system/elements.js";
92
98
  import { AccountAddress } from "../prebuilt/Account/address.js";
93
99
  import { AccountAvatar } from "../prebuilt/Account/avatar.js";
94
- import {
95
- AccountBalance,
96
- type AccountBalanceInfo,
97
- formatAccountFiatBalance,
98
- formatAccountTokenBalance,
99
- } from "../prebuilt/Account/balance.js";
100
+ import { AccountBalance } from "../prebuilt/Account/balance.js";
100
101
  import { AccountBlobbie } from "../prebuilt/Account/blobbie.js";
101
102
  import { AccountName } from "../prebuilt/Account/name.js";
102
- import { AccountProvider } from "../prebuilt/Account/provider.js";
103
103
  import { ChainIcon } from "../prebuilt/Chain/icon.js";
104
104
  import { ChainName } from "../prebuilt/Chain/name.js";
105
105
  import { ChainProvider } from "../prebuilt/Chain/provider.js";
@@ -2,8 +2,8 @@ import { describe, expect, it } from "vitest";
2
2
  import { render, screen, waitFor } from "~test/react-render.js";
3
3
  import { TEST_CLIENT } from "~test/test-clients.js";
4
4
  import { shortenAddress } from "../../../../../utils/address.js";
5
+ import { AccountProvider } from "../../../../core/account/provider.js";
5
6
  import { AccountAddress } from "./address.js";
6
- import { AccountProvider } from "./provider.js";
7
7
 
8
8
  describe.runIf(process.env.TW_SECRET_KEY)("AccountAddress component", () => {
9
9
  it("should format the address properly", () => {
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
 
3
- import { useAccountContext } from "./provider.js";
3
+ import { useAccountContext } from "../../../../core/account/provider.js";
4
4
 
5
5
  /**
6
6
  * @component
@@ -2,8 +2,8 @@ import { describe, expect, it } from "vitest";
2
2
  import { render, screen, waitFor } from "~test/react-render.js";
3
3
  import { TEST_CLIENT } from "~test/test-clients.js";
4
4
  import { TEST_ACCOUNT_A } from "~test/test-wallets.js";
5
+ import { AccountProvider } from "../../../../core/account/provider.js";
5
6
  import { AccountAvatar } from "./avatar.js";
6
- import { AccountProvider } from "./provider.js";
7
7
 
8
8
  describe.runIf(process.env.TW_SECRET_KEY)("AccountAvatar component", () => {
9
9
  it("should render an image", () => {
@@ -11,8 +11,7 @@ import {
11
11
  import { getSocialProfiles } from "../../../../../social/profiles.js";
12
12
  import type { SocialProfile } from "../../../../../social/types.js";
13
13
  import { parseAvatarRecord } from "../../../../../utils/ens/avatar.js";
14
- import { useAccountContext } from "./provider.js";
15
-
14
+ import { useAccountContext } from "../../../../core/account/provider.js";
16
15
  /**
17
16
  * Props for the AccountAvatar component
18
17
  * @component
@@ -7,13 +7,13 @@ import { ethereum } from "../../../../../chains/chain-definitions/ethereum.js";
7
7
  import { sepolia } from "../../../../../chains/chain-definitions/sepolia.js";
8
8
  import { defineChain } from "../../../../../chains/utils.js";
9
9
  import { NATIVE_TOKEN_ADDRESS } from "../../../../../constants/addresses.js";
10
+ import { AccountProvider } from "../../../../core/account/provider.js";
10
11
  import {
11
- AccountBalance,
12
12
  formatAccountFiatBalance,
13
13
  formatAccountTokenBalance,
14
14
  loadAccountBalance,
15
- } from "./balance.js";
16
- import { AccountProvider } from "./provider.js";
15
+ } from "../../../../core/utils/account.js";
16
+ import { AccountBalance } from "./balance.js";
17
17
 
18
18
  const queryClient = new QueryClient();
19
19
 
@@ -95,7 +95,8 @@ describe.runIf(process.env.TW_SECRET_KEY)("AccountBalance component", () => {
95
95
  await expect(() =>
96
96
  loadAccountBalance({
97
97
  client: TEST_CLIENT,
98
- address: "haha",
98
+ // biome-ignore lint/suspicious/noExplicitAny: for the test
99
+ address: "haha" as any,
99
100
  chain: ethereum,
100
101
  }),
101
102
  ).rejects.toThrowError("Invalid wallet address. Expected an EVM address");
@@ -106,7 +107,8 @@ describe.runIf(process.env.TW_SECRET_KEY)("AccountBalance component", () => {
106
107
  loadAccountBalance({
107
108
  client: TEST_CLIENT,
108
109
  address: VITALIK_WALLET,
109
- tokenAddress: "haha",
110
+ // biome-ignore lint/suspicious/noExplicitAny: for the test
111
+ tokenAddress: "haha" as any,
110
112
  chain: ethereum,
111
113
  }),
112
114
  ).rejects.toThrowError(
@@ -1,35 +1,19 @@
1
1
  "use client";
2
2
 
3
3
  import { type UseQueryOptions, useQuery } from "@tanstack/react-query";
4
- import type { Address } from "abitype";
5
4
  import type React from "react";
6
5
  import type { JSX } from "react";
7
6
  import type { Chain } from "../../../../../chains/types.js";
8
- import type { ThirdwebClient } from "../../../../../client/client.js";
9
- import { NATIVE_TOKEN_ADDRESS } from "../../../../../constants/addresses.js";
10
- import { convertCryptoToFiat } from "../../../../../exports/pay.js";
11
7
  import type { SupportedFiatCurrency } from "../../../../../pay/convert/type.js";
12
8
  import { useActiveWalletChain } from "../../../../../react/core/hooks/wallets/useActiveWalletChain.js";
13
- import { isAddress } from "../../../../../utils/address.js";
14
- import { formatNumber } from "../../../../../utils/formatNumber.js";
15
- import { shortenLargeNumber } from "../../../../../utils/shortenLargeNumber.js";
16
- import { getWalletBalance } from "../../../../../wallets/utils/getWalletBalance.js";
17
- import { useAccountContext } from "./provider.js";
18
-
19
- /**
20
- * @component
21
- * @wallet
22
- */
23
- export type AccountBalanceInfo = {
24
- /**
25
- * Represents either token balance or fiat balance.
26
- */
27
- balance: number;
28
- /**
29
- * Represents either token symbol or fiat symbol
30
- */
31
- symbol: string;
32
- };
9
+ import { getAddress } from "../../../../../utils/address.js";
10
+ import { useAccountContext } from "../../../../core/account/provider.js";
11
+ import {
12
+ type AccountBalanceInfo,
13
+ formatAccountFiatBalance,
14
+ loadAccountBalance,
15
+ } from "../../../../core/utils/account.js";
16
+ import { formatAccountTokenBalance } from "../../../../core/utils/account.js";
33
17
 
34
18
  /**
35
19
  * Props for the AccountBalance component
@@ -199,8 +183,8 @@ export function AccountBalance({
199
183
  loadAccountBalance({
200
184
  chain: chainToLoad,
201
185
  client,
202
- address,
203
- tokenAddress,
186
+ address: getAddress(address),
187
+ tokenAddress: tokenAddress ? getAddress(tokenAddress) : undefined,
204
188
  showBalanceInFiat,
205
189
  }),
206
190
  retry: false,
@@ -237,107 +221,3 @@ export function AccountBalance({
237
221
  </span>
238
222
  );
239
223
  }
240
-
241
- /**
242
- * @internal Exported for tests
243
- */
244
- export async function loadAccountBalance(props: {
245
- chain?: Chain;
246
- client: ThirdwebClient;
247
- address: Address;
248
- tokenAddress?: Address;
249
- showBalanceInFiat?: SupportedFiatCurrency;
250
- }): Promise<AccountBalanceInfo> {
251
- const { chain, client, address, tokenAddress, showBalanceInFiat } = props;
252
- if (!chain) {
253
- throw new Error("chain is required");
254
- }
255
-
256
- if (
257
- tokenAddress &&
258
- tokenAddress?.toLowerCase() === NATIVE_TOKEN_ADDRESS.toLowerCase()
259
- ) {
260
- throw new Error(`Invalid tokenAddress - cannot be ${NATIVE_TOKEN_ADDRESS}`);
261
- }
262
-
263
- if (!isAddress(address)) {
264
- throw new Error("Invalid wallet address. Expected an EVM address");
265
- }
266
-
267
- if (tokenAddress && !isAddress(tokenAddress)) {
268
- throw new Error("Invalid tokenAddress. Expected an EVM contract address");
269
- }
270
-
271
- const tokenBalanceData = await getWalletBalance({
272
- chain,
273
- client,
274
- address,
275
- tokenAddress,
276
- }).catch(() => undefined);
277
-
278
- if (!tokenBalanceData) {
279
- throw new Error(
280
- `Failed to retrieve ${tokenAddress ? `token: ${tokenAddress}` : "native token"} balance for address: ${address} on chainId:${chain.id}`,
281
- );
282
- }
283
-
284
- if (showBalanceInFiat) {
285
- const fiatData = await convertCryptoToFiat({
286
- fromAmount: Number(tokenBalanceData.displayValue),
287
- fromTokenAddress: tokenAddress || NATIVE_TOKEN_ADDRESS,
288
- to: showBalanceInFiat,
289
- chain,
290
- client,
291
- }).catch(() => undefined);
292
-
293
- if (fiatData === undefined) {
294
- throw new Error(
295
- `Failed to resolve fiat value for ${tokenAddress ? `token: ${tokenAddress}` : "native token"} on chainId: ${chain.id}`,
296
- );
297
- }
298
- return {
299
- balance: fiatData?.result,
300
- symbol:
301
- new Intl.NumberFormat("en", {
302
- style: "currency",
303
- currency: showBalanceInFiat,
304
- minimumFractionDigits: 0,
305
- maximumFractionDigits: 0,
306
- })
307
- .formatToParts(0)
308
- .find((p) => p.type === "currency")?.value ||
309
- showBalanceInFiat.toUpperCase(),
310
- };
311
- }
312
-
313
- return {
314
- balance: Number(tokenBalanceData.displayValue),
315
- symbol: tokenBalanceData.symbol,
316
- };
317
- }
318
-
319
- /**
320
- * Format the display balance for both crypto and fiat, in the Details button and Modal
321
- * If both crypto balance and fiat balance exist, we have to keep the string very short to avoid UI issues.
322
- * @internal
323
- * Used internally for the Details button and the Details Modal
324
- */
325
- export function formatAccountTokenBalance(
326
- props: AccountBalanceInfo & { decimals: number },
327
- ): string {
328
- const formattedTokenBalance = formatNumber(props.balance, props.decimals);
329
- return `${formattedTokenBalance} ${props.symbol}`;
330
- }
331
-
332
- /**
333
- * Used internally for the Details button and Details Modal
334
- * @internal
335
- */
336
- export function formatAccountFiatBalance(
337
- props: AccountBalanceInfo & { decimals: number },
338
- ) {
339
- const num = formatNumber(props.balance, props.decimals);
340
- // Need to keep them short to avoid UI overflow issues
341
- const formattedFiatBalance = shortenLargeNumber(num);
342
- return `${props.symbol}${formattedFiatBalance}`;
343
- }
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
 
3
+ import { useAccountContext } from "../../../../core/account/provider.js";
3
4
  import { Blobbie, type BlobbieProps } from "../../ConnectWallet/Blobbie.js";
4
- import { useAccountContext } from "./provider.js";
5
5
 
6
6
  /**
7
7
  * A wrapper for the Blobbie component
@@ -1,8 +1,8 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
  import { render, screen, waitFor } from "~test/react-render.js";
3
3
  import { TEST_CLIENT } from "~test/test-clients.js";
4
+ import { AccountProvider } from "../../../../core/account/provider.js";
4
5
  import { AccountName } from "./name.js";
5
- import { AccountProvider } from "./provider.js";
6
6
 
7
7
  describe.runIf(process.env.TW_SECRET_KEY)("AccountName component", () => {
8
8
  it("should return the correct social name", () => {
@@ -9,7 +9,7 @@ import {
9
9
  } from "../../../../../extensions/ens/resolve-name.js";
10
10
  import { getSocialProfiles } from "../../../../../social/profiles.js";
11
11
  import type { SocialProfile } from "../../../../../social/types.js";
12
- import { useAccountContext } from "./provider.js";
12
+ import { useAccountContext } from "../../../../core/account/provider.js";
13
13
 
14
14
  /**
15
15
  * Props for the AccountName component
@@ -1,7 +1,8 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
  import { render, waitFor } from "~test/react-render.js";
3
- import { SocialIcon, WalletIcon, fetchWalletImage } from "./icon.js";
4
- import { WalletProvider } from "./provider.js";
3
+ import { fetchWalletImage } from "../../../../core/utils/walletIcon.js";
4
+ import { WalletProvider } from "../../../../core/wallet/provider.js";
5
+ import { SocialIcon, WalletIcon } from "./icon.js";
5
6
 
6
7
  describe("WalletIcon", () => {
7
8
  it("should fetch wallet image", async () => {
@@ -1,12 +1,12 @@
1
1
  "use client";
2
2
 
3
- import { type UseQueryOptions, useQuery } from "@tanstack/react-query";
3
+ import type { UseQueryOptions } from "@tanstack/react-query";
4
4
  import type { JSX } from "react";
5
- import { getWalletInfo } from "../../../../../wallets/__generated__/getWalletInfo.js";
6
5
  import type { AuthOption } from "../../../../../wallets/types.js";
7
- import type { WalletId } from "../../../../../wallets/wallet-types.js";
8
- import { getSocialIcon } from "../../../../core/utils/walletIcon.js";
9
- import { useWalletContext } from "./provider.js";
6
+ import {
7
+ getSocialIcon,
8
+ useWalletIcon,
9
+ } from "../../../../core/utils/walletIcon.js";
10
10
 
11
11
  export interface WalletIconProps
12
12
  extends Omit<React.ImgHTMLAttributes<HTMLImageElement>, "src"> {
@@ -96,31 +96,7 @@ export function WalletIcon({
96
96
  return <img src={imageQuery.data} {...restProps} alt={restProps.alt} />;
97
97
  }
98
98
 
99
- /**
100
- * @internal
101
- */
102
- function useWalletIcon(props: {
103
- queryOptions?: Omit<UseQueryOptions<string>, "queryFn" | "queryKey">;
104
- }) {
105
- const { id } = useWalletContext();
106
- const imageQuery = useQuery({
107
- queryKey: ["walletIcon", id],
108
- queryFn: async () => fetchWalletImage({ id }),
109
- ...props.queryOptions,
110
- });
111
- return imageQuery;
112
- }
113
-
114
- /**
115
- * @internal Exported for tests only
116
- */
117
- export async function fetchWalletImage(props: {
118
- id: WalletId;
119
- }) {
120
- return getWalletInfo(props.id, true);
121
- }
122
-
123
- interface SocialIconProps
99
+ export interface SocialIconProps
124
100
  extends Omit<React.ImgHTMLAttributes<HTMLImageElement>, "src"> {
125
101
  provider: AuthOption | string;
126
102
  }
@@ -1,8 +1,12 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
  import { render, waitFor } from "~test/react-render.js";
3
3
  import { getFunctionId } from "../../../../../utils/function-id.js";
4
- import { WalletName, fetchWalletName, getQueryKeys } from "./name.js";
5
- import { WalletProvider } from "./provider.js";
4
+ import {
5
+ fetchWalletName,
6
+ getQueryKeys,
7
+ } from "../../../../core/utils/walletname.js";
8
+ import { WalletProvider } from "../../../../core/wallet/provider.js";
9
+ import { WalletName } from "./name.js";
6
10
 
7
11
  describe.runIf(process.env.TW_SECRET_KEY)("WalletName", () => {
8
12
  it("fetchWalletName: should fetch wallet name from id", async () => {
@@ -1,11 +1,8 @@
1
1
  "use client";
2
2
 
3
- import { type UseQueryOptions, useQuery } from "@tanstack/react-query";
3
+ import type { UseQueryOptions } from "@tanstack/react-query";
4
4
  import type { JSX } from "react";
5
- import { getFunctionId } from "../../../../../utils/function-id.js";
6
- import { getWalletInfo } from "../../../../../wallets/__generated__/getWalletInfo.js";
7
- import type { WalletId } from "../../../../../wallets/wallet-types.js";
8
- import { useWalletContext } from "./provider.js";
5
+ import { useWalletName } from "../../../../core/utils/walletname.js";
9
6
 
10
7
  /**
11
8
  * Props for the WalletName component
@@ -115,50 +112,3 @@ export function WalletName({
115
112
  }
116
113
  return <span {...restProps}>{nameQuery.data}</span>;
117
114
  }
118
-
119
- /**
120
- * @internal
121
- */
122
- function useWalletName(props: {
123
- formatFn?: (str: string) => string;
124
- queryOptions?: Omit<UseQueryOptions<string>, "queryFn" | "queryKey">;
125
- }) {
126
- const { id } = useWalletContext();
127
- const nameQuery = useQuery({
128
- queryKey: getQueryKeys({ id, formatFn: props.formatFn }),
129
- queryFn: async () => fetchWalletName({ id, formatFn: props.formatFn }),
130
- ...props.queryOptions,
131
- });
132
- return nameQuery;
133
- }
134
-
135
- /**
136
- * @internal Exported for tests only
137
- */
138
- export function getQueryKeys(props: {
139
- id: WalletId;
140
- formatFn?: (str: string) => string;
141
- }) {
142
- if (typeof props.formatFn === "function") {
143
- return [
144
- "walletName",
145
- props.id,
146
- { resolver: getFunctionId(props.formatFn) },
147
- ] as const;
148
- }
149
- return ["walletName", props.id] as const;
150
- }
151
-
152
- /**
153
- * @internal Exported for tests only
154
- */
155
- export async function fetchWalletName(props: {
156
- id: WalletId;
157
- formatFn?: (str: string) => string;
158
- }) {
159
- const info = await getWalletInfo(props.id);
160
- if (typeof props.formatFn === "function") {
161
- return props.formatFn(info.name);
162
- }
163
- return info.name;
164
- }
@@ -13,6 +13,9 @@
13
13
  * @utils
14
14
  */
15
15
  export function shortenLargeNumber(value: number) {
16
+ if (value === 0) {
17
+ return "0.00";
18
+ }
16
19
  if (value < 1000) {
17
20
  return value.toString();
18
21
  }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = "5.86.7-nightly-f5f8a40320d5d768d5866813f53ee4880bdf7851-20250129000319";
1
+ export const version = "5.87.1";
@@ -24,6 +24,7 @@ export type ConnectionManager = ReturnType<typeof createConnectionManager>;
24
24
  export type ConnectManagerOptions = {
25
25
  client: ThirdwebClient;
26
26
  accountAbstraction?: SmartWalletOptions;
27
+ setWalletAsActive?: boolean;
27
28
  onConnect?: (wallet: Wallet) => void;
28
29
  };
29
30
 
@@ -146,7 +147,9 @@ export function createConnectionManager(storage: AsyncStorage) {
146
147
  // add personal wallet to connected wallets list even if it's not the active one
147
148
  addConnectedWallet(wallet);
148
149
 
149
- handleSetActiveWallet(activeWallet);
150
+ if (options?.setWalletAsActive !== false) {
151
+ handleSetActiveWallet(activeWallet);
152
+ }
150
153
 
151
154
  wallet.subscribe("accountChanged", async () => {
152
155
  // We reimplement connect here to prevent memory leaks
@@ -1 +0,0 @@
1
- {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../../../../../src/react/web/ui/prebuilt/Account/provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;AAgDb,0CAaC;AAKD,8CAQC;;AAtED,iCAAkD;AAmBlD,MAAM,sBAAsB,GAAG,eAAe,CAAC,IAAA,qBAAa,EAE1D,SAAS,CAAC,CAAC;AAEb;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,eAAe,CAC7B,KAAoD;IAEpD,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CACb,iGAAiG,CAClG,CAAC;IACJ,CAAC;IACD,OAAO,CACL,uBAAC,sBAAsB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAC1C,KAAK,CAAC,QAAQ,GACiB,CACnC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,iBAAiB;IAC/B,MAAM,GAAG,GAAG,IAAA,kBAAU,EAAC,sBAAsB,CAAC,CAAC;IAC/C,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CACb,oIAAoI,CACrI,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../../../../../src/react/web/ui/prebuilt/Wallet/provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;AA0Cb,wCAQC;AAKD,4CAQC;;AA5DD,iCAAkD;AAYlD;;GAEG;AACU,QAAA,qBAAqB,GAAmB,IAAA,qBAAa,EAEhE,SAAS,CAAC,CAAC;AAEb;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,cAAc,CAC5B,KAAmD;IAEnD,OAAO,CACL,uBAAC,6BAAqB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YACzC,KAAK,CAAC,QAAQ,GACgB,CAClC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,gBAAgB;IAC9B,MAAM,GAAG,GAAG,IAAA,kBAAU,EAAC,6BAAqB,CAAC,CAAC;IAC9C,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CACb,6HAA6H,CAC9H,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}