Skip to content

Commit

Permalink
fix: react to change in NETWORKS config passed to FuelProvider (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuizAsFight authored Oct 12, 2024
1 parent 2622540 commit cd36eda
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/forty-bugs-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuels/react": patch
---

fix: react to change in NETWORKS config passed to FuelProvider
3 changes: 3 additions & 0 deletions packages/react/src/hooks/useIsSupportedNetwork.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Provider } from 'fuels';
import { useMemo } from 'react';
import { type UseNamedQueryParams, useNamedQuery } from '../core';
import { useFuel } from '../providers';
import { QUERY_KEYS } from '../utils';
Expand Down Expand Up @@ -31,9 +32,11 @@ export function useIsSupportedNetwork(params?: UseIsSupportedNetwork) {
const { network } = useNetwork();
const { isConnected } = useIsConnected();
const { currentConnector } = useCurrentConnector();

return useNamedQuery('isSupportedNetwork', {
queryKey: QUERY_KEYS.isSupportedNetwork(
currentConnector?.name,
networks,
network,
isConnected,
),
Expand Down
3 changes: 3 additions & 0 deletions packages/react/src/utils/queryKeys.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { QueryKey } from '@tanstack/react-query';
import type { BytesLike, Network, Provider } from 'fuels';
import type { NetworkConfig } from '../types';

export const QUERY_KEYS = {
base: ['fuel'] as QueryKey,
Expand Down Expand Up @@ -86,11 +87,13 @@ export const QUERY_KEYS = {
},
isSupportedNetwork: (
connectorName: string | null | undefined,
networks: Array<NetworkConfig>,
network: Partial<Network> | null,
isConnected: boolean,
): QueryKey => {
const queryKey = QUERY_KEYS.base.concat('isSupportedNetwork');
if (connectorName) queryKey.push(connectorName);
if (networks) queryKey.push(networks);
if (network) queryKey.push(network);
if (isConnected) queryKey.push(isConnected);
return queryKey;
Expand Down

0 comments on commit cd36eda

Please sign in to comment.