Skip to content

Commit

Permalink
fix: restrict variations of config usage
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Jun 9, 2022
1 parent 2085bc6 commit 5ec0fcc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/widget/src/providers/WidgetProvider/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { WidgetConfig } from '../../types';

export interface WidgetContextProps extends WidgetConfig {
export type WidgetContextProps = WidgetConfig & {
fromChain?: number;
toChain?: number;
}
};

export interface WidgetProviderProps {
config?: WidgetConfig;
Expand Down
57 changes: 44 additions & 13 deletions packages/widget/src/types/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,54 @@ export type ThemeConfig = {
typography?: TypographyOptions;
};

export interface WidgetConfig {
export interface WidgetWalletCallbacks {
connect(): Signer;
disconnect(): void;
provideSigner(): Signer;
switchChain(): Signer;
addToken(): void;
}

interface WidgetConfigBase {
fromAmount?: number;
fromChain?: `${ChainKey}` | number;
fromToken?: string;
toChain?: `${ChainKey}` | number;
toToken?: string;
disabledChains?: number[];
disableInternalWalletManagement?: boolean;
walletCallbacks?: {
connect: { (): Signer };
disconnect: { (): void };
provideSigner: { (): Signer };
switchChain: { (): Signer };
addToken: { (): void };
};
containerStyle?: CSSProperties;
theme?: ThemeConfig;
appearance?: Appearance;
disableAppearance?: boolean;
}

type WidgetFromTokenConfig =
| {
fromChain: `${ChainKey}` | number;
fromToken?: string;
}
| {
fromChain?: never;
fromToken?: never;
};

type WidgetToTokenConfig =
| {
toChain: `${ChainKey}` | number;
toToken?: string;
}
| {
toChain?: never;
toToken?: never;
};

type WidgetWalletManagementConfig =
| {
disableInternalWalletManagement: true;
walletCallbacks: WidgetWalletCallbacks;
}
| {
disableInternalWalletManagement?: false;
walletCallbacks?: never;
};

export type WidgetConfig = WidgetConfigBase &
WidgetFromTokenConfig &
WidgetToTokenConfig &
WidgetWalletManagementConfig;

0 comments on commit 5ec0fcc

Please sign in to comment.