keynesol-shared 1.0.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 +118 -0
- package/dist/components/Common/ErrorBoundary.d.ts +23 -0
- package/dist/components/Common/ErrorBoundary.d.ts.map +1 -0
- package/dist/components/Common/ErrorBoundary.js +93 -0
- package/dist/components/Common/ErrorBoundary.jsx +103 -0
- package/dist/components/Common/ErrorMessage.d.ts +8 -0
- package/dist/components/Common/ErrorMessage.d.ts.map +1 -0
- package/dist/components/Common/ErrorMessage.js +36 -0
- package/dist/components/Common/ErrorMessage.jsx +40 -0
- package/dist/components/Common/Loading.d.ts +8 -0
- package/dist/components/Common/Loading.d.ts.map +1 -0
- package/dist/components/Common/Loading.js +41 -0
- package/dist/components/Common/Loading.jsx +44 -0
- package/dist/components/Common/LoadingIndicator.d.ts +17 -0
- package/dist/components/Common/LoadingIndicator.d.ts.map +1 -0
- package/dist/components/Common/LoadingIndicator.js +95 -0
- package/dist/components/Common/LoadingIndicator.jsx +108 -0
- package/dist/components/Common/ProgramStatus.d.ts +3 -0
- package/dist/components/Common/ProgramStatus.d.ts.map +1 -0
- package/dist/components/Common/ProgramStatus.js +26 -0
- package/dist/components/Common/ProgramStatus.jsx +27 -0
- package/dist/components/Common/Skeleton.d.ts +39 -0
- package/dist/components/Common/Skeleton.d.ts.map +1 -0
- package/dist/components/Common/Skeleton.js +53 -0
- package/dist/components/Common/Skeleton.jsx +67 -0
- package/dist/components/Common/SkeletonScreen.d.ts +18 -0
- package/dist/components/Common/SkeletonScreen.d.ts.map +1 -0
- package/dist/components/Common/SkeletonScreen.js +98 -0
- package/dist/components/Common/SkeletonScreen.jsx +108 -0
- package/dist/components/Common/index.d.ts +11 -0
- package/dist/components/Common/index.d.ts.map +1 -0
- package/dist/components/Common/index.js +10 -0
- package/dist/components/Wallet/TransactionStatus.d.ts +11 -0
- package/dist/components/Wallet/TransactionStatus.d.ts.map +1 -0
- package/dist/components/Wallet/TransactionStatus.js +97 -0
- package/dist/components/Wallet/TransactionStatus.jsx +106 -0
- package/dist/components/Wallet/WalletBalance.d.ts +4 -0
- package/dist/components/Wallet/WalletBalance.d.ts.map +1 -0
- package/dist/components/Wallet/WalletBalance.js +82 -0
- package/dist/components/Wallet/WalletBalance.jsx +86 -0
- package/dist/components/Wallet/WalletButton.d.ts +3 -0
- package/dist/components/Wallet/WalletButton.d.ts.map +1 -0
- package/dist/components/Wallet/WalletButton.js +51 -0
- package/dist/components/Wallet/WalletButton.jsx +53 -0
- package/dist/components/Wallet/WalletConnectionModal.d.ts +8 -0
- package/dist/components/Wallet/WalletConnectionModal.d.ts.map +1 -0
- package/dist/components/Wallet/WalletConnectionModal.js +150 -0
- package/dist/components/Wallet/WalletConnectionModal.jsx +170 -0
- package/dist/components/Wallet/WalletProvider.d.ts +9 -0
- package/dist/components/Wallet/WalletProvider.d.ts.map +1 -0
- package/dist/components/Wallet/WalletProvider.js +70 -0
- package/dist/components/Wallet/WalletProvider.jsx +75 -0
- package/dist/components/Wallet/index.d.ts +9 -0
- package/dist/components/Wallet/index.d.ts.map +1 -0
- package/dist/components/Wallet/index.js +8 -0
- package/dist/components/index.d.ts +7 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +6 -0
- package/dist/hooks/index.d.ts +10 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +9 -0
- package/dist/hooks/useCache.d.ts +16 -0
- package/dist/hooks/useCache.d.ts.map +1 -0
- package/dist/hooks/useCache.js +67 -0
- package/dist/hooks/usePolling.d.ts +16 -0
- package/dist/hooks/usePolling.d.ts.map +1 -0
- package/dist/hooks/usePolling.js +79 -0
- package/dist/hooks/useProgram.d.ts +14 -0
- package/dist/hooks/useProgram.d.ts.map +1 -0
- package/dist/hooks/useProgram.js +88 -0
- package/dist/hooks/useTokenBalance.d.ts +16 -0
- package/dist/hooks/useTokenBalance.d.ts.map +1 -0
- package/dist/hooks/useTokenBalance.js +100 -0
- package/dist/hooks/useVaults.d.ts +23 -0
- package/dist/hooks/useVaults.d.ts.map +1 -0
- package/dist/hooks/useVaults.js +98 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/services/index.d.ts +7 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +6 -0
- package/dist/services/reconciliationService.d.ts +76 -0
- package/dist/services/reconciliationService.d.ts.map +1 -0
- package/dist/services/reconciliationService.js +216 -0
- package/dist/services/syncService.d.ts +51 -0
- package/dist/services/syncService.d.ts.map +1 -0
- package/dist/services/syncService.js +218 -0
- package/dist/types/index.d.ts +201 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +1 -0
- package/dist/utils/cacheManager.d.ts +73 -0
- package/dist/utils/cacheManager.d.ts.map +1 -0
- package/dist/utils/cacheManager.js +232 -0
- package/dist/utils/errorHandler.d.ts +76 -0
- package/dist/utils/errorHandler.d.ts.map +1 -0
- package/dist/utils/errorHandler.js +267 -0
- package/dist/utils/index.d.ts +12 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +11 -0
- package/dist/utils/performanceMonitor.d.ts +75 -0
- package/dist/utils/performanceMonitor.d.ts.map +1 -0
- package/dist/utils/performanceMonitor.js +197 -0
- package/dist/utils/rpcRetry.d.ts +12 -0
- package/dist/utils/rpcRetry.d.ts.map +1 -0
- package/dist/utils/rpcRetry.js +47 -0
- package/dist/utils/supabase.d.ts +198 -0
- package/dist/utils/supabase.d.ts.map +1 -0
- package/dist/utils/supabase.js +50 -0
- package/dist/utils/toastService.d.ts +52 -0
- package/dist/utils/toastService.d.ts.map +1 -0
- package/dist/utils/toastService.js +139 -0
- package/dist/utils/tokenUtils.d.ts +33 -0
- package/dist/utils/tokenUtils.d.ts.map +1 -0
- package/dist/utils/tokenUtils.js +66 -0
- package/dist/utils/validation.d.ts +35 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +83 -0
- package/package.json +45 -0
- package/src/components/Common/ErrorBoundary.tsx +135 -0
- package/src/components/Common/ErrorMessage.tsx +52 -0
- package/src/components/Common/Loading.tsx +56 -0
- package/src/components/Common/LoadingIndicator.tsx +143 -0
- package/src/components/Common/ProgramStatus.tsx +37 -0
- package/src/components/Common/Skeleton.tsx +83 -0
- package/src/components/Common/SkeletonScreen.tsx +166 -0
- package/src/components/Common/index.ts +10 -0
- package/src/components/Wallet/TransactionStatus.tsx +138 -0
- package/src/components/Wallet/WalletBalance.tsx +94 -0
- package/src/components/Wallet/WalletButton.tsx +65 -0
- package/src/components/Wallet/WalletConnectionModal.tsx +193 -0
- package/src/components/Wallet/WalletProvider.tsx +104 -0
- package/src/components/Wallet/index.ts +8 -0
- package/src/components/index.ts +6 -0
- package/src/hooks/index.ts +10 -0
- package/src/hooks/useCache.ts +87 -0
- package/src/hooks/usePolling.ts +98 -0
- package/src/hooks/useProgram.ts +93 -0
- package/src/hooks/useTokenBalance.ts +113 -0
- package/src/hooks/useVaults.ts +122 -0
- package/src/index.ts +23 -0
- package/src/services/index.ts +6 -0
- package/src/services/reconciliationService.ts +246 -0
- package/src/services/syncService.ts +238 -0
- package/src/types/index.ts +233 -0
- package/src/utils/cacheManager.ts +286 -0
- package/src/utils/errorHandler.ts +336 -0
- package/src/utils/index.ts +12 -0
- package/src/utils/performanceMonitor.ts +222 -0
- package/src/utils/rpcRetry.ts +55 -0
- package/src/utils/supabase.ts +253 -0
- package/src/utils/toastService.ts +166 -0
- package/src/utils/tokenUtils.ts +75 -0
- package/src/utils/validation.ts +107 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import React from 'react';
|
|
11
|
+
import styled from 'styled-components';
|
|
12
|
+
import { useWallet } from '@solana/wallet-adapter-react';
|
|
13
|
+
const ModalOverlay = styled.div `
|
|
14
|
+
display: ${props => props.isOpen ? 'flex' : 'none'};
|
|
15
|
+
position: fixed;
|
|
16
|
+
top: 0;
|
|
17
|
+
left: 0;
|
|
18
|
+
right: 0;
|
|
19
|
+
bottom: 0;
|
|
20
|
+
background: rgba(0, 0, 0, 0.8);
|
|
21
|
+
backdrop-filter: blur(4px);
|
|
22
|
+
z-index: 1000;
|
|
23
|
+
align-items: center;
|
|
24
|
+
justify-content: center;
|
|
25
|
+
animation: fadeIn 0.2s ease-in-out;
|
|
26
|
+
|
|
27
|
+
@keyframes fadeIn {
|
|
28
|
+
from { opacity: 0; }
|
|
29
|
+
to { opacity: 1; }
|
|
30
|
+
}
|
|
31
|
+
`;
|
|
32
|
+
const ModalContent = styled.div `
|
|
33
|
+
background: var(--color-surface, #f9fafb);
|
|
34
|
+
border: 1px solid var(--color-primary, #6a8102);
|
|
35
|
+
border-radius: 1rem;
|
|
36
|
+
padding: 2rem;
|
|
37
|
+
max-width: 400px;
|
|
38
|
+
width: 90%;
|
|
39
|
+
animation: slideUp 0.3s ease-out;
|
|
40
|
+
|
|
41
|
+
@keyframes slideUp {
|
|
42
|
+
from {
|
|
43
|
+
transform: translateY(20px);
|
|
44
|
+
opacity: 0;
|
|
45
|
+
}
|
|
46
|
+
to {
|
|
47
|
+
transform: translateY(0);
|
|
48
|
+
opacity: 1;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
`;
|
|
52
|
+
const ModalHeader = styled.div `
|
|
53
|
+
display: flex;
|
|
54
|
+
justify-content: space-between;
|
|
55
|
+
align-items: center;
|
|
56
|
+
margin-bottom: 1.5rem;
|
|
57
|
+
`;
|
|
58
|
+
const ModalTitle = styled.h2 `
|
|
59
|
+
font-size: 1.5rem;
|
|
60
|
+
color: var(--color-text, #1a1a1a);
|
|
61
|
+
margin: 0;
|
|
62
|
+
`;
|
|
63
|
+
const CloseButton = styled.button `
|
|
64
|
+
background: none;
|
|
65
|
+
border: none;
|
|
66
|
+
color: var(--color-text-secondary, #6b7280);
|
|
67
|
+
font-size: 1.5rem;
|
|
68
|
+
cursor: pointer;
|
|
69
|
+
padding: 0;
|
|
70
|
+
width: 32px;
|
|
71
|
+
height: 32px;
|
|
72
|
+
display: flex;
|
|
73
|
+
align-items: center;
|
|
74
|
+
justify-content: center;
|
|
75
|
+
border-radius: 0.5rem;
|
|
76
|
+
transition: all 0.2s;
|
|
77
|
+
|
|
78
|
+
&:hover {
|
|
79
|
+
background: var(--color-background, #ffffff);
|
|
80
|
+
color: var(--color-text, #1a1a1a);
|
|
81
|
+
}
|
|
82
|
+
`;
|
|
83
|
+
const WalletList = styled.div `
|
|
84
|
+
display: flex;
|
|
85
|
+
flex-direction: column;
|
|
86
|
+
gap: 0.75rem;
|
|
87
|
+
`;
|
|
88
|
+
const WalletButton = styled.button `
|
|
89
|
+
display: flex;
|
|
90
|
+
align-items: center;
|
|
91
|
+
gap: 1rem;
|
|
92
|
+
padding: 1rem;
|
|
93
|
+
background: var(--color-background, #ffffff);
|
|
94
|
+
border: 1px solid var(--color-primary, #6a8102);
|
|
95
|
+
border-radius: 0.5rem;
|
|
96
|
+
color: var(--color-text, #1a1a1a);
|
|
97
|
+
font-size: 1rem;
|
|
98
|
+
font-weight: 500;
|
|
99
|
+
cursor: pointer;
|
|
100
|
+
transition: all 0.2s;
|
|
101
|
+
|
|
102
|
+
&:hover {
|
|
103
|
+
background: var(--color-primary, #6a8102);
|
|
104
|
+
color: var(--color-background, #ffffff);
|
|
105
|
+
transform: translateX(4px);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
&:disabled {
|
|
109
|
+
opacity: 0.5;
|
|
110
|
+
cursor: not-allowed;
|
|
111
|
+
transform: none;
|
|
112
|
+
}
|
|
113
|
+
`;
|
|
114
|
+
const WalletIcon = styled.div `
|
|
115
|
+
width: 32px;
|
|
116
|
+
height: 32px;
|
|
117
|
+
display: flex;
|
|
118
|
+
align-items: center;
|
|
119
|
+
justify-content: center;
|
|
120
|
+
font-size: 1.5rem;
|
|
121
|
+
`;
|
|
122
|
+
const WalletName = styled.span `
|
|
123
|
+
flex: 1;
|
|
124
|
+
text-align: left;
|
|
125
|
+
`;
|
|
126
|
+
const Description = styled.p `
|
|
127
|
+
color: var(--color-text-secondary, #6b7280);
|
|
128
|
+
font-size: 0.875rem;
|
|
129
|
+
margin-bottom: 1.5rem;
|
|
130
|
+
line-height: 1.5;
|
|
131
|
+
`;
|
|
132
|
+
const WalletConnectionModal = ({ isOpen, onClose }) => {
|
|
133
|
+
const { wallets, select, connecting } = useWallet();
|
|
134
|
+
const handleWalletSelect = (walletName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
135
|
+
try {
|
|
136
|
+
select(walletName);
|
|
137
|
+
onClose();
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
console.error('Failed to select wallet:', error);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
const handleOverlayClick = (e) => {
|
|
144
|
+
if (e.target === e.currentTarget) {
|
|
145
|
+
onClose();
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
return (<ModalOverlay isOpen={isOpen} onClick={handleOverlayClick}>
|
|
149
|
+
<ModalContent>
|
|
150
|
+
<ModalHeader>
|
|
151
|
+
<ModalTitle>Connect Wallet</ModalTitle>
|
|
152
|
+
<CloseButton onClick={onClose}>×</CloseButton>
|
|
153
|
+
</ModalHeader>
|
|
154
|
+
|
|
155
|
+
<Description>
|
|
156
|
+
Select a wallet to connect to the Web3 Prediction Platform and start staking.
|
|
157
|
+
</Description>
|
|
158
|
+
|
|
159
|
+
<WalletList>
|
|
160
|
+
{wallets.map((wallet) => (<WalletButton key={wallet.adapter.name} onClick={() => handleWalletSelect(wallet.adapter.name)} disabled={connecting}>
|
|
161
|
+
<WalletIcon>
|
|
162
|
+
{wallet.adapter.icon ? (<img src={wallet.adapter.icon} alt={wallet.adapter.name} width={32} height={32}/>) : ('👛')}
|
|
163
|
+
</WalletIcon>
|
|
164
|
+
<WalletName>{wallet.adapter.name}</WalletName>
|
|
165
|
+
</WalletButton>))}
|
|
166
|
+
</WalletList>
|
|
167
|
+
</ModalContent>
|
|
168
|
+
</ModalOverlay>);
|
|
169
|
+
};
|
|
170
|
+
export default WalletConnectionModal;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
interface WalletProviderProps {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
network?: 'devnet' | 'mainnet-beta' | 'testnet';
|
|
5
|
+
rpcEndpoint?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const WalletProvider: ({ children, network: networkProp, rpcEndpoint: rpcEndpointProp }: WalletProviderProps) => React.JSX.Element;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=WalletProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WalletProvider.d.ts","sourceRoot":"","sources":["../../../src/components/Wallet/WalletProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAW,SAAS,EAAE,MAAM,OAAO,CAAC;AASlD,UAAU,mBAAmB;IAC3B,QAAQ,EAAE,SAAS,CAAC;IACpB,OAAO,CAAC,EAAE,QAAQ,GAAG,cAAc,GAAG,SAAS,CAAC;IAChD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,cAAc,GAAI,kEAI5B,mBAAmB,sBAoFrB,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { ConnectionProvider, WalletProvider as SolanaWalletProvider } from '@solana/wallet-adapter-react';
|
|
4
|
+
import { WalletAdapterNetwork } from '@solana/wallet-adapter-base';
|
|
5
|
+
import { PhantomWalletAdapter, SolflareWalletAdapter } from '@solana/wallet-adapter-wallets';
|
|
6
|
+
import { WalletModalProvider } from '@solana/wallet-adapter-react-ui';
|
|
7
|
+
import { clusterApiUrl } from '@solana/web3.js';
|
|
8
|
+
require('@solana/wallet-adapter-react-ui/styles.css');
|
|
9
|
+
export const WalletProvider = ({ children, network: networkProp, rpcEndpoint: rpcEndpointProp }) => {
|
|
10
|
+
var _a;
|
|
11
|
+
// Get network from prop, environment variable, or default to devnet
|
|
12
|
+
const networkEnv = networkProp ||
|
|
13
|
+
(typeof process !== 'undefined' && ((_a = process.env) === null || _a === void 0 ? void 0 : _a.NEXT_PUBLIC_SOLANA_NETWORK)) ||
|
|
14
|
+
'devnet';
|
|
15
|
+
const network = networkEnv === 'mainnet-beta'
|
|
16
|
+
? WalletAdapterNetwork.Mainnet
|
|
17
|
+
: networkEnv === 'testnet'
|
|
18
|
+
? WalletAdapterNetwork.Testnet
|
|
19
|
+
: WalletAdapterNetwork.Devnet;
|
|
20
|
+
// Use custom RPC endpoint if provided, otherwise use cluster API URL
|
|
21
|
+
const endpoint = useMemo(() => {
|
|
22
|
+
var _a;
|
|
23
|
+
const customEndpoint = rpcEndpointProp ||
|
|
24
|
+
(typeof process !== 'undefined' && ((_a = process.env) === null || _a === void 0 ? void 0 : _a.NEXT_PUBLIC_RPC_ENDPOINT));
|
|
25
|
+
if (customEndpoint) {
|
|
26
|
+
return customEndpoint;
|
|
27
|
+
}
|
|
28
|
+
return clusterApiUrl(network);
|
|
29
|
+
}, [network, rpcEndpointProp]);
|
|
30
|
+
const wallets = useMemo(() => {
|
|
31
|
+
const walletAdapters = [];
|
|
32
|
+
// Only add Phantom if it's not already registered as Standard Wallet
|
|
33
|
+
try {
|
|
34
|
+
const phantom = new PhantomWalletAdapter();
|
|
35
|
+
walletAdapters.push(phantom);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
console.warn('Phantom wallet adapter already registered or error:', error);
|
|
39
|
+
}
|
|
40
|
+
// Add Solflare
|
|
41
|
+
try {
|
|
42
|
+
const solflare = new SolflareWalletAdapter();
|
|
43
|
+
walletAdapters.push(solflare);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
console.warn('Solflare wallet adapter error:', error);
|
|
47
|
+
}
|
|
48
|
+
return walletAdapters;
|
|
49
|
+
}, []);
|
|
50
|
+
// Disable WebSocket for custom RPC endpoints that may not support it
|
|
51
|
+
// Solana SDK will automatically fallback to HTTP polling
|
|
52
|
+
const connectionConfig = useMemo(() => {
|
|
53
|
+
var _a;
|
|
54
|
+
const customEndpoint = rpcEndpointProp ||
|
|
55
|
+
(typeof process !== 'undefined' && ((_a = process.env) === null || _a === void 0 ? void 0 : _a.NEXT_PUBLIC_RPC_ENDPOINT));
|
|
56
|
+
// If using custom endpoint (not public Solana RPC), disable WebSocket
|
|
57
|
+
const isCustomEndpoint = customEndpoint &&
|
|
58
|
+
!customEndpoint.includes('api.devnet.solana.com') &&
|
|
59
|
+
!customEndpoint.includes('api.mainnet-beta.solana.com') &&
|
|
60
|
+
!customEndpoint.includes('api.testnet.solana.com');
|
|
61
|
+
return Object.assign({ commitment: 'confirmed' }, (isCustomEndpoint ? {
|
|
62
|
+
wsEndpoint: undefined,
|
|
63
|
+
disableRetryOnRateLimit: false,
|
|
64
|
+
} : {}));
|
|
65
|
+
}, [rpcEndpointProp]);
|
|
66
|
+
// Type assertion to fix React 18/19 compatibility
|
|
67
|
+
const ConnectionProviderComponent = ConnectionProvider;
|
|
68
|
+
// Type assertion to fix React 18/19 compatibility
|
|
69
|
+
return (_jsx(ConnectionProviderComponent, { endpoint: endpoint, config: connectionConfig, children: _jsx(SolanaWalletProvider, { wallets: wallets, autoConnect: true, children: _jsx(WalletModalProvider, { children: children }) }) }));
|
|
70
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { ConnectionProvider, WalletProvider as SolanaWalletProvider } from '@solana/wallet-adapter-react';
|
|
3
|
+
import { WalletAdapterNetwork } from '@solana/wallet-adapter-base';
|
|
4
|
+
import { PhantomWalletAdapter, SolflareWalletAdapter } from '@solana/wallet-adapter-wallets';
|
|
5
|
+
import { WalletModalProvider } from '@solana/wallet-adapter-react-ui';
|
|
6
|
+
import { clusterApiUrl } from '@solana/web3.js';
|
|
7
|
+
require('@solana/wallet-adapter-react-ui/styles.css');
|
|
8
|
+
export const WalletProvider = ({ children, network: networkProp, rpcEndpoint: rpcEndpointProp }) => {
|
|
9
|
+
var _a;
|
|
10
|
+
// Get network from prop, environment variable, or default to devnet
|
|
11
|
+
const networkEnv = networkProp ||
|
|
12
|
+
(typeof process !== 'undefined' && ((_a = process.env) === null || _a === void 0 ? void 0 : _a.NEXT_PUBLIC_SOLANA_NETWORK)) ||
|
|
13
|
+
'devnet';
|
|
14
|
+
const network = networkEnv === 'mainnet-beta'
|
|
15
|
+
? WalletAdapterNetwork.Mainnet
|
|
16
|
+
: networkEnv === 'testnet'
|
|
17
|
+
? WalletAdapterNetwork.Testnet
|
|
18
|
+
: WalletAdapterNetwork.Devnet;
|
|
19
|
+
// Use custom RPC endpoint if provided, otherwise use cluster API URL
|
|
20
|
+
const endpoint = useMemo(() => {
|
|
21
|
+
var _a;
|
|
22
|
+
const customEndpoint = rpcEndpointProp ||
|
|
23
|
+
(typeof process !== 'undefined' && ((_a = process.env) === null || _a === void 0 ? void 0 : _a.NEXT_PUBLIC_RPC_ENDPOINT));
|
|
24
|
+
if (customEndpoint) {
|
|
25
|
+
return customEndpoint;
|
|
26
|
+
}
|
|
27
|
+
return clusterApiUrl(network);
|
|
28
|
+
}, [network, rpcEndpointProp]);
|
|
29
|
+
const wallets = useMemo(() => {
|
|
30
|
+
const walletAdapters = [];
|
|
31
|
+
// Only add Phantom if it's not already registered as Standard Wallet
|
|
32
|
+
try {
|
|
33
|
+
const phantom = new PhantomWalletAdapter();
|
|
34
|
+
walletAdapters.push(phantom);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
console.warn('Phantom wallet adapter already registered or error:', error);
|
|
38
|
+
}
|
|
39
|
+
// Add Solflare
|
|
40
|
+
try {
|
|
41
|
+
const solflare = new SolflareWalletAdapter();
|
|
42
|
+
walletAdapters.push(solflare);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
console.warn('Solflare wallet adapter error:', error);
|
|
46
|
+
}
|
|
47
|
+
return walletAdapters;
|
|
48
|
+
}, []);
|
|
49
|
+
// Disable WebSocket for custom RPC endpoints that may not support it
|
|
50
|
+
// Solana SDK will automatically fallback to HTTP polling
|
|
51
|
+
const connectionConfig = useMemo(() => {
|
|
52
|
+
var _a;
|
|
53
|
+
const customEndpoint = rpcEndpointProp ||
|
|
54
|
+
(typeof process !== 'undefined' && ((_a = process.env) === null || _a === void 0 ? void 0 : _a.NEXT_PUBLIC_RPC_ENDPOINT));
|
|
55
|
+
// If using custom endpoint (not public Solana RPC), disable WebSocket
|
|
56
|
+
const isCustomEndpoint = customEndpoint &&
|
|
57
|
+
!customEndpoint.includes('api.devnet.solana.com') &&
|
|
58
|
+
!customEndpoint.includes('api.mainnet-beta.solana.com') &&
|
|
59
|
+
!customEndpoint.includes('api.testnet.solana.com');
|
|
60
|
+
return Object.assign({ commitment: 'confirmed' }, (isCustomEndpoint ? {
|
|
61
|
+
wsEndpoint: undefined,
|
|
62
|
+
disableRetryOnRateLimit: false,
|
|
63
|
+
} : {}));
|
|
64
|
+
}, [rpcEndpointProp]);
|
|
65
|
+
// Type assertion to fix React 18/19 compatibility
|
|
66
|
+
const ConnectionProviderComponent = ConnectionProvider;
|
|
67
|
+
// Type assertion to fix React 18/19 compatibility
|
|
68
|
+
return (<ConnectionProviderComponent endpoint={endpoint} config={connectionConfig}>
|
|
69
|
+
<SolanaWalletProvider wallets={wallets} autoConnect>
|
|
70
|
+
<WalletModalProvider>
|
|
71
|
+
{children}
|
|
72
|
+
</WalletModalProvider>
|
|
73
|
+
</SolanaWalletProvider>
|
|
74
|
+
</ConnectionProviderComponent>);
|
|
75
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wallet Components Index
|
|
3
|
+
*/
|
|
4
|
+
export * from './WalletProvider';
|
|
5
|
+
export * from './WalletButton';
|
|
6
|
+
export { default as WalletBalance } from './WalletBalance';
|
|
7
|
+
export { default as TransactionStatus } from './TransactionStatus';
|
|
8
|
+
export { default as WalletConnectionModal } from './WalletConnectionModal';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Wallet/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wallet Components Index
|
|
3
|
+
*/
|
|
4
|
+
export * from './WalletProvider';
|
|
5
|
+
export * from './WalletButton';
|
|
6
|
+
export { default as WalletBalance } from './WalletBalance';
|
|
7
|
+
export { default as TransactionStatus } from './TransactionStatus';
|
|
8
|
+
export { default as WalletConnectionModal } from './WalletConnectionModal';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface CacheOptions {
|
|
2
|
+
ttl?: number;
|
|
3
|
+
key?: string;
|
|
4
|
+
namespace?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Custom hook for caching data with automatic invalidation
|
|
8
|
+
*/
|
|
9
|
+
export declare const useCache: <T>(fetchFn: () => Promise<T>, options?: CacheOptions) => {
|
|
10
|
+
data: T | null;
|
|
11
|
+
loading: boolean;
|
|
12
|
+
error: Error | null;
|
|
13
|
+
refetch: () => Promise<void>;
|
|
14
|
+
invalidate: () => void;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=useCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCache.d.ts","sourceRoot":"","sources":["../../src/hooks/useCache.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,YAAY;IAC3B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,EACxB,SAAS,MAAM,OAAO,CAAC,CAAC,CAAC,EACzB,UAAS,YAAiB,KACzB;IACD,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,UAAU,EAAE,MAAM,IAAI,CAAC;CAwDxB,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Caching Hook for Blockchain Data
|
|
12
|
+
* Requirements: 12.1 - Multi-level caching for blockchain data with cache invalidation
|
|
13
|
+
*/
|
|
14
|
+
import React from 'react';
|
|
15
|
+
import { cacheManager } from '../utils/cacheManager';
|
|
16
|
+
/**
|
|
17
|
+
* Custom hook for caching data with automatic invalidation
|
|
18
|
+
*/
|
|
19
|
+
export const useCache = (fetchFn, options = {}) => {
|
|
20
|
+
const { ttl, key, namespace = 'default' } = options;
|
|
21
|
+
const cacheKey = key || `cache_${fetchFn.toString()}`;
|
|
22
|
+
const [data, setData] = React.useState(() => {
|
|
23
|
+
return cacheManager.get(namespace, cacheKey);
|
|
24
|
+
});
|
|
25
|
+
const [loading, setLoading] = React.useState(!data);
|
|
26
|
+
const [error, setError] = React.useState(null);
|
|
27
|
+
const fetchData = React.useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
// Check cache first
|
|
29
|
+
const cached = cacheManager.get(namespace, cacheKey);
|
|
30
|
+
if (cached) {
|
|
31
|
+
setData(cached);
|
|
32
|
+
setLoading(false);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
setLoading(true);
|
|
37
|
+
setError(null);
|
|
38
|
+
const result = yield fetchFn();
|
|
39
|
+
// Store in cache (using default TTL from namespace config if not provided)
|
|
40
|
+
const cacheTtl = ttl || 5000; // Default 5 seconds
|
|
41
|
+
cacheManager.set(namespace, cacheKey, result, cacheTtl);
|
|
42
|
+
setData(result);
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
setError(err);
|
|
46
|
+
setData(null);
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
setLoading(false);
|
|
50
|
+
}
|
|
51
|
+
}), [fetchFn, namespace, cacheKey, ttl]);
|
|
52
|
+
React.useEffect(() => {
|
|
53
|
+
fetchData();
|
|
54
|
+
}, [fetchData]);
|
|
55
|
+
const invalidate = React.useCallback(() => {
|
|
56
|
+
cacheManager.invalidate(namespace, cacheKey);
|
|
57
|
+
setData(null);
|
|
58
|
+
fetchData();
|
|
59
|
+
}, [namespace, cacheKey, fetchData]);
|
|
60
|
+
return {
|
|
61
|
+
data,
|
|
62
|
+
loading,
|
|
63
|
+
error,
|
|
64
|
+
refetch: fetchData,
|
|
65
|
+
invalidate,
|
|
66
|
+
};
|
|
67
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface PollingOptions {
|
|
2
|
+
interval?: number;
|
|
3
|
+
enabled?: boolean;
|
|
4
|
+
onError?: (error: Error) => void;
|
|
5
|
+
immediate?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Hook for polling data at regular intervals
|
|
9
|
+
* Implements Requirement 10.1: 5-second data synchronization
|
|
10
|
+
*/
|
|
11
|
+
export declare const usePolling: (callback: () => Promise<void> | void, options?: PollingOptions) => {
|
|
12
|
+
start: () => void;
|
|
13
|
+
stop: () => void;
|
|
14
|
+
isActive: boolean;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=usePolling.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePolling.d.ts","sourceRoot":"","sources":["../../src/hooks/usePolling.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;GAGG;AACH,eAAO,MAAM,UAAU,GACrB,UAAU,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,EACpC,UAAS,cAAmB,KAC3B;IACD,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;CA0EnB,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Polling Hook for Real-Time Data Synchronization
|
|
12
|
+
* Requirements: 10.1 - 5-second blockchain data synchronization
|
|
13
|
+
*/
|
|
14
|
+
import { useEffect, useRef, useCallback } from 'react';
|
|
15
|
+
/**
|
|
16
|
+
* Hook for polling data at regular intervals
|
|
17
|
+
* Implements Requirement 10.1: 5-second data synchronization
|
|
18
|
+
*/
|
|
19
|
+
export const usePolling = (callback, options = {}) => {
|
|
20
|
+
const { interval = 5000, // 5 seconds default
|
|
21
|
+
enabled = true, onError, immediate = true, } = options;
|
|
22
|
+
const intervalRef = useRef(null);
|
|
23
|
+
const isActiveRef = useRef(false);
|
|
24
|
+
const callbackRef = useRef(callback);
|
|
25
|
+
// Update callback ref when it changes
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
callbackRef.current = callback;
|
|
28
|
+
}, [callback]);
|
|
29
|
+
const execute = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
try {
|
|
31
|
+
yield callbackRef.current();
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
console.error('Polling error:', error);
|
|
35
|
+
if (onError) {
|
|
36
|
+
onError(error);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}), [onError]);
|
|
40
|
+
const start = useCallback(() => {
|
|
41
|
+
if (isActiveRef.current) {
|
|
42
|
+
return; // Already running
|
|
43
|
+
}
|
|
44
|
+
isActiveRef.current = true;
|
|
45
|
+
// Execute immediately if requested
|
|
46
|
+
if (immediate) {
|
|
47
|
+
execute();
|
|
48
|
+
}
|
|
49
|
+
// Set up interval
|
|
50
|
+
intervalRef.current = setInterval(() => {
|
|
51
|
+
execute();
|
|
52
|
+
}, interval);
|
|
53
|
+
}, [interval, immediate, execute]);
|
|
54
|
+
const stop = useCallback(() => {
|
|
55
|
+
if (intervalRef.current) {
|
|
56
|
+
clearInterval(intervalRef.current);
|
|
57
|
+
intervalRef.current = null;
|
|
58
|
+
}
|
|
59
|
+
isActiveRef.current = false;
|
|
60
|
+
}, []);
|
|
61
|
+
// Auto-start/stop based on enabled flag
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (enabled) {
|
|
64
|
+
start();
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
stop();
|
|
68
|
+
}
|
|
69
|
+
// Cleanup on unmount
|
|
70
|
+
return () => {
|
|
71
|
+
stop();
|
|
72
|
+
};
|
|
73
|
+
}, [enabled, start, stop]);
|
|
74
|
+
return {
|
|
75
|
+
start,
|
|
76
|
+
stop,
|
|
77
|
+
isActive: isActiveRef.current,
|
|
78
|
+
};
|
|
79
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AnchorProvider, Idl } from '@coral-xyz/anchor';
|
|
2
|
+
import { PublicKey } from '@solana/web3.js';
|
|
3
|
+
export interface UseProgramOptions {
|
|
4
|
+
idlPath?: string;
|
|
5
|
+
programId?: PublicKey;
|
|
6
|
+
}
|
|
7
|
+
export declare const useProgram: (options?: UseProgramOptions) => {
|
|
8
|
+
program: any;
|
|
9
|
+
provider: AnchorProvider;
|
|
10
|
+
idl: Idl;
|
|
11
|
+
idlError: string;
|
|
12
|
+
programId: PublicKey;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=useProgram.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useProgram.d.ts","sourceRoot":"","sources":["../../src/hooks/useProgram.ts"],"names":[],"mappings":"AAEA,OAAO,EAAW,cAAc,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAmB5C,MAAM,WAAW,iBAAiB;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAED,eAAO,MAAM,UAAU,GAAI,UAAS,iBAAsB;;;;;;CAiEzD,CAAC"}
|