@account-kit/privy-integration 4.73.1-alpha.2 → 4.73.1-alpha.4
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/dist/esm/Provider.native.d.ts +6 -0
- package/dist/esm/Provider.native.js +13 -0
- package/dist/esm/Provider.native.js.map +1 -0
- package/dist/esm/adapters/web.native.d.ts +5 -0
- package/dist/esm/adapters/web.native.js +6 -0
- package/dist/esm/adapters/web.native.js.map +1 -0
- package/dist/esm/hooks/useAlchemySendTransaction.js +1 -1
- package/dist/esm/hooks/useAlchemySendTransaction.js.map +1 -1
- package/dist/esm/providers/WebProvider.native.d.ts +5 -0
- package/dist/esm/providers/WebProvider.native.js +9 -0
- package/dist/esm/providers/WebProvider.native.js.map +1 -0
- 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.native.d.ts +7 -0
- package/dist/types/Provider.native.d.ts.map +1 -0
- package/dist/types/adapters/web.native.d.ts +6 -0
- package/dist/types/adapters/web.native.d.ts.map +1 -0
- package/dist/types/providers/WebProvider.native.d.ts +6 -0
- package/dist/types/providers/WebProvider.native.d.ts.map +1 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +13 -5
- package/src/Provider.native.tsx +18 -0
- package/src/Provider.tsx +6 -0
- package/src/adapters/web.native.ts +6 -0
- package/src/context/AlchemyContext.tsx +162 -0
- package/src/hooks/useAlchemySendTransaction.ts +1 -1
- package/src/providers/ReactNativeProvider.tsx +45 -0
- package/src/providers/WebProvider.native.tsx +11 -0
- package/src/providers/WebProvider.tsx +45 -0
- package/src/version.ts +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Native stub for web Provider
|
|
3
|
+
* This file prevents Metro from importing web-specific code
|
|
4
|
+
*/
|
|
5
|
+
export function AlchemyProvider() {
|
|
6
|
+
throw new Error("Web Provider is not available in React Native. " +
|
|
7
|
+
'Import from "@account-kit/privy-integration/react-native" instead.');
|
|
8
|
+
}
|
|
9
|
+
export function useAlchemyConfig() {
|
|
10
|
+
throw new Error("useAlchemyConfig from web Provider is not available in React Native. " +
|
|
11
|
+
'Import from "@account-kit/privy-integration/react-native" instead.');
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=Provider.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Provider.native.js","sourceRoot":"","sources":["../../src/Provider.native.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,UAAU,eAAe;IAC7B,MAAM,IAAI,KAAK,CACb,iDAAiD;QAC/C,oEAAoE,CACvE,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,MAAM,IAAI,KAAK,CACb,uEAAuE;QACrE,oEAAoE,CACvE,CAAC;AACJ,CAAC","sourcesContent":["/**\n * React Native stub for web Provider\n * This file prevents Metro from importing web-specific code\n */\n\nexport function AlchemyProvider() {\n throw new Error(\n \"Web Provider is not available in React Native. \" +\n 'Import from \"@account-kit/privy-integration/react-native\" instead.',\n );\n}\n\nexport function useAlchemyConfig() {\n throw new Error(\n \"useAlchemyConfig from web Provider is not available in React Native. \" +\n 'Import from \"@account-kit/privy-integration/react-native\" instead.',\n );\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.native.js","sourceRoot":"","sources":["../../../src/adapters/web.native.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC","sourcesContent":["/**\n * React Native stub for web adapter\n * This file prevents Metro from importing @privy-io/react-auth\n */\n\nexport const webAdapter = null;\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useCallback, useState } from "react";
|
|
2
2
|
import { isHex } from "viem";
|
|
3
3
|
import { useAlchemyClient } from "./useAlchemyClient.js";
|
|
4
|
-
import { useAlchemyConfig } from "../
|
|
4
|
+
import { useAlchemyConfig } from "../context/AlchemyContext.js";
|
|
5
5
|
import { useEmbeddedWallet } from "./internal/useEmbeddedWallet.js";
|
|
6
6
|
/**
|
|
7
7
|
* Normalize value to hex format
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAlchemySendTransaction.js","sourceRoot":"","sources":["../../../src/hooks/useAlchemySendTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAA0B,KAAK,EAAE,MAAM,MAAM,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"useAlchemySendTransaction.js","sourceRoot":"","sources":["../../../src/hooks/useAlchemySendTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAA0B,KAAK,EAAE,MAAM,MAAM,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAQpE;;;;;;GAMG;AACH,SAAS,cAAc,CAAC,KAA+B;IACrD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;IACnC,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;IAC3C,CAAC;IACD,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QACjB,OAAO,KAAK,CAAC;IACf,CAA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Q,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,eAAe,CAAC;YACxD,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;YAC3D,CAAC;YAED,MAAM,QAAQ,GAA0B,EAAE,OAAO,EAAE,CAAC;YACpD,OAAO,CAAC,QAAQ,CAAC,CAAC;YAClB,OAAO,QAAQ,CAAC;QAClB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,QAAQ,GACZ,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;YAC/D,QAAQ,CAAC,QAAQ,CAAC,CAAC;YACnB,MAAM,QAAQ,CAAC;QACjB,CAAC;gBAAS,CAAC;YACT,YAAY,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;IACH,CAAC,EACD,CAAC,SAAS,EAAE,iBAAiB,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAC3E,CAAC;IAEF,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE;QAC7B,QAAQ,CAAC,IAAI,CAAC,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,CAAC;QACd,YAAY,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACL,eAAe;QACf,SAAS;QACT,KAAK;QACL,IAAI;QACJ,KAAK;KACN,CAAC;AACJ,CAAC","sourcesContent":["import { useCallback, useState } from \"react\";\nimport { type Address, type Hex, isHex } from \"viem\";\nimport { useAlchemyClient } from \"./useAlchemyClient.js\";\nimport { useAlchemyConfig } from \"../context/AlchemyContext.js\";\nimport { useEmbeddedWallet } from \"./internal/useEmbeddedWallet.js\";\nimport type {\n UnsignedTransactionRequest,\n SendTransactionOptions,\n SendTransactionResult,\n UseSendTransactionResult,\n} from \"../types\";\n\n/**\n * Normalize value to hex format\n * Accepts bigint, number, decimal string, or hex string\n *\n * @param {string | number | bigint} value - Value to normalize\n * @returns {Hex} Hex string representation of the value\n */\nfunction normalizeValue(value: string | number | bigint): Hex {\n if (typeof value === \"bigint\") {\n return `0x${value.toString(16)}`;\n }\n if (typeof value === \"number\") {\n return `0x${BigInt(value).toString(16)}`;\n }\n if (isHex(value)) {\n return value;\n }\n // Assume decimal string\n return `0x${BigInt(value).toString(16)}`;\n}\n\n/**\n * Hook to send transactions with optional gas sponsorship via Alchemy\n * Supports both single transactions and batch transactions\n * Drop-in alternative to Privy's useSendTransaction hook\n *\n * @returns {UseSendTransactionResult} Hook result with sendTransaction function and state\n *\n * @example Single transaction\n * ```tsx\n * const { sendTransaction, isLoading, error, data } = useAlchemySendTransaction();\n *\n * const handleSend = async () => {\n * try {\n * const result = await sendTransaction({\n * to: '0x...',\n * data: '0x...',\n * value: '1000000000000000000', // 1 ETH\n * });\n * console.log('Transaction hash:', result.txnHash);\n * } catch (err) {\n * console.error('Transaction failed:', err);\n * }\n * };\n * ```\n *\n * @example Batch transactions\n * ```tsx\n * const { sendTransaction } = useAlchemySendTransaction();\n *\n * const result = await sendTransaction([\n * { to: '0x...', data: '0x...', value: '1000000000000000000' },\n * { to: '0x...', data: '0x...' },\n * ]);\n * ```\n */\nexport function useAlchemySendTransaction(): UseSendTransactionResult {\n const { getClient } = useAlchemyClient();\n const config = useAlchemyConfig();\n const getEmbeddedWallet = useEmbeddedWallet();\n\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n const [data, setData] = useState<SendTransactionResult | null>(null);\n\n const sendTransaction = useCallback(\n async (\n input: UnsignedTransactionRequest | UnsignedTransactionRequest[],\n options?: SendTransactionOptions,\n ): Promise<SendTransactionResult> => {\n setIsLoading(true);\n setError(null);\n\n try {\n const client = await getClient();\n const embeddedWallet = getEmbeddedWallet();\n\n // Determine if transaction should be sponsored\n const hasPolicyId = !!config.policyId;\n const enableSponsorship = !config.disableSponsorship;\n const shouldSponsor =\n options?.disableSponsorship !== undefined\n ? !options.disableSponsorship\n : hasPolicyId && enableSponsorship;\n\n // Format the transaction call(s)\n const inputs = Array.isArray(input) ? input : [input];\n const formattedCalls = inputs.map((txn) => ({\n to: txn.to,\n data: txn.data,\n value: txn.value ? normalizeValue(txn.value) : undefined,\n }));\n\n // Build capabilities based on sponsorship\n const policyId = Array.isArray(config.policyId)\n ? config.policyId[0]\n : config.policyId;\n\n const capabilities: {\n eip7702Auth: true;\n paymasterService?: { policyId: string };\n } = { eip7702Auth: true };\n\n if (shouldSponsor && policyId) {\n capabilities.paymasterService = { policyId };\n }\n\n // Send the transaction(s)\n const result = await client.sendCalls({\n from: embeddedWallet.address as Address,\n calls: formattedCalls,\n capabilities,\n });\n\n if (!result.preparedCallIds || result.preparedCallIds.length === 0) {\n throw new Error(\n \"No prepared call IDs returned from transaction submission\",\n );\n }\n\n // Wait for the transaction to be confirmed\n const txStatus = await client.waitForCallsStatus({\n id: result.preparedCallIds[0],\n timeout: 60_000,\n });\n\n const txnHash = txStatus.receipts?.[0]?.transactionHash;\n if (!txnHash) {\n throw new Error(\"Transaction hash not found in receipt\");\n }\n\n const txResult: SendTransactionResult = { txnHash };\n setData(txResult);\n return txResult;\n } catch (err) {\n const errorObj =\n err instanceof Error ? err : new Error(\"Transaction failed\");\n setError(errorObj);\n throw errorObj;\n } finally {\n setIsLoading(false);\n }\n },\n [getClient, getEmbeddedWallet, config.policyId, config.disableSponsorship],\n );\n\n const reset = useCallback(() => {\n setError(null);\n setData(null);\n setIsLoading(false);\n }, []);\n\n return {\n sendTransaction,\n isLoading,\n error,\n data,\n reset,\n };\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Native stub for WebProvider
|
|
3
|
+
* This file prevents Metro from importing web-specific code
|
|
4
|
+
*/
|
|
5
|
+
export function AlchemyProvider() {
|
|
6
|
+
throw new Error("WebProvider is not available in React Native. " +
|
|
7
|
+
'Import from "@account-kit/privy-integration/react-native" instead.');
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=WebProvider.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebProvider.native.js","sourceRoot":"","sources":["../../../src/providers/WebProvider.native.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,UAAU,eAAe;IAC7B,MAAM,IAAI,KAAK,CACb,gDAAgD;QAC9C,oEAAoE,CACvE,CAAC;AACJ,CAAC","sourcesContent":["/**\n * React Native stub for WebProvider\n * This file prevents Metro from importing web-specific code\n */\n\nexport function AlchemyProvider() {\n throw new Error(\n \"WebProvider is not available in React Native. \" +\n 'Import from \"@account-kit/privy-integration/react-native\" instead.',\n );\n}\n"]}
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "4.73.1-alpha.
|
|
1
|
+
export declare const VERSION = "4.73.1-alpha.4";
|
package/dist/esm/version.js
CHANGED
package/dist/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yBAAyB;AACzB,MAAM,CAAC,MAAM,OAAO,GAAG,gBAAgB,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"4.73.1-alpha.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yBAAyB;AACzB,MAAM,CAAC,MAAM,OAAO,GAAG,gBAAgB,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"4.73.1-alpha.4\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Provider.native.d.ts","sourceRoot":"","sources":["../../src/Provider.native.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,wBAAgB,eAAe,SAK9B;AAED,wBAAgB,gBAAgB,SAK/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.native.d.ts","sourceRoot":"","sources":["../../../src/adapters/web.native.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAO,MAAM,UAAU,MAAO,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebProvider.native.d.ts","sourceRoot":"","sources":["../../../src/providers/WebProvider.native.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,wBAAgB,eAAe,SAK9B"}
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "4.73.1-alpha.
|
|
1
|
+
export declare const VERSION = "4.73.1-alpha.4";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@account-kit/privy-integration",
|
|
3
|
-
"version": "4.73.1-alpha.
|
|
3
|
+
"version": "4.73.1-alpha.4",
|
|
4
4
|
"description": "Use Alchemy gas sponsorship, swaps and more with Privy",
|
|
5
5
|
"author": "Alchemy",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,11 +10,19 @@
|
|
|
10
10
|
"module": "./dist/esm/index.js",
|
|
11
11
|
"types": "./dist/types/index.d.ts",
|
|
12
12
|
"typings": "./dist/types/index.d.ts",
|
|
13
|
-
"react-native": "./dist/esm/react-native.js",
|
|
14
13
|
"sideEffects": false,
|
|
14
|
+
"react-native": {
|
|
15
|
+
"main": "./dist/esm/react-native.js",
|
|
16
|
+
"./dist/esm/adapters/web.js": "./dist/esm/adapters/web.native.js",
|
|
17
|
+
"./dist/esm/providers/WebProvider.js": "./dist/esm/providers/WebProvider.native.js",
|
|
18
|
+
"./dist/esm/Provider.js": "./dist/esm/Provider.native.js",
|
|
19
|
+
"@privy-io/react-auth": false,
|
|
20
|
+
"@privy-io/react-auth/solana": false
|
|
21
|
+
},
|
|
15
22
|
"files": [
|
|
16
23
|
"dist",
|
|
17
24
|
"src/**/*.ts",
|
|
25
|
+
"src/**/*.tsx",
|
|
18
26
|
"!dist/**/*.tsbuildinfo",
|
|
19
27
|
"!vitest.config.ts",
|
|
20
28
|
"!.env",
|
|
@@ -56,8 +64,8 @@
|
|
|
56
64
|
"typescript-template": "*"
|
|
57
65
|
},
|
|
58
66
|
"dependencies": {
|
|
59
|
-
"@account-kit/infra": "^4.73.1-alpha.
|
|
60
|
-
"@account-kit/wallet-client": "^4.73.1-alpha.
|
|
67
|
+
"@account-kit/infra": "^4.73.1-alpha.3",
|
|
68
|
+
"@account-kit/wallet-client": "^4.73.1-alpha.3"
|
|
61
69
|
},
|
|
62
70
|
"peerDependencies": {
|
|
63
71
|
"@privy-io/expo": "^0.58.0",
|
|
@@ -87,5 +95,5 @@
|
|
|
87
95
|
"url": "https://github.com/alchemyplatform/aa-sdk/issues"
|
|
88
96
|
},
|
|
89
97
|
"homepage": "https://github.com/alchemyplatform/aa-sdk#readme",
|
|
90
|
-
"gitHead": "
|
|
98
|
+
"gitHead": "0b4e411c20856ba68c93c4c71877db2fafd87780"
|
|
91
99
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Native stub for web Provider
|
|
3
|
+
* This file prevents Metro from importing web-specific code
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export function AlchemyProvider() {
|
|
7
|
+
throw new Error(
|
|
8
|
+
"Web Provider is not available in React Native. " +
|
|
9
|
+
'Import from "@account-kit/privy-integration/react-native" instead.',
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function useAlchemyConfig() {
|
|
14
|
+
throw new Error(
|
|
15
|
+
"useAlchemyConfig from web Provider is not available in React Native. " +
|
|
16
|
+
'Import from "@account-kit/privy-integration/react-native" instead.',
|
|
17
|
+
);
|
|
18
|
+
}
|
package/src/Provider.tsx
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
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,7 +1,7 @@
|
|
|
1
1
|
import { useCallback, useState } from "react";
|
|
2
2
|
import { type Address, type Hex, isHex } from "viem";
|
|
3
3
|
import { useAlchemyClient } from "./useAlchemyClient.js";
|
|
4
|
-
import { useAlchemyConfig } from "../
|
|
4
|
+
import { useAlchemyConfig } from "../context/AlchemyContext.js";
|
|
5
5
|
import { useEmbeddedWallet } from "./internal/useEmbeddedWallet.js";
|
|
6
6
|
import type {
|
|
7
7
|
UnsignedTransactionRequest,
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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/version.ts
CHANGED