From 82aa041997eddf56d24ba97da3ba61f38e1cda7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ti=E1=BA=BFn=20Nguy=E1=BB=85n=20Kh=E1=BA=AFc?= Date: Wed, 11 Sep 2024 21:57:06 +1200 Subject: [PATCH] refactor!: rename wallets "reconnect" to "initialize" (#165) --- .changeset/clean-buttons-jump.md | 5 +++++ packages/react/src/contexts/index.tsx | 20 +++++++++---------- ...onnector.ts => use-wallets-initializer.ts} | 12 +++++------ packages/react/src/index.ts | 2 +- 4 files changed, 22 insertions(+), 17 deletions(-) create mode 100644 .changeset/clean-buttons-jump.md rename packages/react/src/hooks/{use-wallets-reconnector.ts => use-wallets-initializer.ts} (65%) diff --git a/.changeset/clean-buttons-jump.md b/.changeset/clean-buttons-jump.md new file mode 100644 index 00000000..bcb3aab1 --- /dev/null +++ b/.changeset/clean-buttons-jump.md @@ -0,0 +1,5 @@ +--- +"@reactive-dot/react": minor +--- + +BREAKING: renamed wallets "reconnect" to "initialize". diff --git a/packages/react/src/contexts/index.tsx b/packages/react/src/contexts/index.tsx index 888ba403..b51485d8 100644 --- a/packages/react/src/contexts/index.tsx +++ b/packages/react/src/contexts/index.tsx @@ -1,4 +1,4 @@ -import { useWalletsReconnector } from "../hooks/use-wallets-reconnector.js"; +import { useWalletsInitializer } from "../hooks/use-wallets-initializer.js"; import { configAtom } from "../stores/config.js"; import { MutationEventSubjectContext } from "./mutation.js"; import type { Config } from "@reactive-dot/core"; @@ -26,9 +26,9 @@ export type ReDotProviderProps = PropsWithChildren<{ config: Config; /** - * Whether or not to reconnect previously connected wallets on mount. + * Whether or not to initialize wallets on mount. */ - autoReconnectWallets?: boolean; + autoInitializeWallets?: boolean; }>; function ReDotHydrator(props: ReDotProviderProps) { @@ -37,12 +37,12 @@ function ReDotHydrator(props: ReDotProviderProps) { return null; } -function WalletsReconnector() { - const [_, reconnect] = useWalletsReconnector(); +function WalletsInitializer() { + const [_, initialize] = useWalletsInitializer(); useEffect(() => { - reconnect(); - }, [reconnect]); + initialize(); + }, [initialize]); return null; } @@ -54,15 +54,15 @@ function WalletsReconnector() { * @returns React element */ export function ReDotProvider({ - autoReconnectWallets = true, + autoInitializeWallets = true, ...props }: ReDotProviderProps) { return ( - {autoReconnectWallets && ( + {autoInitializeWallets && ( - + )} >(IDLE); - const reconnect = useCallback(async () => { + const initialize = useCallback(async () => { setState(PENDING); initializeWallets(wallets); }, [wallets]); - return [state, reconnect] as [ + return [state, initialize] as [ state: typeof state, - reconnect: typeof reconnect, + initialize: typeof initialize, ]; } diff --git a/packages/react/src/index.ts b/packages/react/src/index.ts index 46b3f56d..1a3854f1 100644 --- a/packages/react/src/index.ts +++ b/packages/react/src/index.ts @@ -30,5 +30,5 @@ export { useSigner } from "./hooks/use-signer.js"; export { useTypedApi } from "./hooks/use-typed-api.js"; export { useWalletConnector } from "./hooks/use-wallet-connector.js"; export { useWalletDisconnector } from "./hooks/use-wallet-disconnector.js"; -export { useWalletsReconnector } from "./hooks/use-wallets-reconnector.js"; +export { useWalletsInitializer } from "./hooks/use-wallets-initializer.js"; export { useConnectedWallets, useWallets } from "./hooks/use-wallets.js";