thirdweb 5.32.3 → 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.
- package/dist/cjs/auth/constants.js +30 -0
- package/dist/cjs/auth/constants.js.map +1 -0
- package/dist/cjs/auth/core/verify-jwt.js +2 -2
- package/dist/cjs/auth/core/verify-jwt.js.map +1 -1
- package/dist/cjs/auth/core/verify-login-payload.js +2 -2
- package/dist/cjs/auth/core/verify-login-payload.js.map +1 -1
- package/dist/cjs/auth/is-erc6492-signature.js +25 -0
- package/dist/cjs/auth/is-erc6492-signature.js.map +1 -0
- package/dist/cjs/auth/parse-erc6492-signature.js +28 -0
- package/dist/cjs/auth/parse-erc6492-signature.js.map +1 -0
- package/dist/cjs/auth/serialize-erc6492-signature.js +36 -0
- package/dist/cjs/auth/serialize-erc6492-signature.js.map +1 -0
- package/dist/cjs/auth/types.js +3 -0
- package/dist/cjs/auth/types.js.map +1 -0
- package/dist/cjs/auth/verify-signature.js +196 -0
- package/dist/cjs/auth/verify-signature.js.map +1 -0
- package/dist/cjs/exports/auth.js +11 -5
- package/dist/cjs/exports/auth.js.map +1 -1
- package/dist/cjs/extensions/erc721/read/getOwnedTokenIds.js +13 -4
- package/dist/cjs/extensions/erc721/read/getOwnedTokenIds.js.map +1 -1
- package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js +2 -3
- package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
- package/dist/cjs/react/core/utils/defaultTokens.js.map +1 -1
- package/dist/cjs/react/web/hooks/transaction/useSendTransaction.js +8 -5
- package/dist/cjs/react/web/hooks/transaction/useSendTransaction.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/ConnectButton.js +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/ConnectButton.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/Details.js +24 -4
- package/dist/cjs/react/web/ui/ConnectWallet/Details.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/Modal/AllWalletsUI.js +3 -0
- package/dist/cjs/react/web/ui/ConnectWallet/Modal/AllWalletsUI.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/WalletSelector.js +3 -0
- package/dist/cjs/react/web/ui/ConnectWallet/WalletSelector.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/icons/ImageIcon.js +12 -0
- package/dist/cjs/react/web/ui/ConnectWallet/icons/ImageIcon.js.map +1 -0
- package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewFunds.js +12 -30
- package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewFunds.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewNFTs.js +142 -0
- package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewNFTs.js.map +1 -0
- package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewTokens.js +48 -0
- package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewTokens.js.map +1 -0
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/cjs/wallets/coinbase/coinbaseWebSDK.js +2 -2
- package/dist/cjs/wallets/coinbase/coinbaseWebSDK.js.map +1 -1
- package/dist/cjs/wallets/injected/index.js +2 -2
- package/dist/cjs/wallets/injected/index.js.map +1 -1
- package/dist/cjs/wallets/smart/index.js +0 -1
- package/dist/cjs/wallets/smart/index.js.map +1 -1
- package/dist/esm/auth/constants.js +27 -0
- package/dist/esm/auth/constants.js.map +1 -0
- package/dist/esm/auth/core/verify-jwt.js +1 -1
- package/dist/esm/auth/core/verify-jwt.js.map +1 -1
- package/dist/esm/auth/core/verify-login-payload.js +1 -1
- package/dist/esm/auth/core/verify-login-payload.js.map +1 -1
- package/dist/esm/auth/is-erc6492-signature.js +22 -0
- package/dist/esm/auth/is-erc6492-signature.js.map +1 -0
- package/dist/esm/auth/parse-erc6492-signature.js +25 -0
- package/dist/esm/auth/parse-erc6492-signature.js.map +1 -0
- package/dist/esm/auth/serialize-erc6492-signature.js +33 -0
- package/dist/esm/auth/serialize-erc6492-signature.js.map +1 -0
- package/dist/esm/auth/types.js +2 -0
- package/dist/esm/auth/types.js.map +1 -0
- package/dist/esm/auth/verify-signature.js +191 -0
- package/dist/esm/auth/verify-signature.js.map +1 -0
- package/dist/esm/exports/auth.js +4 -1
- package/dist/esm/exports/auth.js.map +1 -1
- package/dist/esm/extensions/erc721/read/getOwnedTokenIds.js +14 -5
- package/dist/esm/extensions/erc721/read/getOwnedTokenIds.js.map +1 -1
- package/dist/esm/react/core/hooks/transaction/useSendTransaction.js +2 -3
- package/dist/esm/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
- package/dist/esm/react/core/utils/defaultTokens.js.map +1 -1
- package/dist/esm/react/web/hooks/transaction/useSendTransaction.js +8 -5
- package/dist/esm/react/web/hooks/transaction/useSendTransaction.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/ConnectButton.js +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/ConnectButton.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/Details.js +24 -4
- package/dist/esm/react/web/ui/ConnectWallet/Details.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/Modal/AllWalletsUI.js +3 -0
- package/dist/esm/react/web/ui/ConnectWallet/Modal/AllWalletsUI.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/WalletSelector.js +3 -0
- package/dist/esm/react/web/ui/ConnectWallet/WalletSelector.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/icons/ImageIcon.js +8 -0
- package/dist/esm/react/web/ui/ConnectWallet/icons/ImageIcon.js.map +1 -0
- package/dist/esm/react/web/ui/ConnectWallet/screens/ViewFunds.js +13 -31
- package/dist/esm/react/web/ui/ConnectWallet/screens/ViewFunds.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/ViewNFTs.js +139 -0
- package/dist/esm/react/web/ui/ConnectWallet/screens/ViewNFTs.js.map +1 -0
- package/dist/esm/react/web/ui/ConnectWallet/screens/ViewTokens.js +45 -0
- package/dist/esm/react/web/ui/ConnectWallet/screens/ViewTokens.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/esm/wallets/coinbase/coinbaseWebSDK.js +2 -2
- package/dist/esm/wallets/coinbase/coinbaseWebSDK.js.map +1 -1
- package/dist/esm/wallets/injected/index.js +2 -2
- package/dist/esm/wallets/injected/index.js.map +1 -1
- package/dist/esm/wallets/smart/index.js +0 -1
- package/dist/esm/wallets/smart/index.js.map +1 -1
- package/dist/types/auth/constants.d.ts +20 -0
- package/dist/types/auth/constants.d.ts.map +1 -0
- package/dist/types/auth/is-erc6492-signature.d.ts +19 -0
- package/dist/types/auth/is-erc6492-signature.d.ts.map +1 -0
- package/dist/types/auth/parse-erc6492-signature.d.ts +24 -0
- package/dist/types/auth/parse-erc6492-signature.d.ts.map +1 -0
- package/dist/types/auth/serialize-erc6492-signature.d.ts +27 -0
- package/dist/types/auth/serialize-erc6492-signature.d.ts.map +1 -0
- package/dist/types/auth/types.d.ts +7 -0
- package/dist/types/auth/types.d.ts.map +1 -0
- package/dist/types/auth/verify-signature.d.ts +70 -0
- package/dist/types/auth/verify-signature.d.ts.map +1 -0
- package/dist/types/exports/auth.d.ts +5 -1
- package/dist/types/exports/auth.d.ts.map +1 -1
- package/dist/types/extensions/erc721/read/getOwnedTokenIds.d.ts.map +1 -1
- package/dist/types/react/core/hooks/connection/ConnectButtonProps.d.ts +25 -1
- package/dist/types/react/core/hooks/connection/ConnectButtonProps.d.ts.map +1 -1
- package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts +2 -1
- package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts.map +1 -1
- package/dist/types/react/core/utils/defaultTokens.d.ts +2 -0
- package/dist/types/react/core/utils/defaultTokens.d.ts.map +1 -1
- package/dist/types/react/web/hooks/transaction/useSendTransaction.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/Details.d.ts +28 -1
- package/dist/types/react/web/ui/ConnectWallet/Details.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/Modal/AllWalletsUI.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/WalletSelector.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/icons/ImageIcon.d.ts +6 -0
- package/dist/types/react/web/ui/ConnectWallet/icons/ImageIcon.d.ts.map +1 -0
- package/dist/types/react/web/ui/ConnectWallet/screens/ViewFunds.d.ts +5 -2
- package/dist/types/react/web/ui/ConnectWallet/screens/ViewFunds.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/ViewNFTs.d.ts +13 -0
- package/dist/types/react/web/ui/ConnectWallet/screens/ViewNFTs.d.ts.map +1 -0
- package/dist/types/react/web/ui/ConnectWallet/screens/ViewTokens.d.ts +11 -0
- package/dist/types/react/web/ui/ConnectWallet/screens/ViewTokens.d.ts.map +1 -0
- package/dist/types/react/web/ui/ConnectWallet/screens/types.d.ts +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/types.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/version.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/auth/constants.ts +30 -0
- package/src/auth/core/verify-jwt.ts +1 -1
- package/src/auth/core/verify-login-payload.ts +1 -1
- package/src/auth/is-erc6492-signature.test.ts +26 -0
- package/src/auth/is-erc6492-signature.ts +23 -0
- package/src/auth/parse-erc6492-signature.test.ts +30 -0
- package/src/auth/parse-erc6492-signature.ts +38 -0
- package/src/auth/serialize-erc6492-signature.test.ts +23 -0
- package/src/auth/serialize-erc6492-signature.ts +42 -0
- package/src/auth/types.ts +7 -0
- package/src/auth/verify-signature.test.ts +97 -0
- package/src/auth/verify-signature.ts +245 -0
- package/src/exports/auth.ts +9 -1
- package/src/extensions/erc721/read/getOwnedTokenIds.ts +30 -5
- package/src/react/core/hooks/connection/ConnectButtonProps.ts +29 -1
- package/src/react/core/hooks/transaction/useSendTransaction.ts +4 -4
- package/src/react/core/utils/defaultTokens.ts +3 -0
- package/src/react/web/hooks/transaction/useSendTransaction.tsx +19 -4
- package/src/react/web/ui/ConnectWallet/ConnectButton.tsx +1 -0
- package/src/react/web/ui/ConnectWallet/Details.tsx +76 -3
- package/src/react/web/ui/ConnectWallet/Modal/AllWalletsUI.tsx +3 -0
- package/src/react/web/ui/ConnectWallet/WalletSelector.tsx +3 -1
- package/src/react/web/ui/ConnectWallet/icons/ImageIcon.tsx +25 -0
- package/src/react/web/ui/ConnectWallet/screens/ViewFunds.tsx +32 -87
- package/src/react/web/ui/ConnectWallet/screens/ViewNFTs.tsx +255 -0
- package/src/react/web/ui/ConnectWallet/screens/ViewTokens.tsx +125 -0
- package/src/react/web/ui/ConnectWallet/screens/types.ts +2 -0
- package/src/version.ts +1 -1
- package/src/wallets/coinbase/coinbaseWebSDK.ts +2 -2
- package/src/wallets/injected/index.ts +2 -2
- package/src/wallets/smart/index.ts +0 -3
- package/src/wallets/smart/smart-wallet-integration.test.ts +1 -1
- package/dist/cjs/auth/verifySignature.js +0 -137
- package/dist/cjs/auth/verifySignature.js.map +0 -1
- package/dist/esm/auth/verifySignature.js +0 -132
- package/dist/esm/auth/verifySignature.js.map +0 -1
- package/dist/types/auth/verifySignature.d.ts +0 -53
- package/dist/types/auth/verifySignature.d.ts.map +0 -1
- package/src/auth/verifySignature.test.ts +0 -53
- package/src/auth/verifySignature.ts +0 -166
@@ -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
|
+
}
|
package/src/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = "5.
|
1
|
+
export const version = "5.34.0-nightly-f6ff5a78fc2d65f0f250b154f1405210ca57ce0a-20240706000322";
|
@@ -373,7 +373,7 @@ function onConnect(
|
|
373
373
|
await provider.disconnect();
|
374
374
|
}
|
375
375
|
|
376
|
-
function onDisconnect() {
|
376
|
+
async function onDisconnect() {
|
377
377
|
disconnect();
|
378
378
|
emitter.emit("disconnect", undefined);
|
379
379
|
}
|
@@ -401,7 +401,7 @@ function onConnect(
|
|
401
401
|
return [
|
402
402
|
account,
|
403
403
|
chain,
|
404
|
-
|
404
|
+
onDisconnect,
|
405
405
|
(newChain) => switchChainCoinbaseWalletSDK(provider, newChain),
|
406
406
|
];
|
407
407
|
}
|
@@ -228,7 +228,7 @@ async function onConnect(
|
|
228
228
|
provider.removeListener("disconnect", onDisconnect);
|
229
229
|
}
|
230
230
|
|
231
|
-
function onDisconnect() {
|
231
|
+
async function onDisconnect() {
|
232
232
|
disconnect();
|
233
233
|
emitter.emit("disconnect", undefined);
|
234
234
|
}
|
@@ -258,7 +258,7 @@ async function onConnect(
|
|
258
258
|
return [
|
259
259
|
account,
|
260
260
|
chain,
|
261
|
-
|
261
|
+
onDisconnect,
|
262
262
|
(newChain) => switchChain(provider, newChain),
|
263
263
|
] as const;
|
264
264
|
}
|
@@ -203,9 +203,6 @@ async function createSmartAccount(
|
|
203
203
|
]);
|
204
204
|
const isDeployed = await isContractDeployed(accountContract);
|
205
205
|
if (!isDeployed) {
|
206
|
-
console.log(
|
207
|
-
"Account contract not deployed yet. Deploying account before signing message",
|
208
|
-
);
|
209
206
|
await _deployAccount({
|
210
207
|
options,
|
211
208
|
account,
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { beforeAll, describe, expect, it } from "vitest";
|
2
2
|
import { TEST_CLIENT } from "../../../test/src/test-clients.js";
|
3
3
|
import { typedData } from "../../../test/src/typed-data.js";
|
4
|
-
import { verifySignature } from "../../auth/
|
4
|
+
import { verifySignature } from "../../auth/verify-signature.js";
|
5
5
|
import { arbitrumSepolia } from "../../chains/chain-definitions/arbitrum-sepolia.js";
|
6
6
|
import { type ThirdwebContract, getContract } from "../../contract/contract.js";
|
7
7
|
import { parseEventLogs } from "../../event/actions/parse-logs.js";
|
@@ -1,137 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.verifyEOASignature = verifyEOASignature;
|
4
|
-
exports.verifyContractWalletSignature = verifyContractWalletSignature;
|
5
|
-
exports.verifySignature = verifySignature;
|
6
|
-
const viem_1 = require("viem");
|
7
|
-
const contract_js_1 = require("../contract/contract.js");
|
8
|
-
const isValidSignature_js_1 = require("../extensions/erc1271/__generated__/isValidSignature/read/isValidSignature.js");
|
9
|
-
const hex_js_1 = require("../utils/encoding/hex.js");
|
10
|
-
const hashMessage_js_1 = require("../utils/hashing/hashMessage.js");
|
11
|
-
/**
|
12
|
-
* Verifies the signature of a message using an Ethereum account's EOA (Externally Owned Account).
|
13
|
-
* @param options - The options for verifying the signature.
|
14
|
-
* @returns A boolean indicating whether the signature is valid.
|
15
|
-
* @throws An error if the signature is invalid.
|
16
|
-
* @example
|
17
|
-
* ```ts
|
18
|
-
* import { verifyEOASignature } from 'thirdweb/auth';
|
19
|
-
*
|
20
|
-
* const isValid = await verifyEOASignature({
|
21
|
-
* message: '0x1234567890123456789012345678901234567890',
|
22
|
-
* signature: '0x1234567890123456789012345678901234567890',
|
23
|
-
* address: '0x1234567890123456789012345678901234567890',
|
24
|
-
* });
|
25
|
-
* ```
|
26
|
-
* @auth
|
27
|
-
*/
|
28
|
-
async function verifyEOASignature(options) {
|
29
|
-
const messageHash = (0, hashMessage_js_1.hashMessage)(options.message);
|
30
|
-
if (!(0, hex_js_1.isHex)(options.signature)) {
|
31
|
-
return false;
|
32
|
-
}
|
33
|
-
const recoveredAddress = await (0, viem_1.recoverAddress)({
|
34
|
-
hash: messageHash,
|
35
|
-
signature: options.signature,
|
36
|
-
});
|
37
|
-
if (recoveredAddress.toLowerCase() === options.address.toLowerCase()) {
|
38
|
-
return true;
|
39
|
-
}
|
40
|
-
return false;
|
41
|
-
}
|
42
|
-
const EIP1271_MAGICVALUE = "0x1626ba7e";
|
43
|
-
/**
|
44
|
-
* Verifies the signature of a contract wallet.
|
45
|
-
* @param options - The parameters for verifying the signature.
|
46
|
-
* @returns A boolean indicating whether the signature is valid.
|
47
|
-
* @throws An error if the signature is invalid.
|
48
|
-
* @example
|
49
|
-
* ```ts
|
50
|
-
* import { verifyContractWalletSignature } from 'thirdweb/auth';
|
51
|
-
*
|
52
|
-
* const isValid = await verifyContractWalletSignature({
|
53
|
-
* message: '0x1234567890123456789012345678901234567890',
|
54
|
-
* signature: '0x1234567890123456789012345678901234567890',
|
55
|
-
* address: '0x1234567890123456789012345678901234567890',
|
56
|
-
* chain: ...,
|
57
|
-
* client: ...,
|
58
|
-
* });
|
59
|
-
* ```
|
60
|
-
* @auth
|
61
|
-
*/
|
62
|
-
async function verifyContractWalletSignature(options) {
|
63
|
-
if (!(0, hex_js_1.isHex)(options.signature)) {
|
64
|
-
throw new Error("Invalid signature");
|
65
|
-
}
|
66
|
-
const contract = (0, contract_js_1.getContract)({
|
67
|
-
address: options.address,
|
68
|
-
chain: options.chain,
|
69
|
-
client: options.client,
|
70
|
-
});
|
71
|
-
const messageHash = (0, hashMessage_js_1.hashMessage)(options.message);
|
72
|
-
const result = await (0, isValidSignature_js_1.isValidSignature)({
|
73
|
-
contract,
|
74
|
-
hash: messageHash,
|
75
|
-
signature: options.signature,
|
76
|
-
});
|
77
|
-
return result === EIP1271_MAGICVALUE;
|
78
|
-
}
|
79
|
-
/**
|
80
|
-
* Verifies the signature based on the provided options.
|
81
|
-
* Handles smart contract wallet signatures and EOA signatures.
|
82
|
-
* **IMPORTANT: in order to check smart contract signatures, a chain and client must be provided.**
|
83
|
-
* @param options - The options for signature verification.
|
84
|
-
* @returns A boolean indicating whether the signature is valid or not.
|
85
|
-
* @example
|
86
|
-
* ```ts
|
87
|
-
* import { verifySignature } from 'thirdweb/auth';
|
88
|
-
*
|
89
|
-
* const isValid = await verifySignature({
|
90
|
-
* message: 'Your message to sign',
|
91
|
-
* signature: '0x91db0222ec371a8c18d3b187a6d2e77789bffca1b96826ef6b8708e0d4a66c80312fc3ae95b8fbc147265abf539bb6f360152be61a0e1411d7f5771a599e769a1c',
|
92
|
-
* address: '0xda9C7A86AeE76701FC1c23ae548e8E93Ba3e42A5',
|
93
|
-
* client: thirdwebClient,
|
94
|
-
* chain: chain
|
95
|
-
* });
|
96
|
-
* ```
|
97
|
-
* @auth
|
98
|
-
*/
|
99
|
-
let warningTriggered = false;
|
100
|
-
async function verifySignature(options) {
|
101
|
-
try {
|
102
|
-
const isValidEOASig = await verifyEOASignature(options);
|
103
|
-
if (isValidEOASig) {
|
104
|
-
return true;
|
105
|
-
}
|
106
|
-
}
|
107
|
-
catch {
|
108
|
-
// no-op, we skip to contract signature check
|
109
|
-
}
|
110
|
-
if (isVerifyContractWalletSignatureParams(options)) {
|
111
|
-
try {
|
112
|
-
return await verifyContractWalletSignature(options);
|
113
|
-
}
|
114
|
-
catch {
|
115
|
-
// no-op we skip to return false
|
116
|
-
}
|
117
|
-
}
|
118
|
-
else if (!warningTriggered) {
|
119
|
-
// We only trigger this warning once
|
120
|
-
warningTriggered = true;
|
121
|
-
console.error(`
|
122
|
-
Failed to verify EOA signature and no chain or client provided.
|
123
|
-
|
124
|
-
If you mean to use a smart account, please provide a chain and client.
|
125
|
-
For more information on how to setup a smart account with Auth, see https://portal.thirdweb.com/connect/auth
|
126
|
-
`);
|
127
|
-
}
|
128
|
-
// if we reach here, we have no way to verify the signature
|
129
|
-
return false;
|
130
|
-
}
|
131
|
-
function isVerifyContractWalletSignatureParams(options) {
|
132
|
-
return ("chain" in options &&
|
133
|
-
options.chain !== undefined &&
|
134
|
-
"client" in options &&
|
135
|
-
options.client !== undefined);
|
136
|
-
}
|
137
|
-
//# sourceMappingURL=verifySignature.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"verifySignature.js","sourceRoot":"","sources":["../../../src/auth/verifySignature.ts"],"names":[],"mappings":";;AAgCA,gDAgBC;AA8BD,sEAsBC;AA2BD,0CA2BC;AA1JD,+BAAsC;AAGtC,yDAAsD;AACtD,uHAAiH;AACjH,qDAAiD;AACjD,oEAA8D;AAS9D;;;;;;;;;;;;;;;;GAgBG;AACI,KAAK,UAAU,kBAAkB,CAAC,OAAiC;IACxE,MAAM,WAAW,GAAG,IAAA,4BAAW,EAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEjD,IAAI,CAAC,IAAA,cAAK,EAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,gBAAgB,GAAG,MAAM,IAAA,qBAAc,EAAC;QAC5C,IAAI,EAAE,WAAW;QACjB,SAAS,EAAE,OAAO,CAAC,SAAS;KAC7B,CAAC,CAAC;IAEH,IAAI,gBAAgB,CAAC,WAAW,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;QACrE,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AASD,MAAM,kBAAkB,GAAG,YAAY,CAAC;AAExC;;;;;;;;;;;;;;;;;;GAkBG;AACI,KAAK,UAAU,6BAA6B,CACjD,OAA4C;IAE5C,IAAI,CAAC,IAAA,cAAK,EAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;IACvC,CAAC;IAED,MAAM,QAAQ,GAAG,IAAA,yBAAW,EAAC;QAC3B,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,IAAA,4BAAW,EAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEjD,MAAM,MAAM,GAAG,MAAM,IAAA,sCAAgB,EAAC;QACpC,QAAQ;QACR,IAAI,EAAE,WAAW;QACjB,SAAS,EAAE,OAAO,CAAC,SAAS;KAC7B,CAAC,CAAC;IAEH,OAAO,MAAM,KAAK,kBAAkB,CAAC;AACvC,CAAC;AAMD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,IAAI,gBAAgB,GAAG,KAAK,CAAC;AACtB,KAAK,UAAU,eAAe,CAAC,OAA8B;IAClE,IAAI,CAAC;QACH,MAAM,aAAa,GAAG,MAAM,kBAAkB,CAAC,OAAO,CAAC,CAAC;QACxD,IAAI,aAAa,EAAE,CAAC;YAClB,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,6CAA6C;IAC/C,CAAC;IACD,IAAI,qCAAqC,CAAC,OAAO,CAAC,EAAE,CAAC;QACnD,IAAI,CAAC;YACH,OAAO,MAAM,6BAA6B,CAAC,OAAO,CAAC,CAAC;QACtD,CAAC;QAAC,MAAM,CAAC;YACP,gCAAgC;QAClC,CAAC;IACH,CAAC;SAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAC7B,oCAAoC;QACpC,gBAAgB,GAAG,IAAI,CAAC;QACxB,OAAO,CAAC,KAAK,CAAC;;;;;KAKb,CAAC,CAAC;IACL,CAAC;IACD,2DAA2D;IAC3D,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,qCAAqC,CAC5C,OAA8B;IAE9B,OAAO,CACL,OAAO,IAAI,OAAO;QAClB,OAAO,CAAC,KAAK,KAAK,SAAS;QAC3B,QAAQ,IAAI,OAAO;QACnB,OAAO,CAAC,MAAM,KAAK,SAAS,CAC7B,CAAC;AACJ,CAAC"}
|