signer-test-sdk-react 0.0.1
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 +114 -0
- package/dist/src/AbstraxnProvider.d.ts +20 -0
- package/dist/src/AbstraxnProvider.js +2213 -0
- package/dist/src/AbstraxnProvider.js.map +1 -0
- package/dist/src/ConnectButton.css +217 -0
- package/dist/src/ConnectButton.d.ts +71 -0
- package/dist/src/ConnectButton.js +102 -0
- package/dist/src/ConnectButton.js.map +1 -0
- package/dist/src/ExternalWalletButtons.css +319 -0
- package/dist/src/ExternalWalletButtons.d.ts +56 -0
- package/dist/src/ExternalWalletButtons.js +245 -0
- package/dist/src/ExternalWalletButtons.js.map +1 -0
- package/dist/src/OnboardingUI.d.ts +63 -0
- package/dist/src/OnboardingUI.js +66 -0
- package/dist/src/OnboardingUI.js.map +1 -0
- package/dist/src/WalletModal.css +549 -0
- package/dist/src/WalletModal.d.ts +6 -0
- package/dist/src/WalletModal.js +89 -0
- package/dist/src/WalletModal.js.map +1 -0
- package/dist/src/components/OnboardingUI/OnboardingUI.css +727 -0
- package/dist/src/components/OnboardingUI/OnboardingUIReact.d.ts +15 -0
- package/dist/src/components/OnboardingUI/OnboardingUIReact.js +65 -0
- package/dist/src/components/OnboardingUI/OnboardingUIReact.js.map +1 -0
- package/dist/src/components/OnboardingUI/OnboardingUIWeb.d.ts +257 -0
- package/dist/src/components/OnboardingUI/OnboardingUIWeb.js +3454 -0
- package/dist/src/components/OnboardingUI/OnboardingUIWeb.js.map +1 -0
- package/dist/src/components/OnboardingUI/components/EmailForm.d.ts +16 -0
- package/dist/src/components/OnboardingUI/components/EmailForm.js +19 -0
- package/dist/src/components/OnboardingUI/components/EmailForm.js.map +1 -0
- package/dist/src/components/OnboardingUI/components/Modal.d.ts +15 -0
- package/dist/src/components/OnboardingUI/components/Modal.js +68 -0
- package/dist/src/components/OnboardingUI/components/Modal.js.map +1 -0
- package/dist/src/components/OnboardingUI/components/OtpForm.d.ts +19 -0
- package/dist/src/components/OnboardingUI/components/OtpForm.js +58 -0
- package/dist/src/components/OnboardingUI/components/OtpForm.js.map +1 -0
- package/dist/src/components/OnboardingUI/components/PasskeyButton.d.ts +14 -0
- package/dist/src/components/OnboardingUI/components/PasskeyButton.js +22 -0
- package/dist/src/components/OnboardingUI/components/PasskeyButton.js.map +1 -0
- package/dist/src/components/OnboardingUI/components/SocialButtons.d.ts +15 -0
- package/dist/src/components/OnboardingUI/components/SocialButtons.js +15 -0
- package/dist/src/components/OnboardingUI/components/SocialButtons.js.map +1 -0
- package/dist/src/components/OnboardingUI/components/index.d.ts +13 -0
- package/dist/src/components/OnboardingUI/components/index.js +9 -0
- package/dist/src/components/OnboardingUI/components/index.js.map +1 -0
- package/dist/src/components/OnboardingUI/hooks/index.d.ts +7 -0
- package/dist/src/components/OnboardingUI/hooks/index.js +6 -0
- package/dist/src/components/OnboardingUI/hooks/index.js.map +1 -0
- package/dist/src/components/OnboardingUI/hooks/useAuthMethods.d.ts +11 -0
- package/dist/src/components/OnboardingUI/hooks/useAuthMethods.js +146 -0
- package/dist/src/components/OnboardingUI/hooks/useAuthMethods.js.map +1 -0
- package/dist/src/components/OnboardingUI/hooks/useOnboarding.d.ts +21 -0
- package/dist/src/components/OnboardingUI/hooks/useOnboarding.js +135 -0
- package/dist/src/components/OnboardingUI/hooks/useOnboarding.js.map +1 -0
- package/dist/src/components/OnboardingUI/index.d.ts +12 -0
- package/dist/src/components/OnboardingUI/index.js +15 -0
- package/dist/src/components/OnboardingUI/index.js.map +1 -0
- package/dist/src/hooks.d.ts +204 -0
- package/dist/src/hooks.js +394 -0
- package/dist/src/hooks.js.map +1 -0
- package/dist/src/index.d.ts +14 -0
- package/dist/src/index.js +11 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/types.d.ts +181 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/wagmiConfig.d.ts +147 -0
- package/dist/src/wagmiConfig.js +81 -0
- package/dist/src/wagmiConfig.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useAuthMethods Hook
|
|
3
|
+
* Handles social authentication methods
|
|
4
|
+
*/
|
|
5
|
+
import { useState, useCallback } from 'react';
|
|
6
|
+
import { useAbstraxnWallet } from '../../../hooks';
|
|
7
|
+
export const useAuthMethods = (config) => {
|
|
8
|
+
const { wallet } = useAbstraxnWallet();
|
|
9
|
+
const [loading, setLoading] = useState(false);
|
|
10
|
+
const [activeMethod, setActiveMethod] = useState(null);
|
|
11
|
+
const handleGoogleLogin = useCallback(async () => {
|
|
12
|
+
if (!wallet) {
|
|
13
|
+
config?.onLoginError?.(new Error('Wallet not initialized'));
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
setLoading(true);
|
|
17
|
+
setActiveMethod('google');
|
|
18
|
+
try {
|
|
19
|
+
if (config?.onGoogleLogin) {
|
|
20
|
+
await config.onGoogleLogin();
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
await wallet.loginWithGoogle();
|
|
24
|
+
}
|
|
25
|
+
config?.onLoginSuccess?.({});
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
const error = err instanceof Error ? err : new Error('Failed to login with Google');
|
|
29
|
+
config?.onLoginError?.(error);
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
setLoading(false);
|
|
33
|
+
setActiveMethod(null);
|
|
34
|
+
}
|
|
35
|
+
}, [wallet, config]);
|
|
36
|
+
const handleTwitterLogin = useCallback(async () => {
|
|
37
|
+
if (!wallet) {
|
|
38
|
+
config?.onLoginError?.(new Error('Wallet not initialized'));
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
setLoading(true);
|
|
42
|
+
setActiveMethod('twitter');
|
|
43
|
+
try {
|
|
44
|
+
if (config?.onTwitterLogin) {
|
|
45
|
+
await config.onTwitterLogin();
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
await wallet.loginWithTwitter();
|
|
49
|
+
}
|
|
50
|
+
config?.onLoginSuccess?.({});
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
const error = err instanceof Error ? err : new Error('Failed to login with X (Twitter)');
|
|
54
|
+
config?.onLoginError?.(error);
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
setLoading(false);
|
|
58
|
+
setActiveMethod(null);
|
|
59
|
+
}
|
|
60
|
+
}, [wallet, config]);
|
|
61
|
+
const handleDiscordLogin = useCallback(async () => {
|
|
62
|
+
if (!wallet) {
|
|
63
|
+
config?.onLoginError?.(new Error('Wallet not initialized'));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
setLoading(true);
|
|
67
|
+
setActiveMethod('discord');
|
|
68
|
+
try {
|
|
69
|
+
if (config?.onDiscordLogin) {
|
|
70
|
+
await config.onDiscordLogin();
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
await wallet.loginWithDiscord();
|
|
74
|
+
}
|
|
75
|
+
config?.onLoginSuccess?.({});
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
const error = err instanceof Error ? err : new Error('Failed to login with Discord');
|
|
79
|
+
config?.onLoginError?.(error);
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
setLoading(false);
|
|
83
|
+
setActiveMethod(null);
|
|
84
|
+
}
|
|
85
|
+
}, [wallet, config]);
|
|
86
|
+
const handlePasskeyLogin = useCallback(async () => {
|
|
87
|
+
if (!wallet) {
|
|
88
|
+
config?.onLoginError?.(new Error('Wallet not initialized'));
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
setLoading(true);
|
|
92
|
+
setActiveMethod('passkey');
|
|
93
|
+
try {
|
|
94
|
+
if (config?.onPasskeyLogin) {
|
|
95
|
+
await config.onPasskeyLogin();
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
await wallet.loginWithPasskey();
|
|
99
|
+
}
|
|
100
|
+
config?.onLoginSuccess?.({});
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
const error = err instanceof Error ? err : new Error('Failed to login with passkey');
|
|
104
|
+
config?.onLoginError?.(error);
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
setLoading(false);
|
|
108
|
+
setActiveMethod(null);
|
|
109
|
+
}
|
|
110
|
+
}, [wallet, config]);
|
|
111
|
+
const handlePasskeySignup = useCallback(async () => {
|
|
112
|
+
if (!wallet) {
|
|
113
|
+
config?.onLoginError?.(new Error('Wallet not initialized'));
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
setLoading(true);
|
|
117
|
+
setActiveMethod('passkey');
|
|
118
|
+
try {
|
|
119
|
+
if (config?.onPasskeySignup) {
|
|
120
|
+
await config.onPasskeySignup();
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
await wallet.signupWithPasskey();
|
|
124
|
+
}
|
|
125
|
+
config?.onLoginSuccess?.({});
|
|
126
|
+
}
|
|
127
|
+
catch (err) {
|
|
128
|
+
const error = err instanceof Error ? err : new Error('Failed to signup with passkey');
|
|
129
|
+
config?.onLoginError?.(error);
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
setLoading(false);
|
|
133
|
+
setActiveMethod(null);
|
|
134
|
+
}
|
|
135
|
+
}, [wallet, config]);
|
|
136
|
+
return {
|
|
137
|
+
loading,
|
|
138
|
+
activeMethod,
|
|
139
|
+
handleGoogleLogin,
|
|
140
|
+
handleTwitterLogin,
|
|
141
|
+
handleDiscordLogin,
|
|
142
|
+
handlePasskeyLogin,
|
|
143
|
+
handlePasskeySignup,
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
//# sourceMappingURL=useAuthMethods.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAuthMethods.js","sourceRoot":"","sources":["../../../../../src/components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ErB,OAAO;QACL,OAAO;QACP,YAAY;QACZ,iBAAiB;QACjB,kBAAkB;QAClB,kBAAkB;QAClB,kBAAkB;QAClB,mBAAmB;KACpB,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { OnboardingUIConfig } from 'signer-test-sdk-core';
|
|
2
|
+
export type OnboardingStep = 'email' | 'otp' | 'loading' | 'error';
|
|
3
|
+
export interface UseOnboardingReturn {
|
|
4
|
+
step: OnboardingStep;
|
|
5
|
+
email: string;
|
|
6
|
+
otp: string;
|
|
7
|
+
otpId: string | null;
|
|
8
|
+
loading: boolean;
|
|
9
|
+
error: string | null;
|
|
10
|
+
resendCooldown: number;
|
|
11
|
+
setEmail: (email: string) => void;
|
|
12
|
+
setOtp: (otp: string) => void;
|
|
13
|
+
handleEmailSubmit: () => Promise<void>;
|
|
14
|
+
handleOtpSubmit: () => Promise<void>;
|
|
15
|
+
handleResendOtp: () => Promise<void>;
|
|
16
|
+
reset: () => void;
|
|
17
|
+
setError: (error: string | null) => void;
|
|
18
|
+
setLoading: (loading: boolean) => void;
|
|
19
|
+
setStep: (step: OnboardingStep) => void;
|
|
20
|
+
}
|
|
21
|
+
export declare const useOnboarding: (config?: Partial<OnboardingUIConfig>) => UseOnboardingReturn;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useOnboarding Hook
|
|
3
|
+
* Business logic for OnboardingUI component
|
|
4
|
+
*/
|
|
5
|
+
import { useState, useCallback } from 'react';
|
|
6
|
+
import { useAbstraxnWallet } from '../../../hooks';
|
|
7
|
+
export const useOnboarding = (config) => {
|
|
8
|
+
const { wallet } = useAbstraxnWallet();
|
|
9
|
+
const [step, setStep] = useState('email');
|
|
10
|
+
const [email, setEmail] = useState('');
|
|
11
|
+
const [otp, setOtp] = useState('');
|
|
12
|
+
const [otpId, setOtpId] = useState(null);
|
|
13
|
+
const [loading, setLoading] = useState(false);
|
|
14
|
+
const [error, setError] = useState(null);
|
|
15
|
+
const [resendCooldown, setResendCooldown] = useState(0);
|
|
16
|
+
const handleEmailSubmit = useCallback(async () => {
|
|
17
|
+
if (!wallet) {
|
|
18
|
+
setError('Wallet not initialized');
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (!email || !email.includes('@')) {
|
|
22
|
+
setError('Please enter a valid email address');
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
setLoading(true);
|
|
26
|
+
setError(null);
|
|
27
|
+
try {
|
|
28
|
+
// Call custom handler if provided
|
|
29
|
+
if (config?.onEmailOtpInitiate) {
|
|
30
|
+
await config.onEmailOtpInitiate(email);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
// Use wallet's built-in method
|
|
34
|
+
const result = await wallet.loginWithOTP(email);
|
|
35
|
+
setOtpId(result.otpId);
|
|
36
|
+
}
|
|
37
|
+
setStep('otp');
|
|
38
|
+
setResendCooldown(60); // 60 second cooldown
|
|
39
|
+
// Start countdown
|
|
40
|
+
const interval = setInterval(() => {
|
|
41
|
+
setResendCooldown((prev) => {
|
|
42
|
+
if (prev <= 1) {
|
|
43
|
+
clearInterval(interval);
|
|
44
|
+
return 0;
|
|
45
|
+
}
|
|
46
|
+
return prev - 1;
|
|
47
|
+
});
|
|
48
|
+
}, 1000);
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
const errorMessage = err instanceof Error ? err.message : 'Failed to send OTP';
|
|
52
|
+
setError(errorMessage);
|
|
53
|
+
config?.onLoginError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
setLoading(false);
|
|
57
|
+
}
|
|
58
|
+
}, [wallet, email, config]);
|
|
59
|
+
const handleOtpSubmit = useCallback(async () => {
|
|
60
|
+
if (!wallet) {
|
|
61
|
+
setError('Wallet not initialized');
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (!otp || otp.length !== 6) {
|
|
65
|
+
setError('Please enter a valid 6-digit OTP');
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
setLoading(true);
|
|
69
|
+
setError(null);
|
|
70
|
+
try {
|
|
71
|
+
// Call custom handler if provided
|
|
72
|
+
if (config?.onEmailOtpVerify) {
|
|
73
|
+
const result = await config.onEmailOtpVerify(email, otp);
|
|
74
|
+
if (result.success) {
|
|
75
|
+
setStep('loading');
|
|
76
|
+
config?.onLoginSuccess?.({ token: result.token });
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
throw new Error('OTP verification failed');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
// Use wallet's built-in method
|
|
84
|
+
if (!otpId) {
|
|
85
|
+
throw new Error('OTP ID not found. Please initiate OTP first.');
|
|
86
|
+
}
|
|
87
|
+
await wallet.verifyOTP(otpId, otp);
|
|
88
|
+
setOtpId(null);
|
|
89
|
+
setStep('loading');
|
|
90
|
+
config?.onLoginSuccess?.({});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
const errorMessage = err instanceof Error ? err.message : 'Failed to verify OTP';
|
|
95
|
+
setError(errorMessage);
|
|
96
|
+
config?.onLoginError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
setLoading(false);
|
|
100
|
+
}
|
|
101
|
+
}, [wallet, email, otp, otpId, config]);
|
|
102
|
+
const handleResendOtp = useCallback(async () => {
|
|
103
|
+
if (resendCooldown > 0)
|
|
104
|
+
return;
|
|
105
|
+
await handleEmailSubmit();
|
|
106
|
+
}, [resendCooldown, handleEmailSubmit]);
|
|
107
|
+
const reset = useCallback(() => {
|
|
108
|
+
setStep('email');
|
|
109
|
+
setEmail('');
|
|
110
|
+
setOtp('');
|
|
111
|
+
setOtpId(null);
|
|
112
|
+
setError(null);
|
|
113
|
+
setLoading(false);
|
|
114
|
+
setResendCooldown(0);
|
|
115
|
+
}, []);
|
|
116
|
+
return {
|
|
117
|
+
step,
|
|
118
|
+
email,
|
|
119
|
+
otp,
|
|
120
|
+
otpId,
|
|
121
|
+
loading,
|
|
122
|
+
error,
|
|
123
|
+
resendCooldown,
|
|
124
|
+
setEmail,
|
|
125
|
+
setOtp,
|
|
126
|
+
handleEmailSubmit,
|
|
127
|
+
handleOtpSubmit,
|
|
128
|
+
handleResendOtp,
|
|
129
|
+
reset,
|
|
130
|
+
setError,
|
|
131
|
+
setLoading,
|
|
132
|
+
setStep,
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
//# sourceMappingURL=useOnboarding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOnboarding.js","sourceRoot":"","sources":["../../../../../src/components/OnboardingUI/hooks/useOnboarding.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAwBnD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,MAAoC,EAAuB,EAAE;IACzF,MAAM,EAAE,MAAM,EAAE,GAAG,iBAAiB,EAAE,CAAC;IACvC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAiB,OAAO,CAAC,CAAC;IAC1D,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;IACvC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;IACnC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAgB,IAAI,CAAC,CAAC;IACxD,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAg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AC;QACf,QAAQ,CAAC,IAAI,CAAC,CAAC;QACf,UAAU,CAAC,KAAK,CAAC,CAAC;QAClB,iBAAiB,CAAC,CAAC,CAAC,CAAC;IACvB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACL,IAAI;QACJ,KAAK;QACL,GAAG;QACH,KAAK;QACL,OAAO;QACP,KAAK;QACL,cAAc;QACd,QAAQ;QACR,MAAM;QACN,iBAAiB;QACjB,eAAe;QACf,eAAe;QACf,KAAK;QACL,QAAQ;QACR,UAAU;QACV,OAAO;KACR,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OnboardingUI Exports
|
|
3
|
+
*
|
|
4
|
+
* This file exports both the new React implementation and the legacy vanilla JS class
|
|
5
|
+
* for backward compatibility during migration.
|
|
6
|
+
*/
|
|
7
|
+
export { OnboardingUIReact } from './OnboardingUIReact';
|
|
8
|
+
export type { OnboardingUIReactProps } from './OnboardingUIReact';
|
|
9
|
+
export { OnboardingUIWeb } from './OnboardingUIWeb';
|
|
10
|
+
export type { OnboardingUIConfig, Theme } from 'signer-test-sdk-core';
|
|
11
|
+
export * from './components';
|
|
12
|
+
export * from './hooks';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OnboardingUI Exports
|
|
3
|
+
*
|
|
4
|
+
* This file exports both the new React implementation and the legacy vanilla JS class
|
|
5
|
+
* for backward compatibility during migration.
|
|
6
|
+
*/
|
|
7
|
+
// New Pure React implementation (recommended)
|
|
8
|
+
export { OnboardingUIReact } from './OnboardingUIReact';
|
|
9
|
+
// Legacy vanilla JS class (deprecated, will be removed in future version)
|
|
10
|
+
export { OnboardingUIWeb } from './OnboardingUIWeb';
|
|
11
|
+
// Component exports
|
|
12
|
+
export * from './components';
|
|
13
|
+
// Hook exports
|
|
14
|
+
export * from './hooks';
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/OnboardingUI/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,8CAA8C;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxD,0EAA0E;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,oBAAoB;AACpB,cAAc,cAAc,CAAC;AAE7B,eAAe;AACf,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import type { WhoamiResponse, TransactionRequest, TransactionResponse, AbstraxnWallet } from 'signer-test-sdk-core';
|
|
2
|
+
/**
|
|
3
|
+
* Hook to check if wallet is connected
|
|
4
|
+
*/
|
|
5
|
+
export declare function useIsConnected(): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Hook to get wallet address
|
|
8
|
+
*/
|
|
9
|
+
export declare function useAddress(): string | null;
|
|
10
|
+
/**
|
|
11
|
+
* Hook to get current user and whoami information
|
|
12
|
+
* Returns an object with both user and whoami data
|
|
13
|
+
*/
|
|
14
|
+
export declare function useUser(): {
|
|
15
|
+
user: import("signer-test-sdk-core").User | null;
|
|
16
|
+
whoami: WhoamiResponse | null;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Hook to get current chain ID
|
|
20
|
+
*/
|
|
21
|
+
export declare function useChainId(): number | null;
|
|
22
|
+
/**
|
|
23
|
+
* Hook to check if wallet is initialized
|
|
24
|
+
*/
|
|
25
|
+
export declare function useIsInitialized(): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Hook to get loading state
|
|
28
|
+
*/
|
|
29
|
+
export declare function useLoading(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Hook to get error state
|
|
32
|
+
*/
|
|
33
|
+
export declare function useError(): Error | null;
|
|
34
|
+
export { useAbstraxnWallet } from './AbstraxnProvider';
|
|
35
|
+
/**
|
|
36
|
+
* Hook to get wallet instance (for advanced usage)
|
|
37
|
+
*/
|
|
38
|
+
export declare function useWallet(): AbstraxnWallet | null;
|
|
39
|
+
/**
|
|
40
|
+
* Hook to prepare and sign transaction
|
|
41
|
+
* Prepares the unsigned transaction, calls the sign API, and returns the signed transaction
|
|
42
|
+
* User can execute this signed transaction themselves
|
|
43
|
+
*/
|
|
44
|
+
export declare function usePrepareTransaction(): {
|
|
45
|
+
prepareTransaction: (to: string, value: string, rpcUrl: string, chainId: number) => Promise<{
|
|
46
|
+
unsignedTransaction: import("viem").TransactionSerializedLegacy;
|
|
47
|
+
signedTransaction: string;
|
|
48
|
+
}>;
|
|
49
|
+
isConnected: boolean;
|
|
50
|
+
address: string | null;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Hook to sign transaction via API
|
|
54
|
+
* Returns the signed transaction that user can execute themselves
|
|
55
|
+
*/
|
|
56
|
+
export declare function useSignTransaction(): {
|
|
57
|
+
signTransaction: (unsignedTransaction: string, fromAddress?: string) => Promise<{
|
|
58
|
+
signedTransaction: string;
|
|
59
|
+
}>;
|
|
60
|
+
isConnected: boolean;
|
|
61
|
+
address: string | null;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Hook to sign and send transaction
|
|
65
|
+
* Signs transaction via API and then executes it internally
|
|
66
|
+
* Returns transaction hash
|
|
67
|
+
*/
|
|
68
|
+
export declare function useSignAndSendTransaction(): {
|
|
69
|
+
signAndSendTransaction: (unsignedTransaction: string, fromAddress?: string, rpcUrl?: string) => Promise<TransactionResponse>;
|
|
70
|
+
isConnected: boolean;
|
|
71
|
+
address: string | null;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Hook to export wallet private key
|
|
75
|
+
* Returns the export bundle containing the private key
|
|
76
|
+
* Automatically picks the connected wallet address (EVM or Solana) from whoami
|
|
77
|
+
*/
|
|
78
|
+
export declare function useExportWallet(): {
|
|
79
|
+
exportWallet: (targetPublicKey: string, privateKey: string, blockchain: "evm" | "solana") => Promise<any>;
|
|
80
|
+
isConnected: boolean;
|
|
81
|
+
address: string | null;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Hook to call whoami API
|
|
85
|
+
* Returns whoami data, loading state, error, and a refresh function
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```tsx
|
|
89
|
+
* const { whoami, loading, error, refreshWhoami } = useWhoami();
|
|
90
|
+
*
|
|
91
|
+
* useEffect(() => {
|
|
92
|
+
* refreshWhoami();
|
|
93
|
+
* }, []);
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export declare function useWhoami(): {
|
|
97
|
+
whoami: WhoamiResponse | null;
|
|
98
|
+
loading: boolean;
|
|
99
|
+
error: Error | null;
|
|
100
|
+
refreshWhoami: () => Promise<WhoamiResponse | null>;
|
|
101
|
+
isConnected: boolean;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Hook to access external wallet functionality
|
|
105
|
+
* Returns external wallet connection state and methods
|
|
106
|
+
*/
|
|
107
|
+
export declare function useExternalWallet(): {
|
|
108
|
+
connectExternalWallet: (connectorId: string) => Promise<void>;
|
|
109
|
+
disconnectExternalWallet: () => Promise<void>;
|
|
110
|
+
isExternalWalletConnected: boolean;
|
|
111
|
+
externalWalletAddress: string | null;
|
|
112
|
+
externalWalletChainId: number | null;
|
|
113
|
+
externalWalletBalance: bigint | null;
|
|
114
|
+
externalWalletNetwork: string | null;
|
|
115
|
+
availableConnectors: {
|
|
116
|
+
id: string;
|
|
117
|
+
name: string;
|
|
118
|
+
icon?: string;
|
|
119
|
+
}[];
|
|
120
|
+
switchExternalWalletChain: (chainId: number) => Promise<void>;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Hook to get external wallet balance
|
|
124
|
+
* Returns balance in wei (BigInt) and formatted balance
|
|
125
|
+
*/
|
|
126
|
+
export declare function useExternalWalletBalance(): {
|
|
127
|
+
balance: bigint | null;
|
|
128
|
+
formattedBalance: string;
|
|
129
|
+
address: string | null;
|
|
130
|
+
isConnected: boolean;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Hook to get external wallet chain information
|
|
134
|
+
* Returns chainId, network name, and switch chain function
|
|
135
|
+
*/
|
|
136
|
+
export declare function useExternalWalletChain(): {
|
|
137
|
+
chainId: number | null;
|
|
138
|
+
network: string | null;
|
|
139
|
+
switchChain: (chainId: number) => Promise<void>;
|
|
140
|
+
isConnected: boolean;
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Comprehensive hook for external wallet information
|
|
144
|
+
* Returns chainId, network, balance, switchChain function, connection status, and walletClient
|
|
145
|
+
* This is the main hook to use for external wallet operations
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```tsx
|
|
149
|
+
* const { chainId, network, balance, formattedBalance, switchChain, isConnected, address, walletClient } = useExternalWalletInfo();
|
|
150
|
+
*
|
|
151
|
+
* // Switch chain
|
|
152
|
+
* await switchChain(137); // Switch to Polygon
|
|
153
|
+
*
|
|
154
|
+
* // Send transaction using walletClient
|
|
155
|
+
* const txHash = await walletClient.sendTransaction({
|
|
156
|
+
* to: '0x...',
|
|
157
|
+
* value: '0.1',
|
|
158
|
+
* });
|
|
159
|
+
*
|
|
160
|
+
* // Sign message using walletClient
|
|
161
|
+
* const signature = await walletClient.signMessage('Hello World');
|
|
162
|
+
*
|
|
163
|
+
* // Display info
|
|
164
|
+
* <div>
|
|
165
|
+
* <p>Network: {network}</p>
|
|
166
|
+
* <p>Balance: {formattedBalance} ETH</p>
|
|
167
|
+
* </div>
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
export declare function useExternalWalletInfo(): {
|
|
171
|
+
chainId: number | null;
|
|
172
|
+
network: string | null;
|
|
173
|
+
balance: bigint | null;
|
|
174
|
+
formattedBalance: string;
|
|
175
|
+
switchChain: (chainId: number) => Promise<void>;
|
|
176
|
+
isConnected: boolean;
|
|
177
|
+
address: string | null;
|
|
178
|
+
walletClient: {
|
|
179
|
+
/**
|
|
180
|
+
* Send a transaction using external wallet
|
|
181
|
+
* @param tx - Transaction request object
|
|
182
|
+
* @returns Promise resolving to transaction response with hash
|
|
183
|
+
*/
|
|
184
|
+
sendTransaction: (tx: TransactionRequest) => Promise<TransactionResponse>;
|
|
185
|
+
/**
|
|
186
|
+
* Sign a message using external wallet
|
|
187
|
+
* @param message - Message string to sign
|
|
188
|
+
* @returns Promise resolving to signature string
|
|
189
|
+
*/
|
|
190
|
+
signMessage: (message: string) => Promise<string>;
|
|
191
|
+
/**
|
|
192
|
+
* Sign a transaction using external wallet
|
|
193
|
+
* @param tx - Transaction request object
|
|
194
|
+
* @returns Promise resolving to signed transaction string
|
|
195
|
+
*/
|
|
196
|
+
signTransaction: (tx: TransactionRequest) => Promise<string>;
|
|
197
|
+
/**
|
|
198
|
+
* Switch chain on external wallet
|
|
199
|
+
* @param chainId - Chain ID to switch to
|
|
200
|
+
* @returns Promise that resolves when chain is switched
|
|
201
|
+
*/
|
|
202
|
+
switchChain: (chainId: number) => Promise<void>;
|
|
203
|
+
};
|
|
204
|
+
};
|