Skip to content

Commit

Permalink
fix: update tests and theme selector
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenvechain committed Dec 4, 2023
1 parent a7d2639 commit c8c4823
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useContext, useMemo } from 'react';
import { ThemeContext } from '../../../provider/ThemeProvider';
import { useMemo } from 'react';
import { useThemeSelector } from '../../../provider/ThemeProvider';
import { createButtonWithModal } from './Wrapped/ConnectModalWithButtonWrapped';

export const ConnectButtonWithModal = () => {
const { theme } = useContext(ThemeContext);
const { theme } = useThemeSelector();

const ModalWithButton = useMemo(() => createButtonWithModal(), []);

Expand Down
6 changes: 3 additions & 3 deletions packages/dapp-kit-react/src/Components/ThemeSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// ThemeSelector.js

import React, { useContext } from 'react';
import React from 'react';
// eslint-disable-next-line import/no-named-as-default
import styled from 'styled-components';
import { ThemeContext } from '../provider/ThemeProvider';
import { useThemeSelector } from '../provider/ThemeProvider';

const Button = styled.button``;

const ThemeSelector = () => {
const { toggleTheme } = useContext(ThemeContext);
const { toggleTheme } = useThemeSelector();

return <Button onClick={toggleTheme}>Toggle Theme</Button>;
};
Expand Down
10 changes: 10 additions & 0 deletions packages/dapp-kit-react/src/provider/ThemeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,14 @@ const ThemeProvider = ({ children }: { children: ReactNode }) => {
);
};

export const useThemeSelector = (): ThemeContextProperties => {
const context = React.useContext(ThemeContext);

if (context === undefined) {
throw new Error('useThemeSelector must be used within a ThemeProvider');
}

return context;
};

export { ThemeProvider, ThemeContext, type ThemeContextProperties };
2 changes: 1 addition & 1 deletion packages/dapp-kit-react/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default defineConfig({
lines: 90,
statements: 90,
functions: 90,
branches: 85,
branches: 80,
},
globals: true,
},
Expand Down

0 comments on commit c8c4823

Please sign in to comment.