@n1xyz/wallet-widget 0.0.1 → 0.0.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/LICENSE +44 -0
- package/README.md +45 -0
- package/dist/Logic/utils.d.ts +1 -0
- package/dist/Logic/utils.js +47 -9
- package/dist/Modal/BackButton.js +14 -1
- package/dist/Modal/ConnectView.js +20 -23
- package/dist/Modal/CreateSessionView.js +23 -11
- package/dist/Modal/CreateUserView.js +1 -1
- package/dist/Modal/ModalHeader.js +14 -3
- package/dist/Modal/N1WalletModal.js +35 -30
- package/dist/Modal/NoWhitelistView.js +14 -1
- package/dist/Modal/Sidebar/N1Sidebar.js +152 -13
- package/dist/Modal/SigningView.js +1 -1
- package/dist/Provider/LazyWalletProvider.js +6 -2
- package/dist/Provider/N1WalletProvider.js +10 -7
- package/dist/Provider/types.d.ts +8 -0
- package/dist/components/Logo.d.ts +7 -0
- package/dist/components/Logo.js +118 -0
- package/dist/components/QRCodeLoader.d.ts +4 -0
- package/dist/components/QRCodeLoader.js +8 -0
- package/dist/components/WalletDeposit/AnimatedButton.d.ts +17 -0
- package/dist/components/WalletDeposit/AnimatedButton.js +29 -0
- package/dist/components/WalletDeposit/components/ChainButton.d.ts +7 -0
- package/dist/components/WalletDeposit/components/ChainButton.js +5 -0
- package/dist/components/WalletDeposit/components/LoadingSquares.d.ts +1 -0
- package/dist/components/WalletDeposit/components/LoadingSquares.js +5 -0
- package/dist/components/WalletDeposit/components/TransactionTable.d.ts +6 -0
- package/dist/components/WalletDeposit/components/TransactionTable.js +8 -0
- package/dist/components/WalletDeposit/components/WaitingMessage.d.ts +6 -0
- package/dist/components/WalletDeposit/components/WaitingMessage.js +6 -0
- package/dist/components/WalletDeposit/constants.d.ts +15 -0
- package/dist/components/WalletDeposit/constants.js +32 -0
- package/dist/components/WalletDeposit/hooks.d.ts +9 -0
- package/dist/components/WalletDeposit/hooks.js +185 -0
- package/dist/components/WalletDeposit/index.d.ts +1 -0
- package/dist/components/WalletDeposit/index.js +136 -0
- package/dist/components/WalletDeposit/screens/AmountInputScreen.d.ts +12 -0
- package/dist/components/WalletDeposit/screens/AmountInputScreen.js +18 -0
- package/dist/components/WalletDeposit/screens/AppsTableScreen.d.ts +8 -0
- package/dist/components/WalletDeposit/screens/AppsTableScreen.js +28 -0
- package/dist/components/WalletDeposit/screens/ChainSelectionScreen.d.ts +5 -0
- package/dist/components/WalletDeposit/screens/ChainSelectionScreen.js +8 -0
- package/dist/components/WalletDeposit/screens/InitialScreen.d.ts +9 -0
- package/dist/components/WalletDeposit/screens/InitialScreen.js +18 -0
- package/dist/components/WalletDeposit/screens/SigningScreen.d.ts +6 -0
- package/dist/components/WalletDeposit/screens/SigningScreen.js +6 -0
- package/dist/components/WalletDeposit/screens/SuccessScreen.d.ts +12 -0
- package/dist/components/WalletDeposit/screens/SuccessScreen.js +7 -0
- package/dist/components/WalletDeposit/types.d.ts +43 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/main.css +1 -1
- package/dist/utils/dynamicImports.d.ts +24 -0
- package/dist/utils/dynamicImports.js +41 -0
- package/dist/utils/shortenString.d.ts +2 -0
- package/dist/utils/shortenString.js +8 -0
- package/package.json +13 -9
- package/.eslintrc.js +0 -29
- package/dist/Common/NIcon.js +0 -7
- package/dist/components/AnimatedButton.d.ts +0 -9
- package/dist/components/AnimatedButton.js +0 -5
- package/postcss.config.js +0 -6
- package/src/Logic/getPseudoName.ts +0 -5832
- package/src/Logic/utils.ts +0 -162
- package/src/Logic/words.ts +0 -93571
- package/src/Modal/BackButton.tsx +0 -23
- package/src/Modal/ConnectView.tsx +0 -88
- package/src/Modal/CreateSessionView.tsx +0 -242
- package/src/Modal/CreateUserView.tsx +0 -195
- package/src/Modal/ModalHeader.tsx +0 -64
- package/src/Modal/N1WalletModal.tsx +0 -275
- package/src/Modal/NoWhitelistView.tsx +0 -61
- package/src/Modal/Sidebar/N1Sidebar.tsx +0 -172
- package/src/Modal/SigningView.tsx +0 -18
- package/src/Modal/SuccessView.tsx +0 -36
- package/src/Provider/LazyWalletProvider.tsx +0 -136
- package/src/Provider/N1WalletProvider.tsx +0 -208
- package/src/Provider/context.ts +0 -11
- package/src/Provider/hooks.ts +0 -22
- package/src/Provider/icons/CoinbaseWalletIcon.tsx +0 -27
- package/src/Provider/icons/ConnectionDotsSVG.tsx +0 -19
- package/src/Provider/icons/MetamaskIcon.tsx +0 -58
- package/src/Provider/icons/PhantomIcon.tsx +0 -26
- package/src/Provider/icons/UserIcon.tsx +0 -15
- package/src/Provider/icons/WalletConnectIcon.tsx +0 -15
- package/src/Provider/index.ts +0 -3
- package/src/Provider/types.ts +0 -77
- package/src/WidgetButton/N1ConnectButton.tsx +0 -72
- package/src/components/LazyLoadWrapper.tsx +0 -19
- package/src/config.ts +0 -2
- package/src/errors/types.ts +0 -49
- package/src/index.ts +0 -5
- package/src/main.css +0 -3
- package/src/styles/main.css +0 -3
- package/src/utils/lazyLoad.ts +0 -12
- package/src/utils/logger.ts +0 -98
- package/src/utils/react-shim.js +0 -8
- package/tailwind.config.js +0 -44
- package/tsconfig.json +0 -21
- /package/dist/{Common/NIcon.d.ts → components/WalletDeposit/types.js} +0 -0
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useState, lazy, Suspense } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
useN1WalletContext,
|
|
4
|
-
useN1WalletInternalContext,
|
|
5
|
-
} from '../Provider/hooks';
|
|
6
|
-
import {
|
|
7
|
-
createWebSession,
|
|
8
|
-
getSessionKeysFromLocalStorage,
|
|
9
|
-
getUser,
|
|
10
|
-
} from '../Logic/utils';
|
|
11
|
-
import { getEd25519PublicKey, signEd25519, bs58Decode } from '@n1xyz/nts-sdk';
|
|
12
|
-
import { N1ModalViewMode } from '../Provider/types';
|
|
13
|
-
import { logger } from '../utils/logger';
|
|
14
|
-
import { WalletError, WalletErrorCode } from '../errors/types';
|
|
15
|
-
|
|
16
|
-
// Lazy load components
|
|
17
|
-
const ConnectView = lazy(() =>
|
|
18
|
-
import('./ConnectView').then((mod) => ({ default: mod.ConnectView }))
|
|
19
|
-
);
|
|
20
|
-
const CreateSessionView = lazy(() =>
|
|
21
|
-
import('./CreateSessionView').then((mod) => ({
|
|
22
|
-
default: mod.CreateSessionView,
|
|
23
|
-
}))
|
|
24
|
-
);
|
|
25
|
-
const SigningView = lazy(() =>
|
|
26
|
-
import('./SigningView').then((mod) => ({ default: mod.SigningView }))
|
|
27
|
-
);
|
|
28
|
-
const CreateUserView = lazy(() =>
|
|
29
|
-
import('./CreateUserView').then((mod) => ({ default: mod.CreateUserView }))
|
|
30
|
-
);
|
|
31
|
-
const SuccessView = lazy(() =>
|
|
32
|
-
import('./SuccessView').then((mod) => ({ default: mod.SuccessView }))
|
|
33
|
-
);
|
|
34
|
-
const N1Sidebar = lazy(() =>
|
|
35
|
-
import('./Sidebar/N1Sidebar').then((mod) => ({ default: mod.N1Sidebar }))
|
|
36
|
-
);
|
|
37
|
-
const NoWhitelistView = lazy(() =>
|
|
38
|
-
import('./NoWhitelistView').then((mod) => ({ default: mod.NoWhitelistView }))
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
const LoadingFallback = () => (
|
|
42
|
-
<div className="flex items-center justify-center w-full h-full">
|
|
43
|
-
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-white"></div>
|
|
44
|
-
</div>
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
export function N1WalletModal() {
|
|
48
|
-
const { showLogin, setShowLogin, viewMode } = useN1WalletContext();
|
|
49
|
-
|
|
50
|
-
const {
|
|
51
|
-
setViewMode,
|
|
52
|
-
setUsername,
|
|
53
|
-
setSessionPubKey,
|
|
54
|
-
setSignMessageWithSessionKey,
|
|
55
|
-
setIsConnected,
|
|
56
|
-
setWalletPubKey,
|
|
57
|
-
setStartClosingLogin,
|
|
58
|
-
startClosingLogin,
|
|
59
|
-
setLoading,
|
|
60
|
-
setAddress,
|
|
61
|
-
dynamicWallet,
|
|
62
|
-
dynamicSdkHasLoaded,
|
|
63
|
-
darkMode,
|
|
64
|
-
handleError,
|
|
65
|
-
showSidebar,
|
|
66
|
-
} = useN1WalletInternalContext();
|
|
67
|
-
|
|
68
|
-
const [showLoginAnimation, setShowLoginAnimation] = useState(false);
|
|
69
|
-
|
|
70
|
-
// Handle loading state
|
|
71
|
-
useEffect(() => {
|
|
72
|
-
if (dynamicSdkHasLoaded || dynamicWallet) {
|
|
73
|
-
setLoading(false);
|
|
74
|
-
}
|
|
75
|
-
}, [dynamicSdkHasLoaded, dynamicWallet]);
|
|
76
|
-
|
|
77
|
-
// Initialize session when wallet is connected
|
|
78
|
-
useEffect(() => {
|
|
79
|
-
logger.debug('N1WalletModal attempt to call initializeSession...');
|
|
80
|
-
|
|
81
|
-
const initializeSession = async () => {
|
|
82
|
-
// If wallet is not connected, or not in connect mode, skip
|
|
83
|
-
if (!dynamicWallet || viewMode !== N1ModalViewMode.Connect) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Wallet is connected or we're in connect mode
|
|
88
|
-
// TODO: make this clearer/ more organized
|
|
89
|
-
try {
|
|
90
|
-
logger.debug('Initialize Session...');
|
|
91
|
-
|
|
92
|
-
if (dynamicWallet) {
|
|
93
|
-
// Check whitelist status first
|
|
94
|
-
const response = await fetch(
|
|
95
|
-
'https://argus-1g4n.onrender.com/api/db/verifyWhitelist',
|
|
96
|
-
{
|
|
97
|
-
method: 'POST',
|
|
98
|
-
headers: {
|
|
99
|
-
'Content-Type': 'application/json',
|
|
100
|
-
},
|
|
101
|
-
body: JSON.stringify({ address: dynamicWallet.address }),
|
|
102
|
-
}
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
const whitelistData = await response.json();
|
|
106
|
-
|
|
107
|
-
if (!whitelistData.isWhitelisted) {
|
|
108
|
-
logger.info('Wallet not whitelisted');
|
|
109
|
-
setViewMode(N1ModalViewMode.NoWhitelist);
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
logger.group('Session Initialization');
|
|
115
|
-
console.log('Session Initialization started');
|
|
116
|
-
try {
|
|
117
|
-
// Get wallet public key
|
|
118
|
-
const walletPubKey =
|
|
119
|
-
dynamicWallet.chain === 'SOL'
|
|
120
|
-
? bs58Decode(dynamicWallet.address)
|
|
121
|
-
: Uint8Array.from(
|
|
122
|
-
Buffer.from(dynamicWallet.address.slice(2), 'hex')
|
|
123
|
-
);
|
|
124
|
-
setWalletPubKey(walletPubKey);
|
|
125
|
-
|
|
126
|
-
// Check for existing session
|
|
127
|
-
const sessionData = getSessionKeysFromLocalStorage(
|
|
128
|
-
dynamicWallet.address
|
|
129
|
-
);
|
|
130
|
-
if (!sessionData) {
|
|
131
|
-
logger.info(
|
|
132
|
-
'No existing session found, transitioning to CreateSession'
|
|
133
|
-
);
|
|
134
|
-
setViewMode(N1ModalViewMode.CreateSession);
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
logger.debug('Session time', sessionData.createdAt);
|
|
138
|
-
logger.debug(
|
|
139
|
-
'Session time',
|
|
140
|
-
new Date(sessionData.createdAt).getTime()
|
|
141
|
-
);
|
|
142
|
-
logger.debug('Current time', Date.now());
|
|
143
|
-
if (
|
|
144
|
-
new Date(sessionData.createdAt).getTime() <
|
|
145
|
-
Date.now() - 1000 * 60 * 60 * 24 * 30
|
|
146
|
-
) {
|
|
147
|
-
logger.info('Session expired');
|
|
148
|
-
// TODO: create a welcome back view + allow them to logout
|
|
149
|
-
// Since we know the wallet already, we only need a new session key
|
|
150
|
-
setViewMode(N1ModalViewMode.CreateSession);
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// Initialize session with existing keys
|
|
155
|
-
const sessionPubKey = await getEd25519PublicKey(
|
|
156
|
-
sessionData.ed25519PrivateKey
|
|
157
|
-
);
|
|
158
|
-
logger.debug('Initializing with existing session key');
|
|
159
|
-
setSessionPubKey(sessionPubKey);
|
|
160
|
-
|
|
161
|
-
const signFn = async (message: Uint8Array) => {
|
|
162
|
-
console.log('zhoooooo');
|
|
163
|
-
console.log('signFn called', {
|
|
164
|
-
message,
|
|
165
|
-
stack: new Error().stack, // This will show the call stack
|
|
166
|
-
});
|
|
167
|
-
return await signEd25519(message, sessionData.ed25519PrivateKey);
|
|
168
|
-
};
|
|
169
|
-
console.log('zeeeeebrta');
|
|
170
|
-
setSignMessageWithSessionKey(() => signFn);
|
|
171
|
-
setAddress(dynamicWallet.address);
|
|
172
|
-
|
|
173
|
-
// Create web session and get user data
|
|
174
|
-
await createWebSession(signFn, sessionPubKey, walletPubKey);
|
|
175
|
-
const user = await getUser();
|
|
176
|
-
const storedUsername = localStorage.getItem(
|
|
177
|
-
`n1_${dynamicWallet.address}_username`
|
|
178
|
-
);
|
|
179
|
-
|
|
180
|
-
if (user?.name || storedUsername) {
|
|
181
|
-
logger.info('User found, completing login');
|
|
182
|
-
const username = user?.name || storedUsername;
|
|
183
|
-
setIsConnected(true);
|
|
184
|
-
setUsername(username!);
|
|
185
|
-
localStorage.setItem(
|
|
186
|
-
`n1_${dynamicWallet.address}_username`,
|
|
187
|
-
username!
|
|
188
|
-
);
|
|
189
|
-
setStartClosingLogin(true);
|
|
190
|
-
} else {
|
|
191
|
-
logger.info('No user found, transitioning to CreateUser');
|
|
192
|
-
setViewMode(N1ModalViewMode.CreatingUser);
|
|
193
|
-
}
|
|
194
|
-
} catch (error) {
|
|
195
|
-
logger.error('Session initialization failed:', error);
|
|
196
|
-
handleError(
|
|
197
|
-
new WalletError(
|
|
198
|
-
WalletErrorCode.CONNECTION_FAILED,
|
|
199
|
-
'Failed to initialize session',
|
|
200
|
-
{ originalError: error }
|
|
201
|
-
)
|
|
202
|
-
);
|
|
203
|
-
} finally {
|
|
204
|
-
logger.groupEnd();
|
|
205
|
-
}
|
|
206
|
-
} catch (error) {
|
|
207
|
-
logger.error('Whitelist check failed:', error);
|
|
208
|
-
handleError(
|
|
209
|
-
new WalletError(
|
|
210
|
-
WalletErrorCode.CONNECTION_FAILED,
|
|
211
|
-
'Failed to check whitelist',
|
|
212
|
-
{ originalError: error }
|
|
213
|
-
)
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
initializeSession();
|
|
219
|
-
}, [dynamicWallet, dynamicSdkHasLoaded, viewMode]);
|
|
220
|
-
|
|
221
|
-
// Handle modal visibility
|
|
222
|
-
useEffect(() => {
|
|
223
|
-
if (showLogin) {
|
|
224
|
-
setStartClosingLogin(false);
|
|
225
|
-
setShowLoginAnimation(true);
|
|
226
|
-
}
|
|
227
|
-
}, [showLogin]);
|
|
228
|
-
|
|
229
|
-
useEffect(() => {
|
|
230
|
-
if (startClosingLogin) {
|
|
231
|
-
setShowLoginAnimation(false);
|
|
232
|
-
const timeout = setTimeout(() => {
|
|
233
|
-
setShowLogin(false);
|
|
234
|
-
setStartClosingLogin(false);
|
|
235
|
-
}, 700);
|
|
236
|
-
return () => clearTimeout(timeout);
|
|
237
|
-
}
|
|
238
|
-
}, [startClosingLogin, setShowLogin, setStartClosingLogin]);
|
|
239
|
-
|
|
240
|
-
if (!showLogin && !showSidebar) return null;
|
|
241
|
-
|
|
242
|
-
console.log('SHOW', showSidebar);
|
|
243
|
-
|
|
244
|
-
return (
|
|
245
|
-
<div className={darkMode ? 'dark' : ''}>
|
|
246
|
-
{showLogin && (
|
|
247
|
-
<div className="fixed inset-0 z-50 flex items-center justify-center">
|
|
248
|
-
<div
|
|
249
|
-
className={`duration-500 ease-in-out font-monument w-screen h-screen fixed top-0 left-0 flex items-center justify-center z-100 ${
|
|
250
|
-
showLoginAnimation ? 'opacity-100' : 'opacity-0'
|
|
251
|
-
}`}
|
|
252
|
-
style={{
|
|
253
|
-
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
|
254
|
-
backdropFilter: 'blur(4px)',
|
|
255
|
-
}}
|
|
256
|
-
>
|
|
257
|
-
<Suspense fallback={<LoadingFallback />}>
|
|
258
|
-
{viewMode === N1ModalViewMode.Connect && <ConnectView />}
|
|
259
|
-
{viewMode === N1ModalViewMode.CreateSession && (
|
|
260
|
-
<CreateSessionView />
|
|
261
|
-
)}
|
|
262
|
-
{viewMode === N1ModalViewMode.Signing && <SigningView />}
|
|
263
|
-
{viewMode === N1ModalViewMode.CreatingUser && <CreateUserView />}
|
|
264
|
-
{viewMode === N1ModalViewMode.Success && <SuccessView />}
|
|
265
|
-
{viewMode === N1ModalViewMode.NoWhitelist && <NoWhitelistView />}
|
|
266
|
-
</Suspense>
|
|
267
|
-
</div>
|
|
268
|
-
</div>
|
|
269
|
-
)}
|
|
270
|
-
<Suspense fallback={<LoadingFallback />}>
|
|
271
|
-
<N1Sidebar />
|
|
272
|
-
</Suspense>
|
|
273
|
-
</div>
|
|
274
|
-
);
|
|
275
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
useN1WalletInternalContext,
|
|
4
|
-
useN1WalletContext,
|
|
5
|
-
} from '../Provider/hooks';
|
|
6
|
-
import { N1ModalViewMode } from '../Provider/types';
|
|
7
|
-
import { ModalHeader } from './ModalHeader';
|
|
8
|
-
|
|
9
|
-
export function NoWhitelistView() {
|
|
10
|
-
const { setViewMode, dynamicHandleLogOut, setIsConnected } =
|
|
11
|
-
useN1WalletInternalContext();
|
|
12
|
-
const { address } = useN1WalletContext();
|
|
13
|
-
|
|
14
|
-
function disconnect() {
|
|
15
|
-
// TODO: create a util function for disconnecting and clearing local storage
|
|
16
|
-
dynamicHandleLogOut();
|
|
17
|
-
if (typeof window !== 'undefined') {
|
|
18
|
-
localStorage.clear();
|
|
19
|
-
if ('caches' in window) {
|
|
20
|
-
caches.keys().then(function (cacheNames) {
|
|
21
|
-
cacheNames.forEach(function (cacheName) {
|
|
22
|
-
caches.delete(cacheName);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
window.location.reload();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
setViewMode(N1ModalViewMode.Connect);
|
|
30
|
-
setIsConnected(false);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const addressText = address
|
|
34
|
-
? `${address.substring(0, 6)}...${address.slice(-4)}`
|
|
35
|
-
: '';
|
|
36
|
-
|
|
37
|
-
return (
|
|
38
|
-
<div className="rounded-[25px] shadow-lg w-96 p-5 bg-white dark:bg-neutral-900 text-neutral-900 dark:text-stone-200">
|
|
39
|
-
<ModalHeader />
|
|
40
|
-
<div className="mt-6 text-center">
|
|
41
|
-
<p className="text-lg mb-4">Sorry, your wallet is not whitelisted.</p>
|
|
42
|
-
<p className="text-sm text-neutral-500 dark:text-neutral-400 mb-6">
|
|
43
|
-
N1 is currently available only for our early developer access program.
|
|
44
|
-
Please reach out to us if you'd like to join.
|
|
45
|
-
</p>
|
|
46
|
-
<button
|
|
47
|
-
onClick={() => window.open('https://tally.so/r/wM8KRg', '_blank')}
|
|
48
|
-
className="w-full py-4 border rounded-[18px] cursor-pointer duration-300 hover:opacity-80 text-white bg-neutral-900 dark:bg-white dark:text-black mb-4"
|
|
49
|
-
>
|
|
50
|
-
Request Early Access
|
|
51
|
-
</button>
|
|
52
|
-
<button
|
|
53
|
-
onClick={disconnect}
|
|
54
|
-
className="w-full py-4 border rounded-[18px] cursor-pointer duration-300 hover:opacity-80 bg-red-50 dark:bg-red-900/20 text-red-600 dark:text-red-400 border-red-200 dark:border-red-800"
|
|
55
|
-
>
|
|
56
|
-
Disconnect {addressText}
|
|
57
|
-
</button>
|
|
58
|
-
</div>
|
|
59
|
-
</div>
|
|
60
|
-
);
|
|
61
|
-
}
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import BlockiesSvg from 'blockies-react-svg';
|
|
2
|
-
import { useEffect, useState } from 'react';
|
|
3
|
-
import { N1ModalViewMode } from '../../Provider/types';
|
|
4
|
-
import {
|
|
5
|
-
useN1WalletContext,
|
|
6
|
-
useN1WalletInternalContext,
|
|
7
|
-
} from '../../Provider/hooks';
|
|
8
|
-
|
|
9
|
-
export function N1Sidebar(_: any) {
|
|
10
|
-
const [closing, setClosing] = useState(false);
|
|
11
|
-
const { username, isConnected, address } = useN1WalletContext();
|
|
12
|
-
const {
|
|
13
|
-
setShowSidebar,
|
|
14
|
-
showSidebar,
|
|
15
|
-
setStartClosingLogin,
|
|
16
|
-
dynamicHandleLogOut,
|
|
17
|
-
} = useN1WalletInternalContext();
|
|
18
|
-
const addressText =
|
|
19
|
-
isConnected && address.substring(0, 9) + '...' + address.slice(-3);
|
|
20
|
-
|
|
21
|
-
const { setViewMode, setIsConnected } = useN1WalletInternalContext();
|
|
22
|
-
|
|
23
|
-
function disconnect() {
|
|
24
|
-
dynamicHandleLogOut();
|
|
25
|
-
setViewMode(N1ModalViewMode.Connect);
|
|
26
|
-
setIsConnected(false);
|
|
27
|
-
setClosing(true);
|
|
28
|
-
setStartClosingLogin(true);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
useEffect(() => {
|
|
32
|
-
if (showSidebar) {
|
|
33
|
-
setClosing(false);
|
|
34
|
-
}
|
|
35
|
-
}, [showSidebar]);
|
|
36
|
-
|
|
37
|
-
useEffect(() => {
|
|
38
|
-
let timeout: NodeJS.Timeout;
|
|
39
|
-
if (closing) {
|
|
40
|
-
timeout = setTimeout(() => {
|
|
41
|
-
setShowSidebar(false);
|
|
42
|
-
setClosing(false);
|
|
43
|
-
}, 700);
|
|
44
|
-
}
|
|
45
|
-
return () => clearTimeout(timeout);
|
|
46
|
-
}, [closing, setShowSidebar]);
|
|
47
|
-
|
|
48
|
-
return (
|
|
49
|
-
<div
|
|
50
|
-
className={
|
|
51
|
-
'fixed inset-0 bg-neutral-400/45 dark:bg-neutral-700/45 h-screen w-screen duration-500 ease-in-out z-[9999] flex items-center justify-end py-3 backdrop-blur-sm ' +
|
|
52
|
-
(!showSidebar && 'hidden pointer-events-none') +
|
|
53
|
-
(closing ? ' opacity-0' : ' opacity-100')
|
|
54
|
-
}
|
|
55
|
-
>
|
|
56
|
-
{showSidebar && (
|
|
57
|
-
<div
|
|
58
|
-
className={'w-screen h-screen fixed top-0 left-0'}
|
|
59
|
-
onClick={() => setClosing(true)}
|
|
60
|
-
/>
|
|
61
|
-
)}
|
|
62
|
-
{showSidebar && (
|
|
63
|
-
<div
|
|
64
|
-
className={
|
|
65
|
-
'relative h-full py-6 pl-6 pr-8 bg-white dark:bg-neutral-900 shadow-xl border-2 border-neutral-200 dark:border-neutral-700 rounded-l-2xl rounded-b-2xl rounded-t-2xl duration-500 ease-in-out overflow-hidden ' +
|
|
66
|
-
(closing ? 'translate-x-full' : 'translate-x-0')
|
|
67
|
-
}
|
|
68
|
-
>
|
|
69
|
-
<div className={'flex flex-col'}>
|
|
70
|
-
<div className="flex w-full mb-4">
|
|
71
|
-
<div className="w-16 h-16 bg-neutral-200 dark:bg-neutral-800 rounded-full flex items-center justify-center relative">
|
|
72
|
-
<div className="overflow-hidden rounded-full w-16 h-16">
|
|
73
|
-
<BlockiesSvg
|
|
74
|
-
address={address}
|
|
75
|
-
className="drop-shadow w-full h-full rounded-[20px]"
|
|
76
|
-
/>
|
|
77
|
-
</div>
|
|
78
|
-
</div>
|
|
79
|
-
<div className={'flex flex-col pl-3 py-2'}>
|
|
80
|
-
<div
|
|
81
|
-
className={
|
|
82
|
-
'font-extrabold text-neutral-900 dark:text-stone-200'
|
|
83
|
-
}
|
|
84
|
-
>
|
|
85
|
-
{username}
|
|
86
|
-
</div>
|
|
87
|
-
<div
|
|
88
|
-
className={
|
|
89
|
-
'font-extrabold text-neutral-400 dark:text-neutral-500'
|
|
90
|
-
}
|
|
91
|
-
>
|
|
92
|
-
{addressText}
|
|
93
|
-
</div>
|
|
94
|
-
</div>
|
|
95
|
-
</div>
|
|
96
|
-
|
|
97
|
-
{/* <div
|
|
98
|
-
className={
|
|
99
|
-
"mt-4 rounded-2xl flex flex-col items-center justify-center h-24 w-full p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 border-neutral-200 dark:border-neutral-700 border text-neutral-700 dark:text-neutral-300 cursor-pointer"
|
|
100
|
-
}
|
|
101
|
-
>
|
|
102
|
-
<div
|
|
103
|
-
className={"bg-orange-400 rounded-sm h-4 w-4 mb-2 rotate-45"}
|
|
104
|
-
></div>
|
|
105
|
-
<div className={"font-bold"}>Hub</div>
|
|
106
|
-
<div className={"text-xs"}>Go to N1 Hub</div>
|
|
107
|
-
</div> */}
|
|
108
|
-
{/* <div
|
|
109
|
-
className={
|
|
110
|
-
"mt-4 rounded-2xl flex flex-col items-center justify-center h-24 w-full p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 border-neutral-200 dark:border-neutral-700 border text-neutral-700 dark:text-neutral-300 cursor-pointer"
|
|
111
|
-
}
|
|
112
|
-
>
|
|
113
|
-
<div
|
|
114
|
-
className={"bg-blue-400 rounded-sm h-4 w-4 mb-2 rotate-45"}
|
|
115
|
-
></div>
|
|
116
|
-
<div className={"font-bold"}>Swap</div>
|
|
117
|
-
<div className={"text-xs"}>Go to N1 Hub</div>
|
|
118
|
-
</div> */}
|
|
119
|
-
|
|
120
|
-
<div
|
|
121
|
-
className={
|
|
122
|
-
'mt-4 rounded-2xl flex flex-col items-center justify-center h-24 w-full p-2 bg-red-50 dark:bg-red-900/20 hover:bg-red-100 dark:hover:bg-red-900/30 border-neutral-200 dark:border-neutral-700 border text-neutral-700 dark:text-neutral-300 cursor-pointer'
|
|
123
|
-
}
|
|
124
|
-
onClick={disconnect}
|
|
125
|
-
>
|
|
126
|
-
<div
|
|
127
|
-
className={'bg-red-400 rounded-sm h-4 w-4 mb-2 rotate-45'}
|
|
128
|
-
></div>
|
|
129
|
-
<div className={'font-bold'}>Disconnect</div>
|
|
130
|
-
<div className={'text-xs'}>Log out from the application</div>
|
|
131
|
-
</div>
|
|
132
|
-
|
|
133
|
-
<div
|
|
134
|
-
className={
|
|
135
|
-
'justify-center w-full flex text-xs mt-8 mb-6 items-center'
|
|
136
|
-
}
|
|
137
|
-
>
|
|
138
|
-
<div
|
|
139
|
-
className={'h-0.5 bg-neutral-300 dark:bg-neutral-700 w-16 mx-2'}
|
|
140
|
-
></div>
|
|
141
|
-
<div
|
|
142
|
-
className={'text-neutral-600 dark:text-neutral-400 font-bold'}
|
|
143
|
-
>
|
|
144
|
-
Other apps
|
|
145
|
-
</div>
|
|
146
|
-
<div
|
|
147
|
-
className={'h-0.5 bg-neutral-300 dark:bg-neutral-700 w-16 mx-2'}
|
|
148
|
-
></div>
|
|
149
|
-
</div>
|
|
150
|
-
<div className={'flex flex-col gap-y-2'}>
|
|
151
|
-
<div className="cursor-pointer flex flex-col flex-shrink-0 mr-6 w-full h-48 bg-neutral-900 dark:bg-black rounded-xl overflow-hidden relative">
|
|
152
|
-
<div
|
|
153
|
-
className={
|
|
154
|
-
'absolute flex flex-row items-center justify-between bottom-0 w-full bg-gradient-to-t px-5 py-3 from-neutral-900 dark:from-black'
|
|
155
|
-
}
|
|
156
|
-
>
|
|
157
|
-
<div className="flex flex-row gap-3 items-center">
|
|
158
|
-
<div className="w-10 h-10 relative rounded-lg overflow-hidden"></div>
|
|
159
|
-
<div className="flex flex-col leading-none">
|
|
160
|
-
<div className="text-white">Nos</div>
|
|
161
|
-
<div className="text-neutral-200">Perp Dex</div>
|
|
162
|
-
</div>
|
|
163
|
-
</div>
|
|
164
|
-
</div>
|
|
165
|
-
</div>
|
|
166
|
-
</div>
|
|
167
|
-
</div>
|
|
168
|
-
</div>
|
|
169
|
-
)}
|
|
170
|
-
</div>
|
|
171
|
-
);
|
|
172
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { ModalHeader } from './ModalHeader';
|
|
3
|
-
|
|
4
|
-
export function SigningView() {
|
|
5
|
-
return (
|
|
6
|
-
<div className="rounded-[25px] shadow-lg w-96 p-5 bg-white dark:bg-neutral-900 text-neutral-900 dark:text-stone-200">
|
|
7
|
-
{/* Header */}
|
|
8
|
-
<ModalHeader />
|
|
9
|
-
|
|
10
|
-
<div className="flex flex-col items-center justify-center">
|
|
11
|
-
<div className="animate-spin-slow w-16 h-16 border-4 rounded-full border-neutral-200 dark:border-neutral-700 border-t-neutral-900 dark:border-t-white" />
|
|
12
|
-
<p className="text-sm mb-4 mt-6 text-neutral-500 dark:text-neutral-400">
|
|
13
|
-
Please sign the message to authenticate
|
|
14
|
-
</p>
|
|
15
|
-
</div>
|
|
16
|
-
</div>
|
|
17
|
-
);
|
|
18
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { ModalHeader } from './ModalHeader';
|
|
3
|
-
import { useN1WalletInternalContext } from '../Provider/hooks';
|
|
4
|
-
|
|
5
|
-
export function SuccessView() {
|
|
6
|
-
const { setViewMode, setStartClosingLogin } = useN1WalletInternalContext();
|
|
7
|
-
const close = () => {
|
|
8
|
-
setStartClosingLogin(true);
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
return (
|
|
12
|
-
<div className="rounded-[25px] shadow-lg w-96 p-5 bg-white dark:bg-neutral-900 text-neutral-900 dark:text-stone-200">
|
|
13
|
-
<ModalHeader />
|
|
14
|
-
|
|
15
|
-
<div className={'rounded-[25px] overflow-hidden mb-4'}>
|
|
16
|
-
<img
|
|
17
|
-
src={
|
|
18
|
-
'https://cdn.midjourney.com/17b152e3-2c93-4d00-b4cc-860d787a4994/0_2.png'
|
|
19
|
-
}
|
|
20
|
-
className={'w-full'}
|
|
21
|
-
/>
|
|
22
|
-
</div>
|
|
23
|
-
|
|
24
|
-
<div className="my-2">
|
|
25
|
-
<div className="space-y-2">
|
|
26
|
-
<button
|
|
27
|
-
className="w-full py-4 border rounded-[18px] cursor-pointer duration-300 hover:opacity-80 text-white bg-neutral-900 dark:bg-white dark:text-neutral-900"
|
|
28
|
-
onClick={close}
|
|
29
|
-
>
|
|
30
|
-
Success! Continue
|
|
31
|
-
</button>
|
|
32
|
-
</div>
|
|
33
|
-
</div>
|
|
34
|
-
</div>
|
|
35
|
-
);
|
|
36
|
-
}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState, useRef } from 'react';
|
|
2
|
-
import { useN1WalletInternalContext } from './hooks';
|
|
3
|
-
import { logger } from '../utils/logger';
|
|
4
|
-
|
|
5
|
-
const getSettings = (darkMode: boolean) => ({
|
|
6
|
-
initialAuthenticationMode: 'connect-only',
|
|
7
|
-
environmentId: '9a47561c-6a0b-4a5b-ace1-12621c11cebd',
|
|
8
|
-
theme: {
|
|
9
|
-
mode: darkMode ? 'dark' : 'light',
|
|
10
|
-
},
|
|
11
|
-
events: {
|
|
12
|
-
onAuthSuccess: (args: any) => {
|
|
13
|
-
console.log('onAuthSuccess was called', args);
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
function DynamicContextConsumer({ children }: { children: any }) {
|
|
19
|
-
const {
|
|
20
|
-
setDynamicWallet,
|
|
21
|
-
setAddress,
|
|
22
|
-
setDynamicSdkHasLoaded,
|
|
23
|
-
setShowDynamicWidget,
|
|
24
|
-
darkMode,
|
|
25
|
-
setDynamicHandleLogOut,
|
|
26
|
-
} = useN1WalletInternalContext();
|
|
27
|
-
|
|
28
|
-
const [DynamicContext, setDynamicContext] = useState<any>(null);
|
|
29
|
-
const showAuthFlowRef = useRef<((show: boolean) => void) | null>(null);
|
|
30
|
-
|
|
31
|
-
useEffect(() => {
|
|
32
|
-
import('@dynamic-labs/sdk-react-core').then(({ useDynamicContext }) => {
|
|
33
|
-
setDynamicContext(() => useDynamicContext);
|
|
34
|
-
});
|
|
35
|
-
}, []);
|
|
36
|
-
|
|
37
|
-
// Set up a stable widget function that uses the ref
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
setShowDynamicWidget(() => (show: boolean) => {
|
|
40
|
-
if (showAuthFlowRef.current) {
|
|
41
|
-
showAuthFlowRef.current(show);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}, [setShowDynamicWidget]);
|
|
45
|
-
|
|
46
|
-
if (!DynamicContext) {
|
|
47
|
-
return <>{children}</>;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const DynamicComponent = () => {
|
|
51
|
-
const { primaryWallet, sdkHasLoaded, setShowAuthFlow, handleLogOut } =
|
|
52
|
-
DynamicContext();
|
|
53
|
-
|
|
54
|
-
// Store setShowAuthFlow in ref to avoid re-renders
|
|
55
|
-
useEffect(() => {
|
|
56
|
-
showAuthFlowRef.current = setShowAuthFlow;
|
|
57
|
-
}, [setShowAuthFlow]);
|
|
58
|
-
|
|
59
|
-
useEffect(() => {
|
|
60
|
-
if (primaryWallet?.address) {
|
|
61
|
-
logger.debug('Primary wallet found');
|
|
62
|
-
setDynamicWallet(primaryWallet);
|
|
63
|
-
setAddress(primaryWallet.address);
|
|
64
|
-
} else {
|
|
65
|
-
logger.debug('No primary wallet found');
|
|
66
|
-
setDynamicWallet(null);
|
|
67
|
-
setAddress('');
|
|
68
|
-
}
|
|
69
|
-
}, [primaryWallet]);
|
|
70
|
-
|
|
71
|
-
useEffect(() => {
|
|
72
|
-
if (sdkHasLoaded) {
|
|
73
|
-
setDynamicSdkHasLoaded(true);
|
|
74
|
-
}
|
|
75
|
-
}, [sdkHasLoaded]);
|
|
76
|
-
|
|
77
|
-
// Set the logout handler
|
|
78
|
-
useEffect(() => {
|
|
79
|
-
if (handleLogOut) {
|
|
80
|
-
setDynamicHandleLogOut(() => handleLogOut);
|
|
81
|
-
}
|
|
82
|
-
}, [handleLogOut]);
|
|
83
|
-
|
|
84
|
-
return <>{children}</>;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
return <DynamicComponent />;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function LazyInternal(props: { children: any }) {
|
|
91
|
-
const [Provider, setProvider] = useState<any>(null);
|
|
92
|
-
const [walletConnectors, setWalletConnectors] = useState<any[]>([]);
|
|
93
|
-
const { darkMode } = useN1WalletInternalContext();
|
|
94
|
-
|
|
95
|
-
useEffect(() => {
|
|
96
|
-
const loadDynamicDeps = async () => {
|
|
97
|
-
try {
|
|
98
|
-
const [
|
|
99
|
-
{ DynamicContextProvider },
|
|
100
|
-
{ EthereumWalletConnectors },
|
|
101
|
-
{ SolanaWalletConnectors },
|
|
102
|
-
] = await Promise.all([
|
|
103
|
-
import('@dynamic-labs/sdk-react-core'),
|
|
104
|
-
import('@dynamic-labs/ethereum'),
|
|
105
|
-
import('@dynamic-labs/solana'),
|
|
106
|
-
]);
|
|
107
|
-
|
|
108
|
-
setProvider(() => DynamicContextProvider);
|
|
109
|
-
setWalletConnectors([EthereumWalletConnectors, SolanaWalletConnectors]);
|
|
110
|
-
} catch (error) {
|
|
111
|
-
console.error('Failed to load Dynamic dependencies:', error);
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
loadDynamicDeps();
|
|
116
|
-
}, []);
|
|
117
|
-
|
|
118
|
-
if (!Provider || walletConnectors.length === 0) {
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const dynamicSettings = {
|
|
123
|
-
...getSettings(darkMode),
|
|
124
|
-
walletConnectors,
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
return (
|
|
128
|
-
<Provider settings={dynamicSettings}>
|
|
129
|
-
<DynamicContextConsumer>{props.children}</DynamicContextConsumer>
|
|
130
|
-
</Provider>
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export function LazyWalletProvider({ children }: any) {
|
|
135
|
-
return <LazyInternal>{children}</LazyInternal>;
|
|
136
|
-
}
|