Skip to content

Commit

Permalink
[SDK] Fix caching issue with headless UI when custom resolvers are used
Browse files Browse the repository at this point in the history
  • Loading branch information
kien-ngo committed Dec 9, 2024
1 parent f69d1aa commit 63e00b0
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 5 deletions.
13 changes: 12 additions & 1 deletion packages/thirdweb/src/react/web/ui/prebuilt/Chain/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,18 @@ export function ChainIcon({
}: ChainIconProps) {
const { chain } = useChainContext();
const iconQuery = useQuery({
queryKey: ["_internal_chain_icon_", chain.id] as const,
queryKey: [
"_internal_chain_icon_",
chain.id,
{
resolver:
typeof iconResolver === "string"
? iconResolver
: typeof iconResolver === "function"
? iconResolver.toString()
: undefined,
},
] as const,
queryFn: async () => {
if (typeof iconResolver === "string") {
return iconResolver;
Expand Down
13 changes: 12 additions & 1 deletion packages/thirdweb/src/react/web/ui/prebuilt/Chain/name.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,18 @@ export function ChainName({
}: ChainNameProps) {
const { chain } = useChainContext();
const nameQuery = useQuery({
queryKey: ["_internal_chain_name_", chain.id] as const,
queryKey: [
"_internal_chain_name_",
chain.id,
{
resolver:
typeof nameResolver === "string"
? nameResolver

Check warning on line 164 in packages/thirdweb/src/react/web/ui/prebuilt/Chain/name.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/prebuilt/Chain/name.tsx#L164

Added line #L164 was not covered by tests
: typeof nameResolver === "function"
? nameResolver.toString()
: undefined,

Check warning on line 167 in packages/thirdweb/src/react/web/ui/prebuilt/Chain/name.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/prebuilt/Chain/name.tsx#L166-L167

Added lines #L166 - L167 were not covered by tests
},
] as const,
queryFn: async () => {
if (typeof nameResolver === "string") {
return nameResolver;
Expand Down
14 changes: 13 additions & 1 deletion packages/thirdweb/src/react/web/ui/prebuilt/Token/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,19 @@ export function TokenIcon({
}: TokenIconProps) {
const { address, client, chain } = useTokenContext();
const iconQuery = useQuery({
queryKey: ["_internal_token_icon_", chain.id, address] as const,
queryKey: [
"_internal_token_icon_",
chain.id,
address,
{
resolver:
typeof iconResolver === "string"
? iconResolver
: typeof iconResolver === "function"
? iconResolver.toString()
: undefined,
},
] as const,
queryFn: async () => {
if (typeof iconResolver === "string") {
return iconResolver;
Expand Down
14 changes: 13 additions & 1 deletion packages/thirdweb/src/react/web/ui/prebuilt/Token/name.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,19 @@ export function TokenName({
}: TokenNameProps) {
const { address, client, chain } = useTokenContext();
const nameQuery = useQuery({
queryKey: ["_internal_token_name_", chain.id, address] as const,
queryKey: [
"_internal_token_name_",
chain.id,
address,
{
resolver:
typeof nameResolver === "string"
? nameResolver
: typeof nameResolver === "function"
? nameResolver.toString()

Check warning on line 169 in packages/thirdweb/src/react/web/ui/prebuilt/Token/name.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/prebuilt/Token/name.tsx#L169

Added line #L169 was not covered by tests
: undefined,
},
] as const,
queryFn: async () => {
if (typeof nameResolver === "string") {
return nameResolver;
Expand Down
14 changes: 13 additions & 1 deletion packages/thirdweb/src/react/web/ui/prebuilt/Token/symbol.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,19 @@ export function TokenSymbol({
}: TokenSymbolProps) {
const { address, client, chain } = useTokenContext();
const symbolQuery = useQuery({
queryKey: ["_internal_token_symbol_", chain.id, address] as const,
queryKey: [
"_internal_token_symbol_",
chain.id,
address,
{
resolver:
typeof symbolResolver === "string"
? symbolResolver

Check warning on line 164 in packages/thirdweb/src/react/web/ui/prebuilt/Token/symbol.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/prebuilt/Token/symbol.tsx#L164

Added line #L164 was not covered by tests
: typeof symbolResolver === "function"
? symbolResolver.toString()

Check warning on line 166 in packages/thirdweb/src/react/web/ui/prebuilt/Token/symbol.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/prebuilt/Token/symbol.tsx#L166

Added line #L166 was not covered by tests
: undefined,
},
] as const,
queryFn: async () => {
if (typeof symbolResolver === "string") {
return symbolResolver;
Expand Down

0 comments on commit 63e00b0

Please sign in to comment.