Skip to content

Commit

Permalink
refactor!: rename wallets "reconnect" to "initialize" (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
tien authored Sep 11, 2024
1 parent c9a3aab commit 82aa041
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/clean-buttons-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@reactive-dot/react": minor
---

BREAKING: renamed wallets "reconnect" to "initialize".
20 changes: 10 additions & 10 deletions packages/react/src/contexts/index.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand All @@ -54,15 +54,15 @@ function WalletsReconnector() {
* @returns React element
*/
export function ReDotProvider({
autoReconnectWallets = true,
autoInitializeWallets = true,
...props
}: ReDotProviderProps) {
return (
<ScopeProvider atoms={[configAtom]}>
<ReDotHydrator {...props} />
{autoReconnectWallets && (
{autoInitializeWallets && (
<Suspense>
<WalletsReconnector />
<WalletsInitializer />
</Suspense>
)}
<MutationEventSubjectContext.Provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ import { initializeWallets } from "@reactive-dot/core/wallets.js";
import { useCallback, useState } from "react";

/**
* Hook for reconnecting wallets.
* Hook for initializing wallets.
*
* @returns The reconnection state and reconnect function
* @returns The initialization state and initialize function
*/
export function useWalletsReconnector() {
export function useWalletsInitializer() {
const wallets = useWallets();

const [state, setState] = useState<AsyncValue<true, ReDotError>>(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,
];
}
2 changes: 1 addition & 1 deletion packages/react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

0 comments on commit 82aa041

Please sign in to comment.