Skip to content

Commit

Permalink
refactor!: rename action hooks (#87)
Browse files Browse the repository at this point in the history
- `useResetQueryError` to `useQueryErrorResetter`
- `useConnectWallet` to `useWalletConnector`
- `useDisconnectWallet` to `useWalletDisconnector`
- `useReconnectWallets` to `useWalletsReconnector`
  • Loading branch information
tien authored Aug 6, 2024
1 parent 7c69fcc commit 94505d6
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 22 deletions.
10 changes: 10 additions & 0 deletions .changeset/nice-adults-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@reactive-dot/react": minor
---

**BREAKING**: rename action hooks

- `useResetQueryError` to `useQueryErrorResetter`
- `useConnectWallet` to `useWalletConnector`
- `useDisconnectWallet` to `useWalletDisconnector`
- `useReconnectWallets` to `useWalletsReconnector`
7 changes: 4 additions & 3 deletions apps/docs/docs/getting-started/connect-wallets.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,16 @@ export const config = {
import {
useConnectedWallets,
useWallets,
useConnectWallet,
useWalletConnector,
useWalletDisconnector,
} from "@reactive-dot/react";

export function Wallets() {
const wallets = useWallets();
const connectedWallets = useConnectedWallets();

const [_, connectWallet] = useConnectWallet();
const [__, disconnectWallet] = useDisconnectWallet();
const [_, connectWallet] = useWalletConnector();
const [__, disconnectWallet] = useWalletDisconnector();

return (
<section>
Expand Down
6 changes: 3 additions & 3 deletions apps/docs/docs/getting-started/query.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@ function QueryWithRefresh() {

## Retry failed query

Error from queries can be caught and reset using `ErrorBoundary` & [`useResetQueryError`](/api/react/function/useResetQueryError) hook.
Error from queries can be caught and reset using `ErrorBoundary` & [`useQueryErrorResetter`](/api/react/function/useQueryErrorResetter) hook.

```tsx
import { useResetQueryError } from "@reactive-dot/react";
import { useQueryErrorResetter } from "@reactive-dot/react";
import { ErrorBoundary, type FallbackProps } from "react-error-boundary";

function ErrorFallback(props: FallbackProps) {
Expand All @@ -221,7 +221,7 @@ function ErrorFallback(props: FallbackProps) {
}

function AppErrorBoundary() {
const resetQueryError = useResetQueryError();
const resetQueryError = useQueryErrorResetter();

return (
<ErrorBoundary
Expand Down
12 changes: 6 additions & 6 deletions apps/example/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import {
ReDotProvider,
useAccounts,
useBlock,
useConnectWallet,
useConnectedWallets,
useDisconnectWallet,
useLazyLoadQuery,
useLazyLoadQueryWithRefresh,
useMutation,
useMutationEffect,
useNativeTokenAmountFromPlanck,
useResetQueryError,
useQueryErrorResetter,
useWalletConnector,
useWalletDisconnector,
useWallets,
} from "@reactive-dot/react";
import { formatDistance } from "date-fns";
Expand Down Expand Up @@ -171,8 +171,8 @@ type WalletItemProps = {
function WalletItem(props: WalletItemProps) {
const connectedWallets = useConnectedWallets();

const [connectingState, connect] = useConnectWallet(props.wallet);
const [disconnectingState, disconnect] = useDisconnectWallet(props.wallet);
const [connectingState, connect] = useWalletConnector(props.wallet);
const [disconnectingState, disconnect] = useWalletDisconnector(props.wallet);

return (
<li>
Expand Down Expand Up @@ -316,7 +316,7 @@ function ErrorFallback(props: FallbackProps) {
type ExampleProps = { chainName: string };

function Example(props: ExampleProps) {
const resetQueryError = useResetQueryError();
const resetQueryError = useQueryErrorResetter();

useMutationEffect((event) => {
if (event.value === PENDING) {
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/contexts/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useReconnectWallets } from "../hooks/use-reconnect-wallets.js";
import { useWalletsReconnector } from "../hooks/use-wallets-reconnector.js";
import { chainConfigsAtom } from "../stores/config.js";
import { aggregatorsAtom, directWalletsAtom } from "../stores/wallets.js";
import { MutationEventSubjectContext } from "./mutation.js";
Expand Down Expand Up @@ -62,7 +62,7 @@ function ReDotHydrator(props: ReDotProviderProps) {
}

function WalletsReconnector() {
const [_, reconnect] = useReconnectWallets();
const [_, reconnect] = useWalletsReconnector();

useEffect(() => {
reconnect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import { resetQueryError } from "../utils/jotai.js";
*
* @returns Function to reset caught query error
*/
export function useResetQueryError() {
export function useQueryErrorResetter() {
return resetQueryError;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useCallback } from "react";
* @param wallets - Wallets to connect to, will connect to all available wallets if none is specified
* @returns The wallet connection state & connect function
*/
export function useConnectWallet(wallets?: Wallet | Wallet[]) {
export function useWalletConnector(wallets?: Wallet | Wallet[]) {
const hookWallets = wallets;

const [success, setSuccess] = useAsyncState<true>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useCallback } from "react";
* @param wallets - Wallets to disconnect from, will disconnect from all connected wallets if none is specified
* @returns The wallet disconnection state & disconnect function
*/
export function useDisconnectWallet(wallets?: Wallet | Wallet[]) {
export function useWalletDisconnector(wallets?: Wallet | Wallet[]) {
const hookWallets = wallets;

const [success, setSuccess] = useAsyncState<true>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useCallback, useState } from "react";
*
* @returns The reconnection state and reconnect function
*/
export function useReconnectWallets() {
export function useWalletsReconnector() {
const wallets = useWallets();

const [state, setState] = useState<AsyncValue<true, ReDotError>>(IDLE);
Expand Down
8 changes: 4 additions & 4 deletions packages/react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ export { useBlock } from "./hooks/use-block.js";
export { useChainId } from "./hooks/use-chain-id.js";
export { useChainSpecData } from "./hooks/use-chain-spec-data.js";
export { useClient } from "./hooks/use-client.js";
export { useConnectWallet } from "./hooks/use-connect-wallet.js";
export { useDisconnectWallet } from "./hooks/use-disconnect-wallet.js";
export { useMutationEffect } from "./hooks/use-mutation-effect.js";
export { useMutation } from "./hooks/use-mutation.js";
export {
useNativeTokenAmountFromNumber,
useNativeTokenAmountFromPlanck,
} from "./hooks/use-native-token-amount.js";
export { useQueryErrorResetter } from "./hooks/use-query-error-resetter.js";
export {
useLazyLoadQuery,
useLazyLoadQueryWithRefresh,
useQueryRefresher,
} from "./hooks/use-query.js";
export { useReconnectWallets } from "./hooks/use-reconnect-wallets.js";
export { useResetQueryError } from "./hooks/use-reset-query-error.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 { useConnectedWallets, useWallets } from "./hooks/use-wallets.js";

0 comments on commit 94505d6

Please sign in to comment.