Skip to content

Commit

Permalink
refactor rest for ConnectWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacharyCouchman committed Jul 19, 2023
1 parent fbcb27f commit e4a9058
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
addProviderChainListener,
removeProviderEventListeners,
} from '../../lib/providerEvents';
import { SharedViews } from '../../context/view-context/ViewContext';

export interface ConnectLoaderProps {
children?: React.ReactNode;
Expand Down Expand Up @@ -97,12 +98,12 @@ export function ConnectLoader({

useEffect(() => {
if (!web3Provider) {
connectLoaderDispatch({
payload: {
type: ConnectLoaderActions.UPDATE_CONNECTION_STATUS,
connectionStatus: ConnectionStatus.NOT_CONNECTED_NO_PROVIDER,
},
});
// connectLoaderDispatch({
// payload: {
// type: ConnectLoaderActions.UPDATE_CONNECTION_STATUS,
// connectionStatus: ConnectionStatus.NOT_CONNECTED_NO_PROVIDER,
// },
// });
return () => {};
}

Expand Down Expand Up @@ -146,7 +147,7 @@ export function ConnectLoader({
payload: {
type: ConnectLoaderActions.UPDATE_CONNECTION_STATUS,
connectionStatus: ConnectionStatus.CONNECTED_WRONG_NETWORK,
deepLink: ConnectWidgetViews.SWITCH_NETWORK,
deepLink: SharedViews.SWITCH_NETWORK,
},
});
}
Expand Down Expand Up @@ -248,7 +249,7 @@ export function ConnectLoader({
payload: {
type: ConnectLoaderActions.UPDATE_CONNECTION_STATUS,
connectionStatus: ConnectionStatus.CONNECTED_WRONG_NETWORK,
deepLink: ConnectWidgetViews.SWITCH_NETWORK,
deepLink: SharedViews.SWITCH_NETWORK,
},
});
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createContext } from 'react';
import { ConnectWidgetViews } from '../view-context/ConnectViewContextTypes';
import { SharedViews } from '../view-context/ViewContext';

export enum ConnectionStatus {
NOT_CONNECTED_NO_PROVIDER = 'NOT_CONNECTED_NO_PROVIDER',
Expand All @@ -12,7 +13,7 @@ export enum ConnectionStatus {

export interface ConnectLoaderState {
connectionStatus: ConnectionStatus;
deepLink?: ConnectWidgetViews;
deepLink?: ConnectWidgetViews | SharedViews;
}

export const initialConnectLoaderState: ConnectLoaderState = {
Expand All @@ -37,7 +38,7 @@ export enum ConnectLoaderActions {
export interface UpdateConnectionStatusPayload {
type: ConnectLoaderActions.UPDATE_CONNECTION_STATUS;
connectionStatus: ConnectionStatus;
deepLink?: ConnectWidgetViews;
deepLink?: ConnectWidgetViews | SharedViews;
}

// eslint-disable-next-line @typescript-eslint/naming-convention
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { ImmutableNetworkHero } from '../../components/Hero/ImmutableNetworkHero
export interface ConnectWidgetProps {
params?: ConnectWidgetParams;
config: StrongCheckoutWidgetsConfig
deepLink?: ConnectWidgetViews;
deepLink?: ConnectWidgetViews | SharedViews;
sendCloseEventOverride?: () => void;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import { Web3Provider } from '@ethersproject/providers';
import { createContext } from 'react';
import { Checkout, WalletProviderName } from '@imtbl/checkout-sdk';
// import { ProviderSubscription } from '../../../lib/providerSubscription';

export interface ConnectState {
checkout: Checkout | null;
provider: Web3Provider | null;
// providerSubscription: ProviderSubscription | null;
walletProvider: WalletProviderName | null;
sendCloseEvent: () => void;
}

export const initialConnectState: ConnectState = {
checkout: null,
provider: null,
// providerSubscription: null,
walletProvider: null,
sendCloseEvent: () => {},
};
Expand Down Expand Up @@ -82,19 +79,9 @@ export const connectReducer: Reducer<ConnectState, ConnectAction> = (
checkout: action.payload.checkout,
};
case ConnectActions.SET_PROVIDER:
// eslint-disable-next-line no-case-declarations
// let { providerSubscription } = state;

// if (providerSubscription) {
// providerSubscription.unsubscribe();
// }
// providerSubscription = new ProviderSubscription(action.payload.provider, () => {}, () => {});
// providerSubscription.subscribe();

return {
...state,
provider: action.payload.provider,
// providerSubscription,
};
case ConnectActions.SET_PROVIDER_NAME:
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ConnectContext, ConnectActions } from '../context/ConnectContext';
import {
ViewContext,
ViewActions,
SharedViews,
} from '../../../context/view-context/ViewContext';

export interface ReadyToConnectProps {
Expand Down Expand Up @@ -39,7 +40,7 @@ export function ReadyToConnect({ targetChainId }: ReadyToConnectProps) {
viewDispatch({
payload: {
type: ViewActions.UPDATE_VIEW,
view: { type: ConnectWidgetViews.SWITCH_NETWORK },
view: { type: SharedViews.SWITCH_NETWORK },
},
});
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import { getL1ChainId } from '../../../lib/networkUtils';
import {
ViewContext,
ViewActions,
SharedViews,
} from '../../../context/view-context/ViewContext';

export function SwitchNetworkEth() {
const { viewDispatch } = useContext(ViewContext);
const { connectDispatch, connectState } = useContext(ConnectContext);
const { checkout, provider, sendCloseEvent } = connectState;
const { heading, body, button } = text.views[ConnectWidgetViews.SWITCH_NETWORK].eth;
const { heading, body, button } = text.views[SharedViews.SWITCH_NETWORK].eth;

const [buttonText, setButtonText] = useState(button.text);

Expand Down

0 comments on commit e4a9058

Please sign in to comment.