Skip to content

Commit

Permalink
fix: add options for split subvariant
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Sep 30, 2023
1 parent 77da36b commit a63b303
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
6 changes: 5 additions & 1 deletion packages/widget/src/stores/StoreProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ export const StoreProvider: React.FC<PropsWithChildren<WidgetConfigProps>> = ({
}) => {
return (
<SplitSubvariantStoreProvider
state={config.subvariant === 'split' ? 'swap' : undefined}
state={
config.subvariant === 'split'
? config.subvariantOptions || 'swap'
: undefined
}
>
<HeaderStoreProvider namePrefix={config?.keyPrefix}>
<ChainOrderStoreProvider namePrefix={config?.keyPrefix}>
Expand Down
8 changes: 5 additions & 3 deletions packages/widget/src/stores/settings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,19 @@ export interface SendToWalletStore extends SendToWalletState {
setSendToWallet(value: boolean): void;
}

export type SplitSubvariantOptions = 'bridge' | 'swap';

export interface SplitSubvariantState {
state?: 'swap' | 'bridge';
setState(state: 'swap' | 'bridge'): void;
state?: SplitSubvariantOptions;
setState(state: SplitSubvariantOptions): void;
}

export type SplitSubvariantStore = UseBoundStoreWithEqualityFn<
StoreApi<SplitSubvariantState>
>;

export interface SplitSubvariantProps {
state?: 'swap' | 'bridge';
state?: SplitSubvariantOptions;
}

export type SplitSubvariantProviderProps =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const shouldRecreateStore = (
props: SplitSubvariantProps,
) => {
const { state } = store.getState();
return (!state && props.state) || (state && !props.state);
return state !== props.state;
};

export function SplitSubvariantStoreProvider({
Expand Down
2 changes: 2 additions & 0 deletions packages/widget/src/types/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
import type { TypographyOptions } from '@mui/material/styles/createTypography';
import type { CSSProperties, ReactNode, RefObject } from 'react';
import type { LanguageKey, LanguageResources } from '../providers';
import type { SplitSubvariantOptions } from '../stores';

export type WidgetVariant = 'default' | 'expandable' | 'drawer';

Expand Down Expand Up @@ -121,6 +122,7 @@ export interface WidgetConfig {

variant?: WidgetVariant;
subvariant?: WidgetSubvariant;
subvariantOptions?: SplitSubvariantOptions;

appearance?: Appearance;
theme?: ThemeConfig;
Expand Down

0 comments on commit a63b303

Please sign in to comment.