Skip to content

Commit

Permalink
feat: rename loader screen
Browse files Browse the repository at this point in the history
  • Loading branch information
totraev committed Nov 21, 2024
1 parent f67f226 commit 865ffdf
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
10 changes: 5 additions & 5 deletions src/context/Chain.context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ const Context = createContext<Connectors>(defaultState);

export function ChainProvider({ children, context, config }: PropsWithChildren<ProviderProps>) {
const [connectors, setConnectors] = useState(defaultState);
const { addChain, displayLoading, displayTermsOfService } = useAppState();
const { addChain, displayLoader, displayTermsOfService } = useAppState();

const init = useCallback(async () => {
displayLoading?.();
displayLoader?.();

const metadataArr = Object.values(metadata);
const connectorArr = await Promise.all(metadataArr.map((data) => WalletConnector.create(data, context, config)));
Expand All @@ -40,9 +40,9 @@ export function ChainProvider({ children, context, config }: PropsWithChildren<P
}, []);

useEffect(() => {
if (!displayLoading || !addChain || !setConnectors || !displayTermsOfService) return;
if (!displayLoader || !addChain || !setConnectors || !displayTermsOfService) return;

displayLoading();
displayLoader();

init().then((connectors) => {
setConnectors(connectors);
Expand All @@ -53,7 +53,7 @@ export function ChainProvider({ children, context, config }: PropsWithChildren<P

displayTermsOfService();
});
}, [displayLoading, addChain, setConnectors, init, displayTermsOfService]);
}, [displayLoader, addChain, setConnectors, init, displayTermsOfService]);

return <Context.Provider value={connectors}>{children}</Context.Provider>;
}
Expand Down
4 changes: 2 additions & 2 deletions src/state/state.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type Screen<T extends string = string> = {
};

type Screens =
| Screen<"LOADING">
| Screen<"LOADER">
| Screen<"TERMS_OF_SERVICE">
| Screen<"CHAINS">
| Screen<"WALLETS">
Expand All @@ -22,7 +22,7 @@ export interface State {
export interface Actions {
open?: () => void;
close?: () => void;
displayLoading?: () => void;
displayLoader?: () => void;
displayChains?: () => void;
displayWallets?: (chain: string) => void;
displayInscriptions?: () => void;
Expand Down
8 changes: 2 additions & 6 deletions src/state/state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ const StateContext = createContext<State & Actions>(defaultState);
export function StateProvider({ children }: PropsWithChildren) {
const [state, setState] = useState<State>(defaultState);

// useEffect(() => {
// console.log(state);
// }, [state]);

const actions: Actions = useMemo(
() => ({
open: () => {
Expand All @@ -29,8 +25,8 @@ export function StateProvider({ children }: PropsWithChildren) {
setState((state) => ({ ...state, visible: false }));
},

displayLoading: () => {
setState((state) => ({ ...state, screen: { type: "LOADING" } }));
displayLoader: () => {
setState((state) => ({ ...state, screen: { type: "LOADER" } }));
},

displayTermsOfService: () => {
Expand Down
6 changes: 3 additions & 3 deletions src/widgets/WalletProvider/components/WalletDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import type { IChain, IWallet } from "@/core/types";
import { Screen } from "./Screen";

export function WalletDialog() {
const { visible, screen, close, selectWallet, displayLoading, displayChains, displayInscriptions } = useAppState();
const { visible, screen, close, selectWallet, displayLoader, displayChains, displayInscriptions } = useAppState();
const { showAgain, toggleShowAgain, toggleLockInscriptions } = useInscriptionProvider();
const connectors = useChainProviders();

const handleSelectWallet = useCallback(
async (chain: IChain, wallet: IWallet) => {
displayLoading?.();
displayLoader?.();

const connector = connectors[chain.id];
const connectedWallet = await connector?.connect(wallet.id);
Expand All @@ -30,7 +30,7 @@ export function WalletDialog() {
displayChains?.();
}
},
[displayLoading, selectWallet, displayInscriptions, connectors, showAgain],
[displayLoader, selectWallet, displayInscriptions, connectors, showAgain],
);

const handleToggleInscriptions = useCallback(
Expand Down

0 comments on commit 865ffdf

Please sign in to comment.