Skip to content

Commit

Permalink
Replace hook library to be compatible with ssr (#99)
Browse files Browse the repository at this point in the history
* chore: replace hook library to be compatible with ssr

* chore: add use client directive to hooks
  • Loading branch information
slavastartsev authored Oct 8, 2024
1 parent bad821f commit 30f2eb3
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 41 deletions.
6 changes: 3 additions & 3 deletions packages/sats-wagmi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
"postpack": "clean-package restore"
},
"peerDependencies": {
"@tanstack/react-query": ">=5.0.0",
"react": ">=18",
"react-dom": ">=18",
"@tanstack/react-query": ">=5.0.0"
"react-dom": ">=18"
},
"devDependencies": {
"@types/async-retry": "^1.4.8",
Expand All @@ -59,7 +59,7 @@
"bs58check": "^2.1.2",
"clean-package": "^2.2.0",
"sats-connect": "^1.1.2",
"@uidotdev/usehooks": "^2.4.1"
"usehooks-ts": "^3.1.0"
},
"clean-package": "../../clean-package.config.json"
}
2 changes: 2 additions & 0 deletions packages/sats-wagmi/src/hooks/useAccount.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { useQuery } from '@tanstack/react-query';
import { getAddressInfo } from 'bitcoin-address-validation';
import { useEffect } from 'react';
Expand Down
2 changes: 2 additions & 0 deletions packages/sats-wagmi/src/hooks/useBalance.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { UseQueryOptions, useQuery } from '@tanstack/react-query';
import { EsploraClient } from '@gobob/bob-sdk';

Expand Down
2 changes: 2 additions & 0 deletions packages/sats-wagmi/src/hooks/useConnect.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { useMutation } from '@tanstack/react-query';

import { SatsConnector } from '../connectors/base';
Expand Down
2 changes: 2 additions & 0 deletions packages/sats-wagmi/src/hooks/useDisconnect.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { useMutation } from '@tanstack/react-query';

import { useSatsWagmi } from '../provider';
Expand Down
2 changes: 2 additions & 0 deletions packages/sats-wagmi/src/hooks/useFeeEstimate.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { estimateTxFee } from '@gobob/bob-sdk';
import { UndefinedInitialDataOptions, useQuery } from '@tanstack/react-query';

Expand Down
2 changes: 2 additions & 0 deletions packages/sats-wagmi/src/hooks/useFeeRate.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { EsploraClient } from '@gobob/bob-sdk';
import { UndefinedInitialDataOptions, useQuery } from '@tanstack/react-query';

Expand Down
2 changes: 2 additions & 0 deletions packages/sats-wagmi/src/hooks/useSendGatewayTransaction.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { Optional, useMutation, UseMutationOptions } from '@tanstack/react-query';
import { GatewayQuoteParams, GatewaySDK } from '@gobob/bob-sdk';

Expand Down
2 changes: 2 additions & 0 deletions packages/sats-wagmi/src/hooks/useSendTransaction.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { useMutation, UseMutationOptions } from '@tanstack/react-query';

import { useSatsWagmi } from '../provider';
Expand Down
2 changes: 2 additions & 0 deletions packages/sats-wagmi/src/hooks/useSignMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { useMutation, UseMutationOptions } from '@tanstack/react-query';

import { useSatsWagmi } from '../provider';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { UseQueryOptions, useQuery } from '@tanstack/react-query';
import { EsploraClient } from '@gobob/bob-sdk';

Expand Down
10 changes: 8 additions & 2 deletions packages/sats-wagmi/src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { Network as BitcoinNetwork } from 'bitcoin-address-validation';
import { FC, ReactNode, createContext, useCallback, useContext, useEffect, useState } from 'react';
import { useLocalStorage } from '@uidotdev/usehooks';
import { useLocalStorage } from 'usehooks-ts';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';

import { LeatherConnector, MMSnapConnector, UnisatConnector, XverseConnector } from './connectors';
Expand Down Expand Up @@ -44,7 +44,13 @@ const SatsWagmiConfig: FC<SatsWagmiConfigProps> = ({ children, queryClient, netw
const [connectors, setConnectors] = useState<SatsConnector[]>([]);
const [connector, setCurrentConnector] = useState<SatsConnector>();

const [storedConnector, setStoredConnector] = useLocalStorage<string | undefined>(LocalStorageKeys.CONNECTOR);
const [storedConnector, setStoredConnector] = useLocalStorage<string | undefined>(
LocalStorageKeys.CONNECTOR,
undefined,
{
initializeWithValue: typeof window !== 'undefined'
}
);

useEffect(() => {
const init = () => {
Expand Down
70 changes: 34 additions & 36 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 30f2eb3

Please sign in to comment.