Skip to content

Commit

Permalink
fix: make config optional
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Jun 8, 2022
1 parent 29d0bc0 commit ea14369
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/widget/src/AppDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { WidgetConfig } from './types';

export type AppDrawerProps = DrawerProps & {
elementRef?: RefObject<HTMLDivElement>;
config: WidgetConfig;
config?: WidgetConfig;
};

export interface AppDrawerBase {
Expand Down
2 changes: 1 addition & 1 deletion packages/widget/src/AppProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { WalletProvider } from './providers/WalletProvider';
import { WidgetProvider } from './providers/WidgetProvider';

export interface AppProps {
config: WidgetConfig;
config?: WidgetConfig;
}

const QueryProvider = QueryClientProvider as FC<
Expand Down
14 changes: 7 additions & 7 deletions packages/widget/src/providers/WidgetProvider/WidgetProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ export const useWidgetConfig = (): WidgetContextProps =>

export const WidgetProvider: React.FC<
React.PropsWithChildren<WidgetProviderProps>
> = ({ children, config: { fromChain, toChain, ...other } }) => {
> = ({
children,
config: { fromChain, fromToken, toChain, toToken, ...config } = {},
}) => {
const value = useMemo((): WidgetContextProps => {
const config = {
...other,
};
try {
return {
...config,
Expand All @@ -37,14 +37,14 @@ export const WidgetProvider: React.FC<
: typeof toChain === 'string'
? getChainByKey(toChain.toLowerCase() as ChainKey).id
: ChainId.ETH,
fromToken: config.fromToken?.toLowerCase(),
toToken: config.toToken?.toLowerCase(),
fromToken: fromToken?.toLowerCase(),
toToken: toToken?.toLowerCase(),
};
} catch (e) {
console.warn(e);
return config;
}
}, [fromChain, other, toChain]);
}, [config, fromChain, fromToken, toChain, toToken]);
return (
<WidgetContext.Provider value={value}>{children}</WidgetContext.Provider>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/widget/src/providers/WidgetProvider/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export interface WidgetContextProps extends WidgetConfig {
}

export interface WidgetProviderProps {
config: WidgetConfig;
config?: WidgetConfig;
}

0 comments on commit ea14369

Please sign in to comment.