thirdweb 5.33.0 → 5.34.0-nightly-f6ff5a78fc2d65f0f250b154f1405210ca57ce0a-20240706000322

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 (78) hide show
  1. package/dist/cjs/extensions/erc721/read/getOwnedTokenIds.js +13 -4
  2. package/dist/cjs/extensions/erc721/read/getOwnedTokenIds.js.map +1 -1
  3. package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js +2 -3
  4. package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
  5. package/dist/cjs/react/core/utils/defaultTokens.js.map +1 -1
  6. package/dist/cjs/react/web/hooks/transaction/useSendTransaction.js +8 -5
  7. package/dist/cjs/react/web/hooks/transaction/useSendTransaction.js.map +1 -1
  8. package/dist/cjs/react/web/ui/ConnectWallet/ConnectButton.js +1 -1
  9. package/dist/cjs/react/web/ui/ConnectWallet/ConnectButton.js.map +1 -1
  10. package/dist/cjs/react/web/ui/ConnectWallet/Details.js +24 -4
  11. package/dist/cjs/react/web/ui/ConnectWallet/Details.js.map +1 -1
  12. package/dist/cjs/react/web/ui/ConnectWallet/icons/ImageIcon.js +12 -0
  13. package/dist/cjs/react/web/ui/ConnectWallet/icons/ImageIcon.js.map +1 -0
  14. package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewFunds.js +12 -30
  15. package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewFunds.js.map +1 -1
  16. package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewNFTs.js +142 -0
  17. package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewNFTs.js.map +1 -0
  18. package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewTokens.js +48 -0
  19. package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewTokens.js.map +1 -0
  20. package/dist/cjs/version.js +1 -1
  21. package/dist/cjs/version.js.map +1 -1
  22. package/dist/esm/extensions/erc721/read/getOwnedTokenIds.js +14 -5
  23. package/dist/esm/extensions/erc721/read/getOwnedTokenIds.js.map +1 -1
  24. package/dist/esm/react/core/hooks/transaction/useSendTransaction.js +2 -3
  25. package/dist/esm/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
  26. package/dist/esm/react/core/utils/defaultTokens.js.map +1 -1
  27. package/dist/esm/react/web/hooks/transaction/useSendTransaction.js +8 -5
  28. package/dist/esm/react/web/hooks/transaction/useSendTransaction.js.map +1 -1
  29. package/dist/esm/react/web/ui/ConnectWallet/ConnectButton.js +1 -1
  30. package/dist/esm/react/web/ui/ConnectWallet/ConnectButton.js.map +1 -1
  31. package/dist/esm/react/web/ui/ConnectWallet/Details.js +24 -4
  32. package/dist/esm/react/web/ui/ConnectWallet/Details.js.map +1 -1
  33. package/dist/esm/react/web/ui/ConnectWallet/icons/ImageIcon.js +8 -0
  34. package/dist/esm/react/web/ui/ConnectWallet/icons/ImageIcon.js.map +1 -0
  35. package/dist/esm/react/web/ui/ConnectWallet/screens/ViewFunds.js +13 -31
  36. package/dist/esm/react/web/ui/ConnectWallet/screens/ViewFunds.js.map +1 -1
  37. package/dist/esm/react/web/ui/ConnectWallet/screens/ViewNFTs.js +139 -0
  38. package/dist/esm/react/web/ui/ConnectWallet/screens/ViewNFTs.js.map +1 -0
  39. package/dist/esm/react/web/ui/ConnectWallet/screens/ViewTokens.js +45 -0
  40. package/dist/esm/react/web/ui/ConnectWallet/screens/ViewTokens.js.map +1 -0
  41. package/dist/esm/version.js +1 -1
  42. package/dist/esm/version.js.map +1 -1
  43. package/dist/types/extensions/erc721/read/getOwnedTokenIds.d.ts.map +1 -1
  44. package/dist/types/react/core/hooks/connection/ConnectButtonProps.d.ts +25 -1
  45. package/dist/types/react/core/hooks/connection/ConnectButtonProps.d.ts.map +1 -1
  46. package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts +2 -1
  47. package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts.map +1 -1
  48. package/dist/types/react/core/utils/defaultTokens.d.ts +2 -0
  49. package/dist/types/react/core/utils/defaultTokens.d.ts.map +1 -1
  50. package/dist/types/react/web/hooks/transaction/useSendTransaction.d.ts.map +1 -1
  51. package/dist/types/react/web/ui/ConnectWallet/Details.d.ts +28 -1
  52. package/dist/types/react/web/ui/ConnectWallet/Details.d.ts.map +1 -1
  53. package/dist/types/react/web/ui/ConnectWallet/icons/ImageIcon.d.ts +6 -0
  54. package/dist/types/react/web/ui/ConnectWallet/icons/ImageIcon.d.ts.map +1 -0
  55. package/dist/types/react/web/ui/ConnectWallet/screens/ViewFunds.d.ts +5 -2
  56. package/dist/types/react/web/ui/ConnectWallet/screens/ViewFunds.d.ts.map +1 -1
  57. package/dist/types/react/web/ui/ConnectWallet/screens/ViewNFTs.d.ts +13 -0
  58. package/dist/types/react/web/ui/ConnectWallet/screens/ViewNFTs.d.ts.map +1 -0
  59. package/dist/types/react/web/ui/ConnectWallet/screens/ViewTokens.d.ts +11 -0
  60. package/dist/types/react/web/ui/ConnectWallet/screens/ViewTokens.d.ts.map +1 -0
  61. package/dist/types/react/web/ui/ConnectWallet/screens/types.d.ts +1 -1
  62. package/dist/types/react/web/ui/ConnectWallet/screens/types.d.ts.map +1 -1
  63. package/dist/types/version.d.ts +1 -1
  64. package/dist/types/version.d.ts.map +1 -1
  65. package/package.json +1 -1
  66. package/src/extensions/erc721/read/getOwnedTokenIds.ts +30 -5
  67. package/src/react/core/hooks/connection/ConnectButtonProps.ts +29 -1
  68. package/src/react/core/hooks/transaction/useSendTransaction.ts +4 -4
  69. package/src/react/core/utils/defaultTokens.ts +3 -0
  70. package/src/react/web/hooks/transaction/useSendTransaction.tsx +19 -4
  71. package/src/react/web/ui/ConnectWallet/ConnectButton.tsx +1 -0
  72. package/src/react/web/ui/ConnectWallet/Details.tsx +76 -3
  73. package/src/react/web/ui/ConnectWallet/icons/ImageIcon.tsx +25 -0
  74. package/src/react/web/ui/ConnectWallet/screens/ViewFunds.tsx +32 -87
  75. package/src/react/web/ui/ConnectWallet/screens/ViewNFTs.tsx +255 -0
  76. package/src/react/web/ui/ConnectWallet/screens/ViewTokens.tsx +125 -0
  77. package/src/react/web/ui/ConnectWallet/screens/types.ts +2 -0
  78. package/src/version.ts +1 -1
@@ -0,0 +1,255 @@
1
+ import { useQueries } from "@tanstack/react-query";
2
+ import { useMemo } from "react";
3
+ import type { Chain } from "../../../../../chains/types.js";
4
+ import { getCachedChain } from "../../../../../chains/utils.js";
5
+ import type { ThirdwebClient } from "../../../../../client/client.js";
6
+ import { getContract } from "../../../../../contract/contract.js";
7
+ import { getOwnedNFTs as getErc721OwnedNFTs } from "../../../../../extensions/erc721/read/getOwnedNFTs.js";
8
+ import { isERC721 } from "../../../../../extensions/erc721/read/isERC721.js";
9
+ import { getOwnedNFTs as getErc1155OwnedNFTs } from "../../../../../extensions/erc1155/read/getOwnedNFTs.js";
10
+ import { isERC1155 } from "../../../../../extensions/erc1155/read/isERC1155.js";
11
+ import type { Theme } from "../../../../core/design-system/index.js";
12
+ import type { SupportedNFTs } from "../../../../core/utils/defaultTokens.js";
13
+ import { useActiveAccount } from "../../../hooks/wallets/useActiveAccount.js";
14
+ import { useActiveWalletChain } from "../../../hooks/wallets/useActiveWalletChain.js";
15
+ import { MediaRenderer } from "../../MediaRenderer/MediaRenderer.js";
16
+ import { Skeleton } from "../../components/Skeleton.js";
17
+ import { Spacer } from "../../components/Spacer.js";
18
+ import { Container, Line, ModalHeader } from "../../components/basic.js";
19
+
20
+ const fetchNFTs = async (
21
+ client: ThirdwebClient,
22
+ chain: Chain,
23
+ nftAddress: string,
24
+ owner: string,
25
+ ) => {
26
+ const contract = getContract({
27
+ address: nftAddress,
28
+ chain,
29
+ client,
30
+ });
31
+
32
+ const erc721 = await isERC721({ contract }).catch(() => {
33
+ throw new Error(
34
+ `Failed to read contract bytecode for NFT ${nftAddress} on ${chain.name || chain.id}, is this NFT on the correct chain?`,
35
+ );
36
+ });
37
+ if (erc721) {
38
+ const result = await getErc721OwnedNFTs({
39
+ contract,
40
+ owner: owner,
41
+ });
42
+ return result.map((nft) => ({
43
+ ...nft,
44
+ quantityOwned: BigInt(1),
45
+ address: contract.address,
46
+ chain,
47
+ }));
48
+ }
49
+
50
+ const erc1155 = await isERC1155({ contract }).catch(() => false);
51
+ if (erc1155) {
52
+ const result = await getErc1155OwnedNFTs({
53
+ contract,
54
+ address: owner,
55
+ });
56
+ return result.map((nft) => ({ ...nft, address: contract.address, chain }));
57
+ }
58
+
59
+ throw new Error(
60
+ `NFT at ${nftAddress} on chain ${chain.id} is not ERC721 or ERC1155, or does not properly identify itself as supporting either interface`,
61
+ );
62
+ };
63
+
64
+ /**
65
+ * @internal
66
+ */
67
+ export function ViewNFTs(props: {
68
+ supportedNFTs?: SupportedNFTs;
69
+ theme: Theme | "light" | "dark";
70
+ onBack: () => void;
71
+ client: ThirdwebClient;
72
+ }) {
73
+ const activeAccount = useActiveAccount();
74
+ const activeChain = useActiveWalletChain();
75
+
76
+ if (!activeChain?.id || !activeAccount?.address) {
77
+ return null;
78
+ }
79
+
80
+ const nftList = useMemo(() => {
81
+ const nfts = [];
82
+ if (!props.supportedNFTs) return [];
83
+ for (const chainId in props.supportedNFTs) {
84
+ if (props.supportedNFTs[chainId]) {
85
+ nfts.push(
86
+ ...props.supportedNFTs[chainId].map((address) => ({
87
+ address,
88
+ chain: getCachedChain(Number.parseInt(chainId)),
89
+ })),
90
+ );
91
+ }
92
+ }
93
+ return nfts;
94
+ }, [props.supportedNFTs]);
95
+
96
+ const results = useQueries({
97
+ queries: nftList.map((nft) => ({
98
+ queryKey: ["readContract", nft.chain.id, nft.address],
99
+ queryFn: () =>
100
+ fetchNFTs(props.client, nft.chain, nft.address, activeAccount?.address),
101
+ })),
102
+ });
103
+
104
+ return (
105
+ <Container
106
+ style={{
107
+ minHeight: "300px",
108
+ }}
109
+ >
110
+ <Container p="lg">
111
+ <ModalHeader title="View NFTs" onBack={props.onBack} />
112
+ </Container>
113
+ <Line />
114
+ <Container
115
+ px="sm"
116
+ scrollY
117
+ style={{
118
+ maxHeight: "500px",
119
+ }}
120
+ >
121
+ <Spacer y="md" />
122
+ <Container
123
+ style={{
124
+ display: "grid",
125
+ gridTemplateColumns: "1fr 1fr",
126
+ gap: "12px",
127
+ }}
128
+ >
129
+ {results.map((result, index) => {
130
+ if (result.error) {
131
+ console.error(result.error);
132
+ return null;
133
+ }
134
+ return result.isLoading || !result.data ? (
135
+ <Skeleton
136
+ key={`${nftList[index]?.chain?.id}:${nftList[index]?.address}`}
137
+ height="160px"
138
+ width="160px"
139
+ />
140
+ ) : (
141
+ result.data.map((nft) => (
142
+ <NftCard
143
+ key={`${nft.chain.id}:${nft.address}:${nft.id}`}
144
+ {...nft}
145
+ client={props.client}
146
+ chain={nft.chain}
147
+ theme={props.theme}
148
+ />
149
+ ))
150
+ );
151
+ })}
152
+ </Container>
153
+ <Spacer y="lg" />
154
+ </Container>
155
+ </Container>
156
+ );
157
+ }
158
+
159
+ function NftCard(
160
+ props: Awaited<ReturnType<typeof fetchNFTs>>[number] & {
161
+ client: ThirdwebClient;
162
+ chain: Chain;
163
+ theme: Theme | "light" | "dark";
164
+ },
165
+ ) {
166
+ const theme =
167
+ typeof props.theme === "string" ? props.theme : props.theme.type;
168
+ const themeObject = typeof props.theme === "string" ? undefined : props.theme;
169
+ const content = (
170
+ <div
171
+ style={{
172
+ display: "flex",
173
+ flexDirection: "column",
174
+ gap: "4px",
175
+ alignItems: "center",
176
+ }}
177
+ >
178
+ <div
179
+ style={{
180
+ position: "relative",
181
+ display: "flex",
182
+ flexShrink: 0,
183
+ alignItems: "center",
184
+ width: "160px",
185
+ height: "160px",
186
+ borderRadius: "8px",
187
+ overflow: "hidden",
188
+ background:
189
+ theme === "light" ? "rgba(0, 0, 0, 0.10)" : "rgba(0, 0, 0, 0.20)",
190
+ }}
191
+ >
192
+ {props.metadata.image && (
193
+ <MediaRenderer
194
+ src={props.metadata.image}
195
+ style={{
196
+ width: "100%",
197
+ height: "100%",
198
+ }}
199
+ client={props.client}
200
+ />
201
+ )}
202
+ {props.quantityOwned > 1 && (
203
+ <div
204
+ style={{
205
+ position: "absolute",
206
+ bottom: "4px",
207
+ right: "4px",
208
+ background:
209
+ themeObject?.colors?.modalBg ??
210
+ (theme === "light" ? "white" : "black"),
211
+ fontSize: "10px",
212
+ padding: "4px 4px",
213
+ width: "20px",
214
+ height: "20px",
215
+ display: "flex",
216
+ alignItems: "center",
217
+ justifyContent: "center",
218
+ borderRadius: "100%",
219
+ }}
220
+ >
221
+ {props.quantityOwned.toString()}
222
+ </div>
223
+ )}
224
+ {props.chain.icon && (
225
+ <img
226
+ alt={props.chain.name}
227
+ style={{
228
+ position: "absolute",
229
+ bottom: "4px",
230
+ left: "4px",
231
+ width: "20px",
232
+ height: "20px",
233
+ }}
234
+ src={props.chain.icon.url}
235
+ />
236
+ )}
237
+ </div>
238
+ <span style={{ fontWeight: 600 }}>{props.metadata.name}</span>
239
+ </div>
240
+ );
241
+
242
+ if (props.chain.name) {
243
+ return (
244
+ <a
245
+ href={`https://thirdweb.com/${props.chain.id}/${props.address}/nfts/${props.id}`}
246
+ target="_blank"
247
+ rel="noreferrer"
248
+ >
249
+ {content}
250
+ </a>
251
+ );
252
+ }
253
+
254
+ return content;
255
+ }
@@ -0,0 +1,125 @@
1
+ import type { Chain } from "../../../../../chains/types.js";
2
+ import type { ThirdwebClient } from "../../../../../client/client.js";
3
+ import { fontSize } from "../../../../core/design-system/index.js";
4
+ import { useWalletBalance } from "../../../../core/hooks/others/useWalletBalance.js";
5
+ import {
6
+ type SupportedTokens,
7
+ defaultTokens,
8
+ } from "../../../../core/utils/defaultTokens.js";
9
+ import { useActiveAccount } from "../../../hooks/wallets/useActiveAccount.js";
10
+ import { useActiveWalletChain } from "../../../hooks/wallets/useActiveWalletChain.js";
11
+ import { Skeleton } from "../../components/Skeleton.js";
12
+ import { Spacer } from "../../components/Spacer.js";
13
+ import { TokenIcon } from "../../components/TokenIcon.js";
14
+ import { Container, Line, ModalHeader } from "../../components/basic.js";
15
+ import { Text } from "../../components/text.js";
16
+ import { formatTokenBalance } from "./formatTokenBalance.js";
17
+ import {
18
+ type ERC20OrNativeToken,
19
+ NATIVE_TOKEN,
20
+ isNativeToken,
21
+ } from "./nativeToken.js";
22
+
23
+ /**
24
+ * @internal
25
+ */
26
+ export function ViewTokens(props: {
27
+ supportedTokens?: SupportedTokens;
28
+ onBack: () => void;
29
+ client: ThirdwebClient;
30
+ }) {
31
+ const activeChain = useActiveWalletChain();
32
+ const supportedTokens = props.supportedTokens || defaultTokens;
33
+
34
+ if (!activeChain) {
35
+ return null;
36
+ }
37
+
38
+ const tokenList =
39
+ (activeChain?.id ? supportedTokens[activeChain.id] : undefined) || [];
40
+
41
+ return (
42
+ <Container
43
+ style={{
44
+ minHeight: "300px",
45
+ }}
46
+ >
47
+ <Container p="lg">
48
+ <ModalHeader title="View Funds" onBack={props.onBack} />
49
+ </Container>
50
+ <Line />
51
+ <Container
52
+ px="sm"
53
+ scrollY
54
+ style={{
55
+ maxHeight: "500px",
56
+ }}
57
+ >
58
+ <Spacer y="md" />
59
+
60
+ <TokenInfo
61
+ token={NATIVE_TOKEN}
62
+ chain={activeChain}
63
+ client={props.client}
64
+ />
65
+
66
+ {tokenList.map((token) => {
67
+ return (
68
+ <TokenInfo
69
+ token={token}
70
+ key={token.address}
71
+ chain={activeChain}
72
+ client={props.client}
73
+ />
74
+ );
75
+ })}
76
+ <Spacer y="lg" />
77
+ </Container>
78
+ </Container>
79
+ );
80
+ }
81
+
82
+ function TokenInfo(props: {
83
+ token: ERC20OrNativeToken;
84
+ chain: Chain;
85
+ client: ThirdwebClient;
86
+ }) {
87
+ const account = useActiveAccount();
88
+ const tokenBalanceQuery = useWalletBalance({
89
+ address: account?.address,
90
+ chain: props.chain,
91
+ tokenAddress: isNativeToken(props.token) ? undefined : props.token.address,
92
+ client: props.client,
93
+ });
94
+
95
+ const tokenName = isNativeToken(props.token)
96
+ ? tokenBalanceQuery.data?.name
97
+ : props.token.name;
98
+
99
+ return (
100
+ <Container flex="row" gap="sm" p="sm">
101
+ <TokenIcon
102
+ token={props.token}
103
+ chain={props.chain}
104
+ size="lg"
105
+ client={props.client}
106
+ />
107
+
108
+ <Container flex="column" gap="xxs">
109
+ {tokenName ? (
110
+ <Text size="sm" color="primaryText">
111
+ {tokenName}
112
+ </Text>
113
+ ) : (
114
+ <Skeleton height={fontSize.md} width="150px" />
115
+ )}
116
+
117
+ {tokenBalanceQuery.data ? (
118
+ <Text size="xs"> {formatTokenBalance(tokenBalanceQuery.data)}</Text>
119
+ ) : (
120
+ <Skeleton height={fontSize.xs} width="100px" />
121
+ )}
122
+ </Container>
123
+ </Container>
124
+ );
125
+ }
@@ -68,6 +68,8 @@ export type WalletDetailsModalScreen =
68
68
  | "network-switcher"
69
69
  | "pending-tx"
70
70
  | "view-funds"
71
+ | "view-tokens"
72
+ | "view-nfts"
71
73
  | "private-key"
72
74
  | "manage-wallet"
73
75
  | "wallet-connect-receiver"
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = "5.33.0";
1
+ export const version = "5.34.0-nightly-f6ff5a78fc2d65f0f250b154f1405210ca57ce0a-20240706000322";