thirdweb 5.80.1-nightly-ce3e850fdbf34911e20919ecc2674e4a63f08fa3-20241225000333 → 5.80.1-nightly-7293dfa2ff346b761eadb45acc95dc83369bcedd-20241227000333
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/react/web/ui/ConnectWallet/ConnectButton.js +11 -0
- package/dist/cjs/react/web/ui/ConnectWallet/ConnectButton.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/Details.js +59 -16
- package/dist/cjs/react/web/ui/ConnectWallet/Details.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/NetworkSelector.js +48 -24
- package/dist/cjs/react/web/ui/ConnectWallet/NetworkSelector.js.map +1 -1
- package/dist/cjs/react/web/ui/components/ChainActiveDot.js +20 -0
- package/dist/cjs/react/web/ui/components/ChainActiveDot.js.map +1 -0
- package/dist/cjs/react/web/ui/components/ChainIcon.js +24 -29
- package/dist/cjs/react/web/ui/components/ChainIcon.js.map +1 -1
- package/dist/cjs/react/web/ui/components/fallbackChainIcon.js +9 -0
- package/dist/cjs/react/web/ui/components/fallbackChainIcon.js.map +1 -0
- package/dist/cjs/react/web/ui/prebuilt/Chain/icon.js +44 -28
- package/dist/cjs/react/web/ui/prebuilt/Chain/icon.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/ConnectButton.js +11 -0
- package/dist/esm/react/web/ui/ConnectWallet/ConnectButton.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/Details.js +59 -17
- package/dist/esm/react/web/ui/ConnectWallet/Details.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/NetworkSelector.js +45 -21
- package/dist/esm/react/web/ui/ConnectWallet/NetworkSelector.js.map +1 -1
- package/dist/esm/react/web/ui/components/ChainActiveDot.js +17 -0
- package/dist/esm/react/web/ui/components/ChainActiveDot.js.map +1 -0
- package/dist/esm/react/web/ui/components/ChainIcon.js +22 -28
- package/dist/esm/react/web/ui/components/ChainIcon.js.map +1 -1
- package/dist/esm/react/web/ui/components/fallbackChainIcon.js +6 -0
- package/dist/esm/react/web/ui/components/fallbackChainIcon.js.map +1 -0
- package/dist/esm/react/web/ui/prebuilt/Chain/icon.js +42 -28
- package/dist/esm/react/web/ui/prebuilt/Chain/icon.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/react/core/hooks/connection/ConnectButtonProps.d.ts +5 -0
- package/dist/types/react/core/hooks/connection/ConnectButtonProps.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/ConnectButton.d.ts +11 -0
- package/dist/types/react/web/ui/ConnectWallet/ConnectButton.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/Details.d.ts +34 -1
- package/dist/types/react/web/ui/ConnectWallet/Details.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/NetworkSelector.d.ts +46 -1
- package/dist/types/react/web/ui/ConnectWallet/NetworkSelector.d.ts.map +1 -1
- package/dist/types/react/web/ui/components/ChainActiveDot.d.ts +10 -0
- package/dist/types/react/web/ui/components/ChainActiveDot.d.ts.map +1 -0
- package/dist/types/react/web/ui/components/ChainIcon.d.ts +8 -0
- package/dist/types/react/web/ui/components/ChainIcon.d.ts.map +1 -1
- package/dist/types/react/web/ui/components/fallbackChainIcon.d.ts +6 -0
- package/dist/types/react/web/ui/components/fallbackChainIcon.d.ts.map +1 -0
- package/dist/types/react/web/ui/prebuilt/Chain/icon.d.ts +18 -0
- package/dist/types/react/web/ui/prebuilt/Chain/icon.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/react/core/hooks/connection/ConnectButtonProps.ts +6 -0
- package/src/react/web/ui/ConnectWallet/ConnectButton.tsx +11 -0
- package/src/react/web/ui/ConnectWallet/Details.test.tsx +55 -0
- package/src/react/web/ui/ConnectWallet/Details.tsx +176 -98
- package/src/react/web/ui/ConnectWallet/NetworkSelector.test.tsx +189 -0
- package/src/react/web/ui/ConnectWallet/NetworkSelector.tsx +117 -76
- package/src/react/web/ui/components/ChainActiveDot.tsx +17 -0
- package/src/react/web/ui/components/ChainIcon.test.tsx +60 -0
- package/src/react/web/ui/components/ChainIcon.tsx +27 -31
- package/src/react/web/ui/components/fallbackChainIcon.ts +6 -0
- package/src/react/web/ui/prebuilt/Chain/icon.test.tsx +150 -0
- package/src/react/web/ui/prebuilt/Chain/icon.tsx +53 -31
- package/src/version.ts +1 -1
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
import { type UseQueryOptions, useQuery } from "@tanstack/react-query";
|
4
4
|
import type { JSX } from "react";
|
5
|
+
import type { Chain } from "../../../../../chains/types.js";
|
5
6
|
import { getChainMetadata } from "../../../../../chains/utils.js";
|
6
7
|
import type { ThirdwebClient } from "../../../../../client/client.js";
|
7
8
|
import { getFunctionId } from "../../../../../utils/function-id.js";
|
@@ -122,37 +123,8 @@ export function ChainIcon({
|
|
122
123
|
}: ChainIconProps) {
|
123
124
|
const { chain } = useChainContext();
|
124
125
|
const iconQuery = useQuery({
|
125
|
-
queryKey:
|
126
|
-
|
127
|
-
chain.id,
|
128
|
-
{
|
129
|
-
resolver:
|
130
|
-
typeof iconResolver === "string"
|
131
|
-
? iconResolver
|
132
|
-
: typeof iconResolver === "function"
|
133
|
-
? getFunctionId(iconResolver)
|
134
|
-
: undefined,
|
135
|
-
},
|
136
|
-
] as const,
|
137
|
-
queryFn: async () => {
|
138
|
-
if (typeof iconResolver === "string") {
|
139
|
-
return iconResolver;
|
140
|
-
}
|
141
|
-
if (typeof iconResolver === "function") {
|
142
|
-
return iconResolver();
|
143
|
-
}
|
144
|
-
// Check if the chain object already has "icon"
|
145
|
-
if (chain.icon?.url) {
|
146
|
-
return resolveScheme({ uri: chain.icon.url, client });
|
147
|
-
}
|
148
|
-
const possibleUrl = await getChainMetadata(chain).then(
|
149
|
-
(data) => data.icon?.url,
|
150
|
-
);
|
151
|
-
if (!possibleUrl) {
|
152
|
-
throw new Error("Failed to resolve icon for chain");
|
153
|
-
}
|
154
|
-
return resolveScheme({ uri: possibleUrl, client });
|
155
|
-
},
|
126
|
+
queryKey: getQueryKeys({ chainId: chain.id, iconResolver }),
|
127
|
+
queryFn: async () => fetchChainIcon({ chain, client, iconResolver }),
|
156
128
|
...queryOptions,
|
157
129
|
});
|
158
130
|
|
@@ -166,3 +138,53 @@ export function ChainIcon({
|
|
166
138
|
|
167
139
|
return <img src={iconQuery.data} {...restProps} alt={restProps.alt} />;
|
168
140
|
}
|
141
|
+
|
142
|
+
/**
|
143
|
+
* @internal Exported for tests only
|
144
|
+
*/
|
145
|
+
export async function fetchChainIcon(props: {
|
146
|
+
chain: Chain;
|
147
|
+
client: ThirdwebClient;
|
148
|
+
iconResolver?: string | (() => string) | (() => Promise<string>);
|
149
|
+
}) {
|
150
|
+
const { chain, client, iconResolver } = props;
|
151
|
+
if (typeof iconResolver === "string") {
|
152
|
+
return iconResolver;
|
153
|
+
}
|
154
|
+
if (typeof iconResolver === "function") {
|
155
|
+
return iconResolver();
|
156
|
+
}
|
157
|
+
// Check if the chain object already has "icon"
|
158
|
+
if (chain.icon?.url) {
|
159
|
+
return resolveScheme({ uri: chain.icon.url, client });
|
160
|
+
}
|
161
|
+
const possibleUrl = await getChainMetadata(chain)
|
162
|
+
.then((data) => data.icon?.url)
|
163
|
+
.catch(() => undefined);
|
164
|
+
if (!possibleUrl) {
|
165
|
+
throw new Error("Failed to resolve icon for chain");
|
166
|
+
}
|
167
|
+
return resolveScheme({ uri: possibleUrl, client });
|
168
|
+
}
|
169
|
+
|
170
|
+
/**
|
171
|
+
* @internal
|
172
|
+
*/
|
173
|
+
export function getQueryKeys(props: {
|
174
|
+
chainId: number;
|
175
|
+
iconResolver?: string | (() => string) | (() => Promise<string>);
|
176
|
+
}) {
|
177
|
+
const { chainId, iconResolver } = props;
|
178
|
+
return [
|
179
|
+
"_internal_chain_icon_",
|
180
|
+
chainId,
|
181
|
+
{
|
182
|
+
resolver:
|
183
|
+
typeof iconResolver === "string"
|
184
|
+
? iconResolver
|
185
|
+
: typeof iconResolver === "function"
|
186
|
+
? getFunctionId(iconResolver)
|
187
|
+
: undefined,
|
188
|
+
},
|
189
|
+
] as const;
|
190
|
+
}
|
package/src/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = "5.80.1-nightly-
|
1
|
+
export const version = "5.80.1-nightly-7293dfa2ff346b761eadb45acc95dc83369bcedd-20241227000333";
|