@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
package/src/Modal/BackButton.tsx
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { useN1WalletInternalContext } from '../Provider/hooks';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { N1ModalViewMode } from '../Provider/types';
|
|
4
|
-
|
|
5
|
-
export function BackButton(props: { onClick?: () => void }) {
|
|
6
|
-
const { setViewMode, dynamicHandleLogOut } = useN1WalletInternalContext();
|
|
7
|
-
|
|
8
|
-
function back() {
|
|
9
|
-
// todo: disconnect
|
|
10
|
-
console.log('back');
|
|
11
|
-
dynamicHandleLogOut();
|
|
12
|
-
setViewMode(N1ModalViewMode.Connect);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return (
|
|
16
|
-
<button
|
|
17
|
-
className="w-full py-4 border rounded-[18px] cursor-pointer duration-300 hover:opacity-80 bg-neutral-100 dark:bg-neutral-800 text-neutral-500 dark:text-neutral-400 border-neutral-200 dark:border-neutral-700"
|
|
18
|
-
onClick={props.onClick || back}
|
|
19
|
-
>
|
|
20
|
-
Back
|
|
21
|
-
</button>
|
|
22
|
-
);
|
|
23
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { useN1WalletInternalContext } from '../Provider/hooks';
|
|
2
|
-
import { ModalHeader } from './ModalHeader';
|
|
3
|
-
import { WalletError, WalletErrorCode } from '../errors/types';
|
|
4
|
-
import { IoMdWallet } from 'react-icons/io';
|
|
5
|
-
import clsx from 'clsx';
|
|
6
|
-
|
|
7
|
-
export function ConnectView() {
|
|
8
|
-
const { showDynamicWidget, handleError } = useN1WalletInternalContext();
|
|
9
|
-
|
|
10
|
-
const handleConnect = async () => {
|
|
11
|
-
try {
|
|
12
|
-
if (!showDynamicWidget) {
|
|
13
|
-
handleError(
|
|
14
|
-
new WalletError(
|
|
15
|
-
WalletErrorCode.CONNECTION_FAILED,
|
|
16
|
-
'Wallet connection not ready',
|
|
17
|
-
{ reason: 'Dynamic SDK not initialized' }
|
|
18
|
-
)
|
|
19
|
-
);
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
showDynamicWidget(true);
|
|
23
|
-
} catch (error) {
|
|
24
|
-
if (error instanceof WalletError) {
|
|
25
|
-
handleError(error);
|
|
26
|
-
} else {
|
|
27
|
-
handleError(
|
|
28
|
-
new WalletError(
|
|
29
|
-
WalletErrorCode.CONNECTION_FAILED,
|
|
30
|
-
'Failed to connect to wallet',
|
|
31
|
-
{ originalError: error }
|
|
32
|
-
)
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
return (
|
|
39
|
-
<div className="rounded-[25px] shadow-lg w-96 p-5 bg-white dark:bg-neutral-900 dark:text-stone-200">
|
|
40
|
-
<ModalHeader />
|
|
41
|
-
<div className="my-2">
|
|
42
|
-
<div className="space-y-2">
|
|
43
|
-
<AnimatedArrowButton
|
|
44
|
-
onClick={handleConnect}
|
|
45
|
-
buttonClassName="w-full py-4 border rounded-[18px] text-white bg-neutral-900 dark:bg-white dark:text-black cursor-pointer hover:opacity-80 transition-all flex items-center justify-center group"
|
|
46
|
-
>
|
|
47
|
-
<IoMdWallet className="ml-4 mr-2 w-5 h-5" />
|
|
48
|
-
Continue with Wallet
|
|
49
|
-
</AnimatedArrowButton>
|
|
50
|
-
<button
|
|
51
|
-
className="w-full py-4 border rounded-[18px] bg-neutral-100 dark:bg-neutral-800 text-neutral-500 dark:text-neutral-400 border-neutral-200 dark:border-neutral-700 cursor-not-allowed"
|
|
52
|
-
disabled
|
|
53
|
-
>
|
|
54
|
-
Continue with Google (soon)
|
|
55
|
-
</button>
|
|
56
|
-
<button
|
|
57
|
-
className="w-full py-4 border rounded-[18px] bg-neutral-100 dark:bg-neutral-800 text-neutral-500 dark:text-neutral-400 border-neutral-200 dark:border-neutral-700 cursor-not-allowed"
|
|
58
|
-
disabled
|
|
59
|
-
>
|
|
60
|
-
Continue with Email (soon)
|
|
61
|
-
</button>
|
|
62
|
-
</div>
|
|
63
|
-
</div>
|
|
64
|
-
</div>
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function AnimatedArrowButton({
|
|
69
|
-
children,
|
|
70
|
-
onClick,
|
|
71
|
-
buttonClassName,
|
|
72
|
-
}: {
|
|
73
|
-
children: React.ReactNode;
|
|
74
|
-
onClick: () => void;
|
|
75
|
-
buttonClassName?: string;
|
|
76
|
-
}) {
|
|
77
|
-
return (
|
|
78
|
-
<button
|
|
79
|
-
className={clsx(buttonClassName, 'flex flex-row')}
|
|
80
|
-
onClick={onClick}
|
|
81
|
-
>
|
|
82
|
-
{children}
|
|
83
|
-
<span className="ml-4 opacity-0 transform translate-x-[-10px] transition-all duration-200 group-hover:opacity-100 group-hover:translate-x-0">
|
|
84
|
-
→
|
|
85
|
-
</span>
|
|
86
|
-
</button>
|
|
87
|
-
);
|
|
88
|
-
}
|
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
useN1WalletContext,
|
|
4
|
-
useN1WalletInternalContext,
|
|
5
|
-
} from '../Provider/hooks';
|
|
6
|
-
import { ModalHeader } from './ModalHeader';
|
|
7
|
-
import { N1ModalViewMode } from '../Provider/types';
|
|
8
|
-
import { BackButton } from './BackButton';
|
|
9
|
-
import {
|
|
10
|
-
createWebSession,
|
|
11
|
-
generateSessionKeyPair,
|
|
12
|
-
getUser,
|
|
13
|
-
storeSessionKeysInLocalStorage,
|
|
14
|
-
} from '../Logic/utils';
|
|
15
|
-
import { signEd25519 } from '@n1xyz/nts-sdk';
|
|
16
|
-
import { logger } from '../utils/logger';
|
|
17
|
-
import { WalletError, WalletErrorCode } from '../errors/types';
|
|
18
|
-
|
|
19
|
-
export function CreateSessionView() {
|
|
20
|
-
const [NTSComponents, setNTSComponents] = useState<any>(null);
|
|
21
|
-
const [keyPair, setKeyPair] = useState<{
|
|
22
|
-
publicKey: Uint8Array;
|
|
23
|
-
privateKey: Uint8Array;
|
|
24
|
-
} | null>(null);
|
|
25
|
-
|
|
26
|
-
const {
|
|
27
|
-
setViewMode,
|
|
28
|
-
setUsername,
|
|
29
|
-
setStartClosingLogin,
|
|
30
|
-
setIsConnected,
|
|
31
|
-
dynamicWallet,
|
|
32
|
-
handleError,
|
|
33
|
-
setSessionPubKey,
|
|
34
|
-
setSignMessageWithSessionKey,
|
|
35
|
-
dynamicHandleLogOut,
|
|
36
|
-
setDynamicWallet,
|
|
37
|
-
setAddress,
|
|
38
|
-
setSignMessageWithWalletKey,
|
|
39
|
-
} = useN1WalletInternalContext();
|
|
40
|
-
|
|
41
|
-
const { ntsInterface, walletPubKey, address } = useN1WalletContext();
|
|
42
|
-
|
|
43
|
-
// Initialize NTS SDK and generate key pair
|
|
44
|
-
useEffect(() => {
|
|
45
|
-
const loadNTSSDK = async () => {
|
|
46
|
-
try {
|
|
47
|
-
const { Transaction, AdminAction, CoreApps } = await import(
|
|
48
|
-
'@n1xyz/nts-sdk'
|
|
49
|
-
);
|
|
50
|
-
setNTSComponents({ Transaction, AdminAction, CoreApps });
|
|
51
|
-
const newKeyPair = await generateSessionKeyPair();
|
|
52
|
-
setKeyPair(newKeyPair);
|
|
53
|
-
} catch (error) {
|
|
54
|
-
handleError(
|
|
55
|
-
new WalletError(
|
|
56
|
-
WalletErrorCode.CONNECTION_FAILED,
|
|
57
|
-
'Failed to initialize NTS SDK',
|
|
58
|
-
{ originalError: error }
|
|
59
|
-
)
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
loadNTSSDK();
|
|
64
|
-
}, [handleError]);
|
|
65
|
-
|
|
66
|
-
const signWithWallet = async (msg: string): Promise<Uint8Array> => {
|
|
67
|
-
console.log('zooooooooooooooo', msg);
|
|
68
|
-
try {
|
|
69
|
-
if (!dynamicWallet) {
|
|
70
|
-
throw new WalletError(
|
|
71
|
-
WalletErrorCode.WALLET_NOT_FOUND,
|
|
72
|
-
'Wallet not found for signing'
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (dynamicWallet.chain === 'SOL') {
|
|
77
|
-
const signature = await dynamicWallet.signMessage(msg);
|
|
78
|
-
const binaryString = atob(signature);
|
|
79
|
-
const signatureUint8Array = new Uint8Array(binaryString.length);
|
|
80
|
-
for (let i = 0; i < binaryString.length; i++) {
|
|
81
|
-
signatureUint8Array[i] = binaryString.charCodeAt(i);
|
|
82
|
-
}
|
|
83
|
-
return signatureUint8Array;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const sig = (await dynamicWallet.signMessage(msg)) as string;
|
|
87
|
-
logger.debug('Wallet signature received', { signature: sig });
|
|
88
|
-
return Uint8Array.from(Buffer.from(sig.slice(2), 'hex'));
|
|
89
|
-
} catch (error) {
|
|
90
|
-
throw new WalletError(
|
|
91
|
-
WalletErrorCode.USER_REJECTED,
|
|
92
|
-
'Failed to sign message with wallet',
|
|
93
|
-
{ originalError: error }
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const handleSign = async () => {
|
|
99
|
-
logger.debug('handleSign');
|
|
100
|
-
|
|
101
|
-
if (!NTSComponents || !keyPair) {
|
|
102
|
-
logger.warn('Required components not initialized');
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
setViewMode(N1ModalViewMode.Signing);
|
|
107
|
-
|
|
108
|
-
try {
|
|
109
|
-
const sessionKeyHex = Buffer.from(keyPair.publicKey).toString('hex');
|
|
110
|
-
logger.debug('Generated session key', { sessionKey: sessionKeyHex });
|
|
111
|
-
|
|
112
|
-
// Create and sign transaction that registers the session key with Core
|
|
113
|
-
const transactionData = {
|
|
114
|
-
appId: NTSComponents.CoreApps.Admin,
|
|
115
|
-
action: NTSComponents.AdminAction.addSessionKey,
|
|
116
|
-
framework: 'ts',
|
|
117
|
-
data: [
|
|
118
|
-
{
|
|
119
|
-
sessionKey: sessionKeyHex,
|
|
120
|
-
appId: 'hub',
|
|
121
|
-
},
|
|
122
|
-
],
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
setSignMessageWithWalletKey(signWithWallet);
|
|
126
|
-
const tx = new NTSComponents.Transaction(transactionData, walletPubKey!);
|
|
127
|
-
await tx.signWithWalletFunction(signWithWallet);
|
|
128
|
-
try {
|
|
129
|
-
const txRes = await ntsInterface.sendTransaction(
|
|
130
|
-
tx,
|
|
131
|
-
tx.signature!,
|
|
132
|
-
walletPubKey
|
|
133
|
-
);
|
|
134
|
-
if (txRes.success) {
|
|
135
|
-
logger.debug('txRes', txRes);
|
|
136
|
-
} else {
|
|
137
|
-
logger.debug('txRes', txRes);
|
|
138
|
-
throw new WalletError(
|
|
139
|
-
WalletErrorCode.TRANSACTION_FAILED,
|
|
140
|
-
'Transaction failed'
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
} catch (_) {
|
|
144
|
-
throw new WalletError(
|
|
145
|
-
WalletErrorCode.TRANSACTION_FAILED,
|
|
146
|
-
'Transaction did not succeed'
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// Create session signing function
|
|
151
|
-
const signFn = async (message: Uint8Array) => {
|
|
152
|
-
try {
|
|
153
|
-
return await signEd25519(message, keyPair.privateKey as Uint8Array);
|
|
154
|
-
} catch (_) {
|
|
155
|
-
console.log('error', _);
|
|
156
|
-
throw _;
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
// Store session keys
|
|
161
|
-
logger.debug('Storing session keys');
|
|
162
|
-
storeSessionKeysInLocalStorage({
|
|
163
|
-
privKey: keyPair.privateKey as Uint8Array,
|
|
164
|
-
walletPublicKey: address,
|
|
165
|
-
chainName: dynamicWallet!.chain,
|
|
166
|
-
});
|
|
167
|
-
setSessionPubKey(keyPair.publicKey);
|
|
168
|
-
setSignMessageWithSessionKey(() => signFn);
|
|
169
|
-
|
|
170
|
-
// Initialize web session with Argus who verifies that the session is
|
|
171
|
-
// registered with Core, and if so, grants you access to its user metadata db
|
|
172
|
-
await createWebSession(signFn, keyPair.publicKey, walletPubKey);
|
|
173
|
-
|
|
174
|
-
// Check for existing user
|
|
175
|
-
// TODO: handle case for auth.users, currently user.name is a wallet_only_users namespacing
|
|
176
|
-
const user = await getUser();
|
|
177
|
-
if (user?.name) {
|
|
178
|
-
logger.info('Existing user found, completing login');
|
|
179
|
-
setUsername(user.name);
|
|
180
|
-
localStorage.setItem(`n1_${address}_username`, user.name);
|
|
181
|
-
setStartClosingLogin(true);
|
|
182
|
-
setIsConnected(true);
|
|
183
|
-
} else {
|
|
184
|
-
logger.info('No user found, transitioning to user creation');
|
|
185
|
-
setViewMode(N1ModalViewMode.CreatingUser);
|
|
186
|
-
}
|
|
187
|
-
} catch (error: any) {
|
|
188
|
-
logger.error('Session creation failed:', error);
|
|
189
|
-
if (error.name === 'WalletError') {
|
|
190
|
-
handleError(error);
|
|
191
|
-
} else {
|
|
192
|
-
handleError(
|
|
193
|
-
new WalletError(
|
|
194
|
-
WalletErrorCode.CONNECTION_FAILED,
|
|
195
|
-
'Failed to create session',
|
|
196
|
-
{ originalError: JSON.stringify(error) }
|
|
197
|
-
)
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
setViewMode(N1ModalViewMode.CreateSession);
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
return (
|
|
206
|
-
<div className="rounded-[25px] shadow-lg w-96 p-5 bg-white dark:bg-neutral-900 text-neutral-900 dark:text-stone-200">
|
|
207
|
-
<ModalHeader />
|
|
208
|
-
|
|
209
|
-
<div className="rounded-[25px] overflow-hidden mb-4">
|
|
210
|
-
<img
|
|
211
|
-
src="https://cdn.midjourney.com/17b152e3-2c93-4d00-b4cc-860d787a4994/0_2.png"
|
|
212
|
-
className="w-full"
|
|
213
|
-
alt="Session creation illustration"
|
|
214
|
-
/>
|
|
215
|
-
</div>
|
|
216
|
-
|
|
217
|
-
<div className="my-2">
|
|
218
|
-
<div className="space-y-2">
|
|
219
|
-
<button
|
|
220
|
-
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 disabled:opacity-50 disabled:cursor-not-allowed"
|
|
221
|
-
onClick={handleSign}
|
|
222
|
-
disabled={!NTSComponents || !keyPair}
|
|
223
|
-
>
|
|
224
|
-
Authenticate
|
|
225
|
-
</button>
|
|
226
|
-
<BackButton
|
|
227
|
-
onClick={() => {
|
|
228
|
-
logger.debug('BackButton clicked');
|
|
229
|
-
// Log out wallet
|
|
230
|
-
setDynamicWallet(null);
|
|
231
|
-
setAddress('');
|
|
232
|
-
dynamicHandleLogOut();
|
|
233
|
-
|
|
234
|
-
// Set view mode to connect
|
|
235
|
-
setViewMode(N1ModalViewMode.Connect);
|
|
236
|
-
}}
|
|
237
|
-
/>
|
|
238
|
-
</div>
|
|
239
|
-
</div>
|
|
240
|
-
</div>
|
|
241
|
-
);
|
|
242
|
-
}
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import BlockiesSvg from 'blockies-react-svg';
|
|
2
|
-
import { useState } from 'react';
|
|
3
|
-
import { getPseudoName } from '../Logic/getPseudoName';
|
|
4
|
-
import { createUser } from '../Logic/utils';
|
|
5
|
-
import {
|
|
6
|
-
useN1WalletContext,
|
|
7
|
-
useN1WalletInternalContext,
|
|
8
|
-
} from '../Provider/hooks';
|
|
9
|
-
import { N1ModalViewMode } from '../Provider/types';
|
|
10
|
-
import { WalletError, WalletErrorCode } from '../errors/types';
|
|
11
|
-
import { logger } from '../utils/logger';
|
|
12
|
-
import { ModalHeader } from './ModalHeader';
|
|
13
|
-
|
|
14
|
-
export function CreateUserView() {
|
|
15
|
-
const {
|
|
16
|
-
setViewMode,
|
|
17
|
-
setIsConnected,
|
|
18
|
-
setUsername,
|
|
19
|
-
setStartClosingLogin,
|
|
20
|
-
handleError,
|
|
21
|
-
} = useN1WalletInternalContext();
|
|
22
|
-
const { address } = useN1WalletContext();
|
|
23
|
-
|
|
24
|
-
const close = () => {
|
|
25
|
-
setStartClosingLogin(true);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const [usernameLocal, setUsernameLocalLocal] = useState(
|
|
29
|
-
getPseudoName(address)
|
|
30
|
-
);
|
|
31
|
-
const [error, setError] = useState('');
|
|
32
|
-
|
|
33
|
-
// TODO: not sure what this is for??? so i commented it out for now
|
|
34
|
-
// useEffect(() => {
|
|
35
|
-
// const initializeSession = async () => {
|
|
36
|
-
// try {
|
|
37
|
-
// logger.debug("Initializing session");
|
|
38
|
-
// logger.debug("signMessageWithSessionKey", signMessageWithSessionKey);
|
|
39
|
-
// logger.debug("sessionPubKey", sessionPubKey);
|
|
40
|
-
// logger.debug("walletPubKey", walletPubKey);
|
|
41
|
-
// // Silently return if session keys are not available yet
|
|
42
|
-
// if (!signMessageWithSessionKey || !sessionPubKey || !walletPubKey) {
|
|
43
|
-
// return;
|
|
44
|
-
// }
|
|
45
|
-
|
|
46
|
-
// await createWebSession(
|
|
47
|
-
// signMessageWithSessionKey,
|
|
48
|
-
// sessionPubKey,
|
|
49
|
-
// walletPubKey
|
|
50
|
-
// );
|
|
51
|
-
|
|
52
|
-
// const user = await getUser();
|
|
53
|
-
// if (user) {
|
|
54
|
-
// const usernameDb = user.name;
|
|
55
|
-
// setIsConnected(true);
|
|
56
|
-
// setUsername(usernameDb);
|
|
57
|
-
// localStorage.setItem("n1_" + address + "_username", usernameDb);
|
|
58
|
-
// }
|
|
59
|
-
// } catch (error) {
|
|
60
|
-
// if (error instanceof WalletError) {
|
|
61
|
-
// handleError(error);
|
|
62
|
-
// } else {
|
|
63
|
-
// handleError(
|
|
64
|
-
// new WalletError(
|
|
65
|
-
// WalletErrorCode.UNKNOWN,
|
|
66
|
-
// "Failed to initialize user session",
|
|
67
|
-
// { originalError: error }
|
|
68
|
-
// )
|
|
69
|
-
// );
|
|
70
|
-
// }
|
|
71
|
-
// }
|
|
72
|
-
// };
|
|
73
|
-
|
|
74
|
-
// initializeSession();
|
|
75
|
-
// }, [
|
|
76
|
-
// signMessageWithSessionKey,
|
|
77
|
-
// sessionPubKey,
|
|
78
|
-
// walletPubKey,
|
|
79
|
-
// address,
|
|
80
|
-
// setIsConnected,
|
|
81
|
-
// setUsername,
|
|
82
|
-
// setViewMode,
|
|
83
|
-
// handleError,
|
|
84
|
-
// ]);
|
|
85
|
-
|
|
86
|
-
function validateUsername() {
|
|
87
|
-
if (!usernameLocal) {
|
|
88
|
-
setError('Username cannot be blank.');
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
if (!/^[a-zA-Z0-9-]+$/.test(usernameLocal)) {
|
|
92
|
-
setError('Username must be alphanumeric.');
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
setError('');
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
async function handleCreate() {
|
|
100
|
-
logger.debug('Creating User');
|
|
101
|
-
|
|
102
|
-
try {
|
|
103
|
-
// TODO: why is this here?
|
|
104
|
-
// await createWebSession(
|
|
105
|
-
// signMessageWithSessionKey,
|
|
106
|
-
// sessionPubKey,
|
|
107
|
-
// walletPubKey
|
|
108
|
-
// );
|
|
109
|
-
|
|
110
|
-
if (!validateUsername()) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
await createUser(usernameLocal);
|
|
115
|
-
setViewMode(N1ModalViewMode.Success);
|
|
116
|
-
setIsConnected(true);
|
|
117
|
-
setUsername(usernameLocal);
|
|
118
|
-
localStorage.setItem('n1_' + address + '_username', usernameLocal);
|
|
119
|
-
} catch (error) {
|
|
120
|
-
if (error instanceof WalletError) {
|
|
121
|
-
handleError(error);
|
|
122
|
-
} else {
|
|
123
|
-
handleError(
|
|
124
|
-
new WalletError(WalletErrorCode.UNKNOWN, 'Failed to create user', {
|
|
125
|
-
originalError: error,
|
|
126
|
-
})
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return (
|
|
133
|
-
<div className="rounded-[25px] shadow-lg p-5 m-4 bg-white dark:bg-neutral-900 text-neutral-900 dark:text-stone-200">
|
|
134
|
-
<ModalHeader />
|
|
135
|
-
<div className="flex flex-col items-center justify-center">
|
|
136
|
-
<div className="flex mb-2 justify-center sm:justify-between w-full flex-wrap max-w-screen">
|
|
137
|
-
<div className="flex flex-col">
|
|
138
|
-
<div className="w-80 h-80 sm:w-48 sm:h-48 rounded-[25px] flex items-center justify-center relative bg-neutral-100 dark:bg-neutral-800">
|
|
139
|
-
<div className="overflow-hidden rounded-lg w-80 h-80 sm:w-48 sm:h-48 p-2">
|
|
140
|
-
<BlockiesSvg
|
|
141
|
-
address={address}
|
|
142
|
-
className="drop-shadow w-full h-full rounded-[20px]"
|
|
143
|
-
/>
|
|
144
|
-
</div>
|
|
145
|
-
</div>
|
|
146
|
-
<div className="my-4 w-80 sm:w-48 p-2 border rounded-[15px] text-sm duration-300 bg-neutral-100 dark:bg-neutral-800 text-neutral-500 dark:text-neutral-400 border-neutral-200 dark:border-neutral-700">
|
|
147
|
-
You are creating an account that you can use across all N1.
|
|
148
|
-
</div>
|
|
149
|
-
</div>
|
|
150
|
-
|
|
151
|
-
{/* Username Input */}
|
|
152
|
-
<div className="w-80 flex flex-col items-center sm:items-end justify-between h-full my-2">
|
|
153
|
-
<div className="flex flex-col relative bg-neutral-100 dark:bg-neutral-800 border-neutral-200 dark:border-neutral-700 rounded-[15px] border w-72">
|
|
154
|
-
<input
|
|
155
|
-
type="text"
|
|
156
|
-
id="username"
|
|
157
|
-
placeholder="Enter your username"
|
|
158
|
-
value={usernameLocal}
|
|
159
|
-
onChange={(e) => setUsernameLocalLocal(e.target.value)}
|
|
160
|
-
className={`p-3 py-4 outline-none focus:ring focus:ring-orange-200 bg-neutral-100 dark:bg-neutral-800 text-neutral-900 dark:text-stone-200 rounded-[15px] border ${error ? 'border-red-500' : 'border-neutral-200 dark:border-neutral-700'}`}
|
|
161
|
-
/>
|
|
162
|
-
<div className="p-2 flex w-full justify-between text-xs text-neutral-500 dark:text-neutral-400">
|
|
163
|
-
<span className="font-bold">Username:</span> {usernameLocal}
|
|
164
|
-
</div>
|
|
165
|
-
<div className="px-2 pb-2 flex w-full justify-between text-xs text-neutral-500 dark:text-neutral-400">
|
|
166
|
-
<span className="font-bold">Wallet:</span>{' '}
|
|
167
|
-
{address.substring(0, 9) + '...' + address.slice(-3)}
|
|
168
|
-
</div>
|
|
169
|
-
</div>
|
|
170
|
-
{error && (
|
|
171
|
-
<div className="mt-2 w-72 p-2 text-red-600 bg-red-100 dark:bg-red-900/20 dark:text-red-400 border border-red-400 rounded-[15px] text-center">
|
|
172
|
-
{error}
|
|
173
|
-
</div>
|
|
174
|
-
)}
|
|
175
|
-
|
|
176
|
-
<button
|
|
177
|
-
className="my-4 w-72 py-4 border rounded-[15px] text-white bg-neutral-900 dark:bg-white dark:text-black cursor-pointer duration-300 hover:opacity-80"
|
|
178
|
-
onClick={handleCreate}
|
|
179
|
-
>
|
|
180
|
-
Create
|
|
181
|
-
</button>
|
|
182
|
-
<div className="w-72">
|
|
183
|
-
<button
|
|
184
|
-
className="w-full py-4 border rounded-[18px] cursor-pointer duration-300 hover:opacity-80 bg-neutral-100 dark:bg-neutral-800 text-neutral-500 dark:text-neutral-400 border-neutral-200 dark:border-neutral-700 hover:opacity-80"
|
|
185
|
-
onClick={close}
|
|
186
|
-
>
|
|
187
|
-
Close
|
|
188
|
-
</button>
|
|
189
|
-
</div>
|
|
190
|
-
</div>
|
|
191
|
-
</div>
|
|
192
|
-
</div>
|
|
193
|
-
</div>
|
|
194
|
-
);
|
|
195
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { useN1WalletInternalContext } from '../Provider/hooks';
|
|
3
|
-
|
|
4
|
-
export function ModalHeader() {
|
|
5
|
-
const { setStartClosingLogin } = useN1WalletInternalContext();
|
|
6
|
-
const close = () => {
|
|
7
|
-
setStartClosingLogin(true);
|
|
8
|
-
};
|
|
9
|
-
return (
|
|
10
|
-
<div className="flex items-center justify-between mb-4">
|
|
11
|
-
<div className="flex items-center gap-4">
|
|
12
|
-
<div className="w-10">
|
|
13
|
-
<svg
|
|
14
|
-
viewBox="0 0 236 125"
|
|
15
|
-
fill="none"
|
|
16
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
17
|
-
>
|
|
18
|
-
<g clipPath="url(#clip0_239_935)">
|
|
19
|
-
<path
|
|
20
|
-
d="M181.737 0H152.268V29.4694H181.737V0Z"
|
|
21
|
-
fill="currentColor"
|
|
22
|
-
/>
|
|
23
|
-
<path
|
|
24
|
-
d="M57.0683 0H29.4694L0 29.4694V124.674H29.4694V29.4694H44.8619L140.066 124.674H181.74L86.5377 29.4694L57.0683 0Z"
|
|
25
|
-
fill="currentColor"
|
|
26
|
-
/>
|
|
27
|
-
<path
|
|
28
|
-
d="M206.531 29.4694V124.674H236.001V0L206.531 29.4694Z"
|
|
29
|
-
fill="currentColor"
|
|
30
|
-
/>
|
|
31
|
-
</g>
|
|
32
|
-
<defs>
|
|
33
|
-
<clipPath id="clip0_239_935">
|
|
34
|
-
<rect width="236" height="124.674" fill="white" />
|
|
35
|
-
</clipPath>
|
|
36
|
-
</defs>
|
|
37
|
-
</svg>
|
|
38
|
-
</div>
|
|
39
|
-
<h2 className="text-lg text-neutral-900 dark:text-stone-200">
|
|
40
|
-
Sign in with N1
|
|
41
|
-
</h2>
|
|
42
|
-
</div>
|
|
43
|
-
<button
|
|
44
|
-
onClick={close}
|
|
45
|
-
className="text-neutral-400 hover:text-neutral-800 dark:text-neutral-500 dark:hover:text-neutral-300 cursor-pointer text-3xl rounded-full hover:bg-neutral-200 dark:hover:bg-neutral-700 h-10 w-10 p-1 flex items-center justify-center"
|
|
46
|
-
>
|
|
47
|
-
<svg
|
|
48
|
-
width="12"
|
|
49
|
-
height="12"
|
|
50
|
-
viewBox="0 0 14 14"
|
|
51
|
-
fill="none"
|
|
52
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
53
|
-
>
|
|
54
|
-
<path
|
|
55
|
-
d="M1 13L13 1M1 1L13 13"
|
|
56
|
-
stroke="currentColor"
|
|
57
|
-
strokeWidth="2"
|
|
58
|
-
strokeLinecap="round"
|
|
59
|
-
></path>
|
|
60
|
-
</svg>
|
|
61
|
-
</button>
|
|
62
|
-
</div>
|
|
63
|
-
);
|
|
64
|
-
}
|