@account-kit/privy-integration 4.73.1-alpha.9 → 4.75.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -21
- package/dist/esm/Provider.d.ts +71 -4
- package/dist/esm/Provider.js +109 -4
- package/dist/esm/Provider.js.map +1 -1
- package/dist/esm/hooks/internal/useEmbeddedWallet.d.ts +4 -3
- package/dist/esm/hooks/internal/useEmbeddedWallet.js +13 -5
- package/dist/esm/hooks/internal/useEmbeddedWallet.js.map +1 -1
- package/dist/esm/hooks/useAlchemyClient.d.ts +10 -5
- package/dist/esm/hooks/useAlchemyClient.js +46 -25
- package/dist/esm/hooks/useAlchemyClient.js.map +1 -1
- package/dist/esm/hooks/useAlchemyPrepareSwap.js +3 -6
- package/dist/esm/hooks/useAlchemyPrepareSwap.js.map +1 -1
- package/dist/esm/hooks/useAlchemySendTransaction.js +12 -10
- package/dist/esm/hooks/useAlchemySendTransaction.js.map +1 -1
- package/dist/esm/hooks/useAlchemySolanaTransaction.js +1 -1
- package/dist/esm/hooks/useAlchemySolanaTransaction.js.map +1 -1
- package/dist/esm/hooks/useAlchemySubmitSwap.js +1 -1
- package/dist/esm/hooks/useAlchemySubmitSwap.js.map +1 -1
- package/dist/esm/types.d.ts +6 -0
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/types/Provider.d.ts +71 -4
- package/dist/types/Provider.d.ts.map +1 -1
- package/dist/types/hooks/internal/useEmbeddedWallet.d.ts +4 -3
- package/dist/types/hooks/internal/useEmbeddedWallet.d.ts.map +1 -1
- package/dist/types/hooks/useAlchemyClient.d.ts +10 -5
- package/dist/types/hooks/useAlchemyClient.d.ts.map +1 -1
- package/dist/types/hooks/useAlchemyPrepareSwap.d.ts.map +1 -1
- package/dist/types/hooks/useAlchemySendTransaction.d.ts.map +1 -1
- package/dist/types/types.d.ts +6 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/version.d.ts.map +1 -1
- package/package.json +4 -27
- package/src/hooks/internal/useEmbeddedWallet.ts +20 -5
- package/src/hooks/useAlchemyClient.ts +71 -35
- package/src/hooks/useAlchemyPrepareSwap.ts +3 -6
- package/src/hooks/useAlchemySendTransaction.ts +17 -14
- package/src/hooks/useAlchemySolanaTransaction.ts +1 -1
- package/src/hooks/useAlchemySubmitSwap.ts +1 -1
- package/src/types.ts +7 -0
- package/src/version.ts +1 -1
- package/dist/esm/Provider.native.d.ts +0 -6
- package/dist/esm/Provider.native.js +0 -13
- package/dist/esm/Provider.native.js.map +0 -1
- package/dist/esm/adapters/react-native.d.ts +0 -6
- package/dist/esm/adapters/react-native.js +0 -130
- package/dist/esm/adapters/react-native.js.map +0 -1
- package/dist/esm/adapters/types.d.ts +0 -44
- package/dist/esm/adapters/types.js +0 -2
- package/dist/esm/adapters/types.js.map +0 -1
- package/dist/esm/adapters/web.d.ts +0 -6
- package/dist/esm/adapters/web.js +0 -50
- package/dist/esm/adapters/web.js.map +0 -1
- package/dist/esm/adapters/web.native.d.ts +0 -5
- package/dist/esm/adapters/web.native.js +0 -6
- package/dist/esm/adapters/web.native.js.map +0 -1
- package/dist/esm/context/AlchemyContext.d.ts +0 -62
- package/dist/esm/context/AlchemyContext.js +0 -105
- package/dist/esm/context/AlchemyContext.js.map +0 -1
- package/dist/esm/providers/ReactNativeProvider.d.ts +0 -33
- package/dist/esm/providers/ReactNativeProvider.js +0 -37
- package/dist/esm/providers/ReactNativeProvider.js.map +0 -1
- package/dist/esm/providers/WebProvider.d.ts +0 -33
- package/dist/esm/providers/WebProvider.js +0 -37
- package/dist/esm/providers/WebProvider.js.map +0 -1
- package/dist/esm/providers/WebProvider.native.d.ts +0 -5
- package/dist/esm/providers/WebProvider.native.js +0 -9
- package/dist/esm/providers/WebProvider.native.js.map +0 -1
- package/dist/esm/react-native.d.ts +0 -11
- package/dist/esm/react-native.js +0 -13
- package/dist/esm/react-native.js.map +0 -1
- package/dist/types/Provider.native.d.ts +0 -7
- package/dist/types/Provider.native.d.ts.map +0 -1
- package/dist/types/adapters/react-native.d.ts +0 -7
- package/dist/types/adapters/react-native.d.ts.map +0 -1
- package/dist/types/adapters/types.d.ts +0 -45
- package/dist/types/adapters/types.d.ts.map +0 -1
- package/dist/types/adapters/web.d.ts +0 -7
- package/dist/types/adapters/web.d.ts.map +0 -1
- package/dist/types/adapters/web.native.d.ts +0 -6
- package/dist/types/adapters/web.native.d.ts.map +0 -1
- package/dist/types/context/AlchemyContext.d.ts +0 -63
- package/dist/types/context/AlchemyContext.d.ts.map +0 -1
- package/dist/types/providers/ReactNativeProvider.d.ts +0 -34
- package/dist/types/providers/ReactNativeProvider.d.ts.map +0 -1
- package/dist/types/providers/WebProvider.d.ts +0 -34
- package/dist/types/providers/WebProvider.d.ts.map +0 -1
- package/dist/types/providers/WebProvider.native.d.ts +0 -6
- package/dist/types/providers/WebProvider.native.d.ts.map +0 -1
- package/dist/types/react-native.d.ts +0 -12
- package/dist/types/react-native.d.ts.map +0 -1
- package/src/Provider.native.tsx +0 -18
- package/src/Provider.tsx +0 -6
- package/src/adapters/react-native.ts +0 -190
- package/src/adapters/types.ts +0 -56
- package/src/adapters/web.native.ts +0 -6
- package/src/adapters/web.ts +0 -73
- package/src/context/AlchemyContext.tsx +0 -162
- package/src/providers/ReactNativeProvider.tsx +0 -45
- package/src/providers/WebProvider.native.tsx +0 -11
- package/src/providers/WebProvider.tsx +0 -45
- package/src/react-native.ts +0 -29
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type PropsWithChildren,
|
|
3
|
-
createContext,
|
|
4
|
-
useContext,
|
|
5
|
-
useRef,
|
|
6
|
-
useEffect,
|
|
7
|
-
} from "react";
|
|
8
|
-
import type { SmartWalletClient } from "@account-kit/wallet-client";
|
|
9
|
-
import type { AlchemyProviderConfig } from "../types.js";
|
|
10
|
-
import type { PrivyAdapter } from "../adapters/types.js";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Context for Alchemy configuration
|
|
14
|
-
*/
|
|
15
|
-
const AlchemyConfigContext = createContext<AlchemyProviderConfig | null>(null);
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Context for the platform adapter
|
|
19
|
-
*/
|
|
20
|
-
const AdapterContext = createContext<PrivyAdapter | null>(null);
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Client cache stored in React tree (similar to QueryClient in React Query)
|
|
24
|
-
*
|
|
25
|
-
* @internal
|
|
26
|
-
*/
|
|
27
|
-
interface ClientCache {
|
|
28
|
-
client: SmartWalletClient | null;
|
|
29
|
-
cacheKey: string | null;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const ClientCacheContext = createContext<ClientCache | null>(null);
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Props for AlchemyContextProvider
|
|
36
|
-
*/
|
|
37
|
-
interface AlchemyContextProviderProps extends PropsWithChildren {
|
|
38
|
-
config: AlchemyProviderConfig;
|
|
39
|
-
adapter: PrivyAdapter;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Internal provider component that manages Alchemy context
|
|
44
|
-
* Used by both web and React Native providers
|
|
45
|
-
*
|
|
46
|
-
* @internal
|
|
47
|
-
* @param {AlchemyContextProviderProps} props - Component props
|
|
48
|
-
* @param {React.ReactNode} props.children - React children to wrap with context
|
|
49
|
-
* @param {AlchemyProviderConfig} props.config - Alchemy configuration
|
|
50
|
-
* @param {PrivyAdapter} props.adapter - Platform adapter
|
|
51
|
-
* @returns {JSX.Element} Context provider component
|
|
52
|
-
*/
|
|
53
|
-
export function AlchemyContextProvider({
|
|
54
|
-
children,
|
|
55
|
-
config,
|
|
56
|
-
adapter,
|
|
57
|
-
}: AlchemyContextProviderProps) {
|
|
58
|
-
const { authenticated, user } = adapter.usePrivyAuth();
|
|
59
|
-
|
|
60
|
-
// Store cache in a ref - persists across renders but scoped to this component instance
|
|
61
|
-
// This makes it SSR-safe (each request gets its own cache) and React StrictMode-safe
|
|
62
|
-
const cache = useRef<ClientCache>({
|
|
63
|
-
client: null,
|
|
64
|
-
cacheKey: null,
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
// Track previous state to detect logout and wallet changes
|
|
68
|
-
const prevAuthenticatedRef = useRef(authenticated);
|
|
69
|
-
const prevWalletAddressRef = useRef(user?.wallet?.address);
|
|
70
|
-
|
|
71
|
-
// Automatically reset cache when user logs out or switches wallets
|
|
72
|
-
useEffect(() => {
|
|
73
|
-
const wasAuthenticated = prevAuthenticatedRef.current;
|
|
74
|
-
const prevWalletAddress = prevWalletAddressRef.current;
|
|
75
|
-
const currentWalletAddress = user?.wallet?.address;
|
|
76
|
-
|
|
77
|
-
// Reset cache on logout
|
|
78
|
-
if (wasAuthenticated && !authenticated) {
|
|
79
|
-
cache.current.client = null;
|
|
80
|
-
cache.current.cacheKey = null;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Reset cache on wallet address change (account switching)
|
|
84
|
-
if (
|
|
85
|
-
authenticated &&
|
|
86
|
-
prevWalletAddress &&
|
|
87
|
-
currentWalletAddress &&
|
|
88
|
-
prevWalletAddress !== currentWalletAddress
|
|
89
|
-
) {
|
|
90
|
-
cache.current.client = null;
|
|
91
|
-
cache.current.cacheKey = null;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Update refs for next render
|
|
95
|
-
prevAuthenticatedRef.current = authenticated;
|
|
96
|
-
prevWalletAddressRef.current = currentWalletAddress;
|
|
97
|
-
}, [authenticated, user?.wallet?.address]);
|
|
98
|
-
|
|
99
|
-
return (
|
|
100
|
-
<AlchemyConfigContext.Provider value={config}>
|
|
101
|
-
<AdapterContext.Provider value={adapter}>
|
|
102
|
-
<ClientCacheContext.Provider value={cache.current}>
|
|
103
|
-
{children}
|
|
104
|
-
</ClientCacheContext.Provider>
|
|
105
|
-
</AdapterContext.Provider>
|
|
106
|
-
</AlchemyConfigContext.Provider>
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Hook to access Alchemy provider configuration
|
|
112
|
-
* Must be used within an <AlchemyProvider> component
|
|
113
|
-
*
|
|
114
|
-
* @returns {AlchemyProviderConfig} The current Alchemy configuration
|
|
115
|
-
* @throws {Error} If used outside of AlchemyProvider
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
118
|
-
* ```tsx
|
|
119
|
-
* const config = useAlchemyConfig();
|
|
120
|
-
* console.log('Policy ID:', config.policyId);
|
|
121
|
-
* ```
|
|
122
|
-
*/
|
|
123
|
-
export function useAlchemyConfig(): AlchemyProviderConfig {
|
|
124
|
-
const context = useContext(AlchemyConfigContext);
|
|
125
|
-
if (!context) {
|
|
126
|
-
throw new Error("useAlchemyConfig must be used within <AlchemyProvider />");
|
|
127
|
-
}
|
|
128
|
-
return context;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Hook to access the platform adapter
|
|
133
|
-
* Must be used within an <AlchemyProvider> component
|
|
134
|
-
*
|
|
135
|
-
* @internal
|
|
136
|
-
* @returns {PrivyAdapter} The platform adapter
|
|
137
|
-
*/
|
|
138
|
-
export function useAdapter(): PrivyAdapter {
|
|
139
|
-
const context = useContext(AdapterContext);
|
|
140
|
-
if (!context) {
|
|
141
|
-
throw new Error(
|
|
142
|
-
"useAdapter must be used within <AlchemyProvider />. Make sure AlchemyProvider is nested inside PrivyProvider.",
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
return context;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Hook to access the client cache (internal use only)
|
|
150
|
-
*
|
|
151
|
-
* @internal
|
|
152
|
-
* @returns {ClientCache} The client cache object
|
|
153
|
-
*/
|
|
154
|
-
export function useClientCache(): ClientCache {
|
|
155
|
-
const context = useContext(ClientCacheContext);
|
|
156
|
-
if (!context) {
|
|
157
|
-
throw new Error(
|
|
158
|
-
"useClientCache must be used within <AlchemyProvider />. Make sure AlchemyProvider is nested inside PrivyProvider.",
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
return context;
|
|
162
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { PropsWithChildren } from "react";
|
|
2
|
-
import { AlchemyContextProvider } from "../context/AlchemyContext.js";
|
|
3
|
-
import { reactNativeAdapter } from "../adapters/react-native.js";
|
|
4
|
-
import type { AlchemyProviderConfig } from "../types.js";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Provider component for React Native (Expo) applications
|
|
8
|
-
* Must be nested INSIDE PrivyProvider from @privy-io/expo
|
|
9
|
-
*
|
|
10
|
-
* @param {PropsWithChildren<AlchemyProviderConfig>} props - Component props
|
|
11
|
-
* @param {React.ReactNode} props.children - React children to wrap with Alchemy configuration
|
|
12
|
-
* @param {string} [props.apiKey] - Your Alchemy API key
|
|
13
|
-
* @param {string} [props.jwt] - JWT token for authentication
|
|
14
|
-
* @param {string} [props.rpcUrl] - Custom RPC URL for EVM chains
|
|
15
|
-
* @param {string} [props.solanaRpcUrl] - Custom RPC URL for Solana
|
|
16
|
-
* @param {string | string[]} [props.policyId] - Gas Manager policy ID(s) for EVM chains
|
|
17
|
-
* @param {string | string[]} [props.solanaPolicyId] - Gas Manager policy ID(s) for Solana
|
|
18
|
-
* @param {boolean} [props.disableSponsorship] - Set to true to disable sponsorship by default (default: false)
|
|
19
|
-
* @returns {JSX.Element} Provider component
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```tsx
|
|
23
|
-
* import { PrivyProvider } from '@privy-io/expo';
|
|
24
|
-
* import { AlchemyProvider } from '@account-kit/privy-integration/react-native';
|
|
25
|
-
*
|
|
26
|
-
* <PrivyProvider appId="..." clientId="...">
|
|
27
|
-
* <AlchemyProvider
|
|
28
|
-
* apiKey="your-alchemy-api-key"
|
|
29
|
-
* policyId="your-gas-policy-id"
|
|
30
|
-
* >
|
|
31
|
-
* <YourApp />
|
|
32
|
-
* </AlchemyProvider>
|
|
33
|
-
* </PrivyProvider>
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export function AlchemyProvider({
|
|
37
|
-
children,
|
|
38
|
-
...config
|
|
39
|
-
}: PropsWithChildren<AlchemyProviderConfig>) {
|
|
40
|
-
return (
|
|
41
|
-
<AlchemyContextProvider config={config} adapter={reactNativeAdapter}>
|
|
42
|
-
{children}
|
|
43
|
-
</AlchemyContextProvider>
|
|
44
|
-
);
|
|
45
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* React Native stub for WebProvider
|
|
3
|
-
* This file prevents Metro from importing web-specific code
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export function AlchemyProvider() {
|
|
7
|
-
throw new Error(
|
|
8
|
-
"WebProvider is not available in React Native. " +
|
|
9
|
-
'Import from "@account-kit/privy-integration/react-native" instead.',
|
|
10
|
-
);
|
|
11
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { PropsWithChildren } from "react";
|
|
2
|
-
import { AlchemyContextProvider } from "../context/AlchemyContext.js";
|
|
3
|
-
import { webAdapter } from "../adapters/web.js";
|
|
4
|
-
import type { AlchemyProviderConfig } from "../types.js";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Provider component for React web applications
|
|
8
|
-
* Must be nested INSIDE PrivyProvider from @privy-io/react-auth
|
|
9
|
-
*
|
|
10
|
-
* @param {PropsWithChildren<AlchemyProviderConfig>} props - Component props
|
|
11
|
-
* @param {React.ReactNode} props.children - React children to wrap with Alchemy configuration
|
|
12
|
-
* @param {string} [props.apiKey] - Your Alchemy API key
|
|
13
|
-
* @param {string} [props.jwt] - JWT token for authentication
|
|
14
|
-
* @param {string} [props.rpcUrl] - Custom RPC URL for EVM chains
|
|
15
|
-
* @param {string} [props.solanaRpcUrl] - Custom RPC URL for Solana
|
|
16
|
-
* @param {string | string[]} [props.policyId] - Gas Manager policy ID(s) for EVM chains
|
|
17
|
-
* @param {string | string[]} [props.solanaPolicyId] - Gas Manager policy ID(s) for Solana
|
|
18
|
-
* @param {boolean} [props.disableSponsorship] - Set to true to disable sponsorship by default (default: false)
|
|
19
|
-
* @returns {JSX.Element} Provider component
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```tsx
|
|
23
|
-
* import { PrivyProvider } from '@privy-io/react-auth';
|
|
24
|
-
* import { AlchemyProvider } from '@account-kit/privy-integration';
|
|
25
|
-
*
|
|
26
|
-
* <PrivyProvider appId="...">
|
|
27
|
-
* <AlchemyProvider
|
|
28
|
-
* apiKey="your-alchemy-api-key"
|
|
29
|
-
* policyId="your-gas-policy-id"
|
|
30
|
-
* >
|
|
31
|
-
* <YourApp />
|
|
32
|
-
* </AlchemyProvider>
|
|
33
|
-
* </PrivyProvider>
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export function AlchemyProvider({
|
|
37
|
-
children,
|
|
38
|
-
...config
|
|
39
|
-
}: PropsWithChildren<AlchemyProviderConfig>) {
|
|
40
|
-
return (
|
|
41
|
-
<AlchemyContextProvider config={config} adapter={webAdapter}>
|
|
42
|
-
{children}
|
|
43
|
-
</AlchemyContextProvider>
|
|
44
|
-
);
|
|
45
|
-
}
|
package/src/react-native.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* React Native (Expo) entry point
|
|
3
|
-
* Import from '@account-kit/privy-integration/react-native' in Expo apps
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
// Provider
|
|
7
|
-
export { AlchemyProvider } from "./providers/ReactNativeProvider.js";
|
|
8
|
-
export { useAlchemyConfig } from "./context/AlchemyContext.js";
|
|
9
|
-
|
|
10
|
-
// Hooks
|
|
11
|
-
export { useAlchemyClient } from "./hooks/useAlchemyClient.js";
|
|
12
|
-
export { useAlchemySendTransaction } from "./hooks/useAlchemySendTransaction.js";
|
|
13
|
-
export { useAlchemyPrepareSwap } from "./hooks/useAlchemyPrepareSwap.js";
|
|
14
|
-
export { useAlchemySubmitSwap } from "./hooks/useAlchemySubmitSwap.js";
|
|
15
|
-
|
|
16
|
-
// Types
|
|
17
|
-
export type {
|
|
18
|
-
AlchemyProviderConfig,
|
|
19
|
-
UnsignedTransactionRequest,
|
|
20
|
-
SendTransactionOptions,
|
|
21
|
-
SendTransactionResult,
|
|
22
|
-
UseSendTransactionResult,
|
|
23
|
-
PrepareSwapRequest,
|
|
24
|
-
PrepareSwapResult,
|
|
25
|
-
UsePrepareSwapResult,
|
|
26
|
-
SubmitSwapResult,
|
|
27
|
-
UseSubmitSwapResult,
|
|
28
|
-
SwapQuote,
|
|
29
|
-
} from "./types.js";
|