Skip to content

Commit

Permalink
feat: make chains, bridges and exchanges config options reactive (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov authored Jun 5, 2024
1 parent 38949c1 commit cf0de31
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
1 change: 0 additions & 1 deletion packages/widget-embedded/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export const queryClient = new QueryClient({
defaultOptions: {
queries: {
enabled: true,
staleTime: 3_600_000,
refetchInterval: false,
refetchIntervalInBackground: false,
refetchOnWindowFocus: true,
Expand Down
10 changes: 5 additions & 5 deletions packages/widget-playground/src/defaultWidgetConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export const widgetBaseConfig: WidgetConfig = {
// disabledUI: ['toAddress', 'fromAmount', 'toToken', 'fromToken'],
// requiredUI: ['toAddress'],
// slippage: 0.003,
insurance: true,
sdkConfig: {
apiUrl: 'https://li.quest/v1',
rpcUrls: {
Expand Down Expand Up @@ -72,6 +71,7 @@ export const widgetBaseConfig: WidgetConfig = {
// types: {
// allow: [ChainType.EVM],
// },
// allow: [ChainId.ETH, ChainId.OPT],
// },
tokens: {
featured: [
Expand Down Expand Up @@ -188,12 +188,12 @@ export const widgetBaseConfig: WidgetConfig = {
],
},
// bridges: {
// allow: ['stargate'],
// deny: ['connext'],
// allow: ['stargate'],
// deny: ['connext'],
// },
// languages: {
// allow: ['uk'],
// deny: ['uk'],
// allow: ['uk'],
// deny: ['uk'],
// },
// languageResources: {
// en: {
Expand Down
11 changes: 9 additions & 2 deletions packages/widget/src/hooks/useAvailableChains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ export const useAvailableChains = () => {
const { chains } = useWidgetConfig();
const { providers } = useHasExternalWalletProvider();
const { data, isLoading } = useQuery({
queryKey: ['chains', providers, chains?.types] as const,
queryKey: [
'chains',
providers,
chains?.types,
chains?.allow,
chains?.deny,
chains?.from,
chains?.to,
] as const,
queryFn: async ({ queryKey: [, providers, chainTypes] }) => {
const chainTypesRequest = (
providers.length > 0 ? providers : supportedChainTypes
Expand All @@ -25,7 +33,6 @@ export const useAvailableChains = () => {
return availableChains;
},
refetchInterval: 300000,
staleTime: 300000,
});

const getChainById = useCallback(
Expand Down
1 change: 0 additions & 1 deletion packages/widget/src/hooks/useGasRecommendation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,5 @@ export const useGasRecommendation = (
},
enabled: checkRecommendationLiFuel || checkRecommendationMaxButton,
refetchInterval,
staleTime: refetchInterval,
});
};
9 changes: 7 additions & 2 deletions packages/widget/src/hooks/useTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import { isItemAllowed } from '../utils/item.js';
export const useTools = () => {
const { bridges, exchanges } = useWidgetConfig();
const { data } = useQuery({
queryKey: ['tools'],
queryKey: [
'tools',
bridges?.allow,
bridges?.deny,
exchanges?.allow,
exchanges?.deny,
],
queryFn: async (): Promise<ToolsResponse> => {
const tools = await getTools();
const result = {
Expand All @@ -30,7 +36,6 @@ export const useTools = () => {
return result;
},
refetchInterval: 180000,
staleTime: 180000,
});

return { tools: data };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,5 @@ export const EVMBaseProvider: FC<PropsWithChildren> = ({ children }) => {
}
}, [chains, connectors, wagmiConfig]);

return (
<WagmiProvider config={wagmiConfig} reconnectOnMount={false}>
{children}
</WagmiProvider>
);
return <WagmiProvider config={wagmiConfig}>{children}</WagmiProvider>;
};

0 comments on commit cf0de31

Please sign in to comment.