@naculus/connect-appkit-react 0.1.8 → 0.2.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.
Files changed (94) hide show
  1. package/README.md +4 -4
  2. package/dist/client.cjs +1 -1
  3. package/dist/client.cjs.map +1 -1
  4. package/dist/client.d.cts +144 -0
  5. package/dist/client.d.ts +144 -0
  6. package/dist/client.js +1 -1
  7. package/dist/client.js.map +1 -1
  8. package/dist/index.cjs +2 -1
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +2270 -0
  11. package/dist/index.d.ts +2270 -0
  12. package/dist/index.js +2 -1
  13. package/dist/index.js.map +1 -1
  14. package/package.json +30 -12
  15. package/api-extractor.json +0 -21
  16. package/src/chain-abstraction/index.ts +0 -8
  17. package/src/chain-abstraction/useCompareCosts.ts +0 -137
  18. package/src/chain-abstraction/useExecuteRoute.ts +0 -129
  19. package/src/chain-abstraction/useRouteQuote.ts +0 -168
  20. package/src/client.test.ts +0 -242
  21. package/src/client.ts +0 -265
  22. package/src/hooks/useAccount.test.ts +0 -67
  23. package/src/hooks/useAccount.ts +0 -37
  24. package/src/hooks/useBalance.test.ts +0 -459
  25. package/src/hooks/useBalance.ts +0 -170
  26. package/src/hooks/useChain.test.ts +0 -160
  27. package/src/hooks/useChain.ts +0 -53
  28. package/src/hooks/useConnect.test.ts +0 -112
  29. package/src/hooks/useConnect.ts +0 -29
  30. package/src/hooks/useDisconnect.test.ts +0 -75
  31. package/src/hooks/useDisconnect.ts +0 -32
  32. package/src/hooks/useERC20Allowance.ts +0 -93
  33. package/src/hooks/useERC20Approve.ts +0 -220
  34. package/src/hooks/useERC20Transfer.ts +0 -134
  35. package/src/hooks/useERC20TransferSimulation.ts +0 -147
  36. package/src/hooks/useEmbeddedWallet.test.ts +0 -266
  37. package/src/hooks/useEmbeddedWallet.ts +0 -181
  38. package/src/hooks/useLastTx.test.ts +0 -117
  39. package/src/hooks/useLastTx.ts +0 -73
  40. package/src/hooks/useLookupAddress.ts +0 -131
  41. package/src/hooks/useNotification.ts +0 -308
  42. package/src/hooks/useResolveName.ts +0 -128
  43. package/src/hooks/useSIWxLogin.test.ts +0 -307
  44. package/src/hooks/useSIWxLogin.ts +0 -163
  45. package/src/hooks/useSIWxSession.test.ts +0 -481
  46. package/src/hooks/useSIWxSession.ts +0 -290
  47. package/src/hooks/useSendCalls.ts +0 -103
  48. package/src/hooks/useSendTransaction.test.ts +0 -175
  49. package/src/hooks/useSendTransaction.ts +0 -80
  50. package/src/hooks/useSendUserOperation.ts +0 -313
  51. package/src/hooks/useSession.ts +0 -96
  52. package/src/hooks/useSessionKeys.ts +0 -356
  53. package/src/hooks/useSignInWithEthereum.test.ts +0 -224
  54. package/src/hooks/useSignInWithEthereum.ts +0 -46
  55. package/src/hooks/useSignInWithX.test.ts +0 -210
  56. package/src/hooks/useSignInWithX.ts +0 -141
  57. package/src/hooks/useSignMessage.test.ts +0 -151
  58. package/src/hooks/useSignMessage.ts +0 -65
  59. package/src/hooks/useSimulateTransfer.ts +0 -165
  60. package/src/hooks/useSiwxAuthSession.test.ts +0 -456
  61. package/src/hooks/useSiwxAuthSession.ts +0 -163
  62. package/src/hooks/useSmartAccount.ts +0 -194
  63. package/src/hooks/useSwitchChain.ts +0 -68
  64. package/src/hooks/useTokenBalance.test.ts +0 -337
  65. package/src/hooks/useTokenBalance.ts +0 -210
  66. package/src/hooks/useTransactionSimulation.ts +0 -401
  67. package/src/hooks/useTxHistory.test.ts +0 -108
  68. package/src/hooks/useTxHistory.ts +0 -83
  69. package/src/hooks/useTxMonitor.test.ts +0 -127
  70. package/src/hooks/useTxMonitor.ts +0 -178
  71. package/src/hooks/useUserOpStatus.ts +0 -245
  72. package/src/hooks/useValidateDestination.test.ts +0 -96
  73. package/src/hooks/useValidateDestination.ts +0 -72
  74. package/src/hooks/useViemClient.test.ts +0 -155
  75. package/src/hooks/useViemClient.ts +0 -65
  76. package/src/hooks/useWallet.test.ts +0 -133
  77. package/src/hooks/useWallet.ts +0 -39
  78. package/src/hooks/useWeb3ErrorHandler.ts +0 -102
  79. package/src/index.ts +0 -186
  80. package/src/provider/Web3ConnectProvider.test.tsx +0 -178
  81. package/src/provider/Web3ConnectProvider.tsx +0 -530
  82. package/src/token-list/TokenSelector.tsx +0 -351
  83. package/src/token-list/defaults.ts +0 -39
  84. package/src/token-list/index.ts +0 -14
  85. package/src/token-list/useTokenList.ts +0 -119
  86. package/src/token-list/useTokenSearch.ts +0 -99
  87. package/src/types/index.ts +0 -99
  88. package/src/utils/chains.ts +0 -115
  89. package/src/utils/errorMessages.ts +0 -142
  90. package/src/utils/i18n.ts +0 -90
  91. package/src/wc-generated/components.ts +0 -377
  92. package/test/setup.ts +0 -17
  93. package/test/test-utils.tsx +0 -78
  94. package/tsup.config.ts +0 -18
@@ -1,99 +0,0 @@
1
- import type { UniversalWalletSession, Namespace, SessionNamespace } from "@naculus/connect-core";
2
- import type { Chain } from "viem";
3
-
4
- export type WalletChain = {
5
- id: number;
6
- namespace: Namespace;
7
- name: string;
8
- rpcUrl?: string;
9
- explorerUrl?: string;
10
- token?: string;
11
- };
12
-
13
- export type ConnectionStatus = "disconnected" | "connecting" | "authenticating" | "connected" | "reconnecting";
14
-
15
- /** SIWx (Sign-In With X) CAIP-122 configuration */
16
- export interface SIWxConfig {
17
- /** Called after wallet connects to build the message to sign */
18
- createMessage: (params: { address: string; chainId: string }) => Promise<string>;
19
- /** Called after the user signs the message */
20
- handleSignComplete?: (params: { message: string; signature: string }) => Promise<void>;
21
- /** Whether SIWx is required. If true, wallet disconnects on sign failure (default: true) */
22
- required?: boolean;
23
- }
24
-
25
- export interface Web3ConnectConfig {
26
- projectId: string;
27
- metadata: {
28
- name: string;
29
- description: string;
30
- url: string;
31
- icons: string[];
32
- };
33
- chains?: WalletChain[];
34
- /** SIWx (Sign-In With X) post-connection authentication */
35
- siwx?: SIWxConfig;
36
- storageKey?: string;
37
- /** Enable embedded self-custodial wallet */
38
- enableEmbedded?: boolean;
39
- /** Enable passkeys (WebAuthn) connector */
40
- enablePasskeys?: boolean;
41
- /** Enable Solana injected wallet connector (Phantom, Solflare) */
42
- enableSolana?: boolean;
43
- /** Default Solana chain for injected wallet connections (e.g. "solana:0"). */
44
- solanaDefaultChain?: string;
45
- /** Connection timeout in milliseconds (default: 30000) */
46
- connectionTimeout?: number;
47
- /** Max retry attempts for reconnection (default: 2) */
48
- maxRetries?: number;
49
- /**
50
- * Optional AES-256-GCM encryption key for session persistence.
51
- * When provided, session data is encrypted at rest in localStorage.
52
- * When omitted, existing backward-compatible plaintext storage is used.
53
- */
54
- encryptionKey?: string;
55
- }
56
-
57
- export interface Web3State {
58
- status: ConnectionStatus;
59
- session: UniversalWalletSession | null;
60
- accounts: string[];
61
- chainId: string | null;
62
- error: Error | null;
63
- }
64
-
65
- export interface Web3Actions {
66
- startPairing: () => Promise<string>;
67
- completePairing: () => Promise<UniversalWalletSession>;
68
- connect: () => Promise<void>;
69
- connectInjected: (walletId?: string) => Promise<void>;
70
- /** Connect via embedded self-custodial wallet */
71
- connectEmbedded: () => Promise<void>;
72
- /** Connect via passkeys (WebAuthn) */
73
- connectPasskeys: () => Promise<void>;
74
- disconnect: () => Promise<void>;
75
- reconnect: () => Promise<void>;
76
- switchChain: (chainId: string) => Promise<void>;
77
- /** Clear the current error state without triggering reconnection */
78
- clearError: () => void;
79
- }
80
-
81
- export interface UseWalletReturn extends Web3State, Web3Actions {}
82
-
83
- export type EvmTransaction = {
84
- to: string;
85
- from?: string;
86
- value?: string;
87
- data?: string;
88
- gas?: string;
89
- gasPrice?: string;
90
- nonce?: string;
91
- chainId?: number;
92
- };
93
-
94
- export interface ChainInfo {
95
- namespace: Namespace;
96
- chainId: string;
97
- name: string;
98
- selected: boolean;
99
- }
@@ -1,115 +0,0 @@
1
- import type { WalletChain } from "../types";
2
- import { CHAINS, getRpcUrl, DEFAULT_RPC_URLS } from "@naculus/connect-core";
3
-
4
- // ─── Static Overrides ──────────────────────────────────────────────
5
- // Chains that exist in the old default list but are NOT in chain-registry.
6
- // These are deprecated testnets; keep for backward compatibility.
7
-
8
- const STATIC_TESTNETS: WalletChain[] = [
9
- {
10
- id: 5,
11
- namespace: "eip155",
12
- name: "Goerli",
13
- rpcUrl: "https://goerli.blockpi.network/v1/rpc/public",
14
- explorerUrl: "https://goerli.etherscan.io",
15
- token: "ETH",
16
- },
17
- {
18
- id: 80001,
19
- namespace: "eip155",
20
- name: "Mumbai",
21
- rpcUrl: "https://rpc-mumbai.maticvigil.com",
22
- explorerUrl: "https://mumbai.polygonscan.com",
23
- token: "MATIC",
24
- },
25
- {
26
- id: 421613,
27
- namespace: "eip155",
28
- name: "Arbitrum Goerli",
29
- rpcUrl: "https://goerli-rollup.arbitrum.io/rpc",
30
- explorerUrl: "https://goerli.arbiscan.io",
31
- token: "ETH",
32
- },
33
- {
34
- id: 420,
35
- namespace: "eip155",
36
- name: "Optimism Goerli",
37
- rpcUrl: "https://goerli.optimism.io",
38
- explorerUrl: "https://goerli-optimism.etherscan.io",
39
- token: "ETH",
40
- },
41
- ];
42
-
43
- // ─── Build from Registry ───────────────────────────────────────────
44
- // Derive WalletChain entries from the single-source-of-truth chain-registry
45
- // and the RPC URL defaults from rpc.ts.
46
-
47
- function toWalletChain(chainId: number): WalletChain | null {
48
- const info = CHAINS[chainId];
49
- if (!info) return null;
50
-
51
- // Only include chains with an explorer URL (meaningful for UI display)
52
- if (!info.explorerUrl) return null;
53
-
54
- const caip2Id = info.caip2Id;
55
-
56
- return {
57
- id: chainId,
58
- namespace: "eip155",
59
- name: info.name,
60
- rpcUrl: getRpcUrl(caip2Id, DEFAULT_RPC_URLS[caip2Id] ?? ""),
61
- explorerUrl: info.explorerUrl,
62
- token: info.nativeCurrency.symbol,
63
- };
64
- }
65
-
66
- function buildDefaultChains(): WalletChain[] {
67
- if (!CHAINS) return [];
68
-
69
- const registryChains: WalletChain[] = [];
70
-
71
- // Order by chain ID for deterministic output
72
- const chainIds = Object.keys(CHAINS)
73
- .map(Number)
74
- .sort((a, b) => a - b);
75
-
76
- for (const id of chainIds) {
77
- const chain = toWalletChain(id);
78
- if (chain) {
79
- registryChains.push(chain);
80
- }
81
- }
82
-
83
- // Append static testnets that aren't in the registry
84
- for (const testnet of STATIC_TESTNETS) {
85
- if (!CHAINS[testnet.id]) {
86
- registryChains.push(testnet);
87
- }
88
- }
89
-
90
- return registryChains;
91
- }
92
-
93
- export const DEFAULT_EVM_CHAINS: WalletChain[] = buildDefaultChains();
94
-
95
- // ─── Helpers ───────────────────────────────────────────────────────
96
-
97
- export function getChainById(chains: WalletChain[], chainId: string): WalletChain | undefined {
98
- return chains.find((chain) => {
99
- const chainNamespace = chainId.startsWith("eip155:")
100
- ? "eip155"
101
- : null;
102
-
103
- if (!chainNamespace) return false;
104
-
105
- const chainNum = chainId.includes(":")
106
- ? parseInt(chainId.split(":")[1], 10)
107
- : parseInt(chainId, 10);
108
-
109
- return chain.namespace === chainNamespace && chain.id === chainNum;
110
- });
111
- }
112
-
113
- export function getDefaultChains(): WalletChain[] {
114
- return [...DEFAULT_EVM_CHAINS];
115
- }
@@ -1,142 +0,0 @@
1
- /**
2
- * User-friendly error messages for WalletError codes and common errors.
3
- * Maps internal error codes to human-readable messages that can be shown in toasts/UI.
4
- */
5
-
6
- import type { WalletErrorCode } from "@naculus/connect-core";
7
-
8
- /**
9
- * User-friendly title for each WalletError code.
10
- */
11
- export const WALLET_ERROR_TITLES: Record<string, string> = {
12
- wallet_unavailable: "Wallet Not Detected",
13
- user_rejected: "Connection Rejected",
14
- deeplink_timeout: "Wallet Connection Timed Out",
15
- session_expired: "Session Expired",
16
- intent_expired: "Connection Request Expired",
17
- namespace_mismatch: "Network Mismatch",
18
- chain_unsupported: "Unsupported Network",
19
- method_not_allowed: "Action Not Allowed",
20
- signature_rejected: "Signature Rejected",
21
- tx_failed: "Transaction Failed",
22
- };
23
-
24
- /**
25
- * User-friendly description for each WalletError code.
26
- */
27
- export const WALLET_ERROR_DESCRIPTIONS: Record<string, string> = {
28
- wallet_unavailable:
29
- "No wallet found. Please install a compatible wallet (e.g., MetaMask, WalletConnect) and try again.",
30
- user_rejected: "The connection request was declined in your wallet. You can try again whenever you're ready.",
31
- deeplink_timeout:
32
- "The wallet didn't respond in time. This can happen if the wallet app isn't installed or takes too long to open.",
33
- session_expired:
34
- "Your wallet session has expired. Please reconnect to continue.",
35
- intent_expired:
36
- "The connection request expired. Please try connecting again.",
37
- namespace_mismatch:
38
- "This wallet doesn't support the required network. Try using a different wallet or network.",
39
- chain_unsupported:
40
- "This network isn't supported. Please switch to a supported network in your wallet.",
41
- method_not_allowed:
42
- "This action isn't supported by your current wallet or network.",
43
- signature_rejected: "The signature request was declined in your wallet.",
44
- tx_failed:
45
- "The transaction couldn't be completed. This could be due to insufficient funds, network congestion, or a contract error.",
46
- };
47
-
48
- /**
49
- * Default title for unknown errors.
50
- */
51
- export const UNKNOWN_ERROR_TITLE = "Something went wrong";
52
-
53
- /**
54
- * Default description for unknown errors.
55
- */
56
- export const UNKNOWN_ERROR_DESCRIPTION =
57
- "An unexpected error occurred. Please try again. If the problem persists, check your connection and wallet configuration.";
58
-
59
- /**
60
- * Get a user-friendly error message object from any error.
61
- */
62
- export function getUserFriendlyError(
63
- error: unknown
64
- ): { title: string; description: string; code?: string } {
65
- if (!error) {
66
- return { title: UNKNOWN_ERROR_TITLE, description: UNKNOWN_ERROR_DESCRIPTION };
67
- }
68
-
69
- // Check for WalletError with code
70
- const maybeWalletError = error as { name?: string; code?: string; message?: string };
71
- if (maybeWalletError.name === "WalletError" && maybeWalletError.code) {
72
- const code = maybeWalletError.code;
73
- const title = WALLET_ERROR_TITLES[code] ?? UNKNOWN_ERROR_TITLE;
74
- const description =
75
- WALLET_ERROR_DESCRIPTIONS[code] ?? maybeWalletError.message ?? UNKNOWN_ERROR_DESCRIPTION;
76
- return { title, description, code };
77
- }
78
-
79
- // Check for standard Error
80
- if (error instanceof Error) {
81
- const message = error.message;
82
- // Map common error patterns
83
- if (/user rejected/i.test(message) || /rejected/.test(message)) {
84
- return {
85
- title: "Request Rejected",
86
- description: "The request was declined.",
87
- code: "user_rejected",
88
- };
89
- }
90
- if (/timeout/i.test(message) || /timed? ?out/i.test(message)) {
91
- return {
92
- title: "Request Timed Out",
93
- description: "The request took too long. Please try again.",
94
- code: "deeplink_timeout",
95
- };
96
- }
97
- if (/network/i.test(message) || /chain/i.test(message)) {
98
- return {
99
- title: "Network Error",
100
- description: message,
101
- code: "chain_unsupported",
102
- };
103
- }
104
- if (/insufficient funds/i.test(message)) {
105
- return {
106
- title: "Insufficient Funds",
107
- description: "You don't have enough funds to complete this transaction.",
108
- code: "tx_failed",
109
- };
110
- }
111
-
112
- return {
113
- title: UNKNOWN_ERROR_TITLE,
114
- description: message || UNKNOWN_ERROR_DESCRIPTION,
115
- };
116
- }
117
-
118
- // String error
119
- if (typeof error === "string") {
120
- return {
121
- title: UNKNOWN_ERROR_TITLE,
122
- description: error || UNKNOWN_ERROR_DESCRIPTION,
123
- };
124
- }
125
-
126
- return { title: UNKNOWN_ERROR_TITLE, description: UNKNOWN_ERROR_DESCRIPTION };
127
- }
128
-
129
- /**
130
- * Check if an error is retryable (transient).
131
- */
132
- export function isRetryableError(error: unknown): boolean {
133
- const maybe = error as { name?: string; code?: string; message?: string };
134
- if (maybe.name !== "WalletError" || !maybe.code) return false;
135
- const retryableCodes: WalletErrorCode[] = [
136
- "deeplink_timeout",
137
- "session_expired",
138
- "intent_expired",
139
- "tx_failed",
140
- ];
141
- return retryableCodes.includes(maybe.code as WalletErrorCode);
142
- }
package/src/utils/i18n.ts DELETED
@@ -1,90 +0,0 @@
1
- /**
2
- * i18n — ponytail approach: static key-value map, no framework dependency.
3
- *
4
- * All UI strings go through here. No hardcoded text in components.
5
- * To add a language: copy this file and translate the values.
6
- */
7
-
8
- export type Locale = "en" | "zh";
9
-
10
- const en = {
11
- // Storage security
12
- "storage.critical.title": "Insecure Storage Detected",
13
- "storage.critical.body": "Your browser does not support IndexedDB. Wallet data is stored in plaintext in localStorage and could be exposed to XSS attacks. We strongly recommend switching to a modern browser.",
14
- "storage.warning.title": "Storage Security Warning",
15
- "storage.warning.body": "Your browser does not support IndexedDB, but your wallet data is encrypted with AES-256-GCM. Consider switching browsers for better origin isolation.",
16
-
17
- // Address validation
18
- "address.empty": "Address is empty",
19
- "address.invalid_format": "Invalid address format (expected 0x + 40 hex chars)",
20
- "address.zero_address": "Address is the zero address — funds would be permanently lost",
21
- "address.burn_address": "Address appears to be a burn address — funds would be permanently lost",
22
-
23
- // General wallet
24
- "wallet.connect": "Connect Wallet",
25
- "wallet.disconnect": "Disconnect",
26
- "wallet.connecting": "Connecting...",
27
- "wallet.copy_address": "Copy address",
28
- "wallet.copied": "Copied!",
29
- "wallet.view_on_explorer": "View on Explorer",
30
- "wallet.retry": "Retry",
31
- "wallet.connection_failed": "Connection failed",
32
- "wallet.scan_qr": "Scan with your wallet app",
33
-
34
- // Embedded wallet
35
- "embedded.generate": "Create Wallet",
36
- "embedded.import": "Import Wallet",
37
- "embedded.backup_seed": "Back up your seed phrase",
38
- "embedded.backup_warning": "Anyone with your seed phrase can access your funds. Store it securely.",
39
- "embedded.backup_done": "I've saved my seed phrase",
40
- "embedded.wipe": "Remove Wallet",
41
- "embedded.wipe_confirm": "Are you sure? This cannot be undone.",
42
- } as const;
43
-
44
- const zh: Record<keyof typeof en, string> = {
45
- "storage.critical.title": "偵測到不安全儲存",
46
- "storage.critical.body": "您的瀏覽器不支援 IndexedDB。錢包資料以明文儲存在 localStorage 中,可能暴露於 XSS 攻擊。強烈建議更換至現代瀏覽器。",
47
- "storage.warning.title": "儲存安全警告",
48
- "storage.warning.body": "您的瀏覽器不支援 IndexedDB,但錢包資料已使用 AES-256-GCM 加密。建議更換瀏覽器以獲得更好的隔離保護。",
49
-
50
- "address.empty": "地址為空",
51
- "address.invalid_format": "無效的地址格式(應為 0x + 40 個十六進位字元)",
52
- "address.zero_address": "此為零地址 — 資金將永久丟失",
53
- "address.burn_address": "此地址為燒毀地址 — 資金將永久丟失",
54
-
55
- "wallet.connect": "連接錢包",
56
- "wallet.disconnect": "斷開連線",
57
- "wallet.connecting": "連線中...",
58
- "wallet.copy_address": "複製地址",
59
- "wallet.copied": "已複製!",
60
- "wallet.view_on_explorer": "在瀏覽器查看",
61
- "wallet.retry": "重試",
62
- "wallet.connection_failed": "連線失敗",
63
- "wallet.scan_qr": "使用錢包 App 掃描",
64
-
65
- "embedded.generate": "建立錢包",
66
- "embedded.import": "匯入錢包",
67
- "embedded.backup_seed": "備份助記詞",
68
- "embedded.backup_warning": "任何人取得您的助記詞都可以存取您的資金。請安全儲存。",
69
- "embedded.backup_done": "我已儲存助記詞",
70
- "embedded.wipe": "移除錢包",
71
- "embedded.wipe_confirm": "確定要移除嗎?此操作無法復原。",
72
- };
73
-
74
- const locales = { en, zh } as const;
75
-
76
- let currentLocale: Locale = "en";
77
-
78
- export function setLocale(locale: Locale): void {
79
- currentLocale = locale;
80
- }
81
-
82
- export function getLocale(): Locale {
83
- return currentLocale;
84
- }
85
-
86
- export function t(key: keyof typeof en): string {
87
- return locales[currentLocale][key] ?? locales.en[key] ?? key;
88
- }
89
-
90
- export { en, zh };