@magic-ext/magic-widget 1.0.0-canary.979.20968799405.0 → 1.0.0-canary.979.21048249937.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/dist/cjs/index.js +328 -218
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/MagicWidget.d.ts +2 -1
- package/dist/cjs/types/constants.d.ts +2 -2
- package/dist/cjs/types/context/WidgetConfigContext.d.ts +22 -0
- package/dist/cjs/types/context/index.d.ts +1 -0
- package/dist/cjs/types/extension.d.ts +1 -0
- package/dist/cjs/types/hooks/useSiweLogin.d.ts +1 -1
- package/dist/cjs/types/hooks/useWalletConnect.d.ts +2 -2
- package/dist/cjs/types/index.d.ts +1 -0
- package/dist/cjs/types/reducer.d.ts +7 -3
- package/dist/cjs/types/types.d.ts +125 -8
- package/dist/cjs/types/views/LostRecoveryCode.d.ts +4 -1
- package/dist/cjs/types/views/WalletPendingView.d.ts +2 -2
- package/dist/cjs/types/wagmi/connectors.d.ts +4 -4
- package/dist/es/index.mjs +313 -204
- package/dist/es/index.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +4 -4
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
2
|
+
import { MagicWidgetProps } from './types';
|
|
3
|
+
export declare function MagicWidget({ displayMode, isOpen, onClose, closeOnSuccess, closeOnClickOutside, wallets, onSuccess, onError, }: MagicWidgetProps): React.JSX.Element | null;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { OAuthProvider, ProviderMetadata,
|
|
2
|
-
export declare const WALLET_METADATA: Record<
|
|
1
|
+
import { OAuthProvider, ProviderMetadata, ThirdPartyWallet } from './types';
|
|
2
|
+
export declare const WALLET_METADATA: Record<ThirdPartyWallet, ProviderMetadata>;
|
|
3
3
|
export declare const OAUTH_METADATA: Record<OAuthProvider, ProviderMetadata>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { LoginResult, MagicWidgetProps, ThirdPartyWallet } from '../types';
|
|
3
|
+
interface WidgetConfigContextValue {
|
|
4
|
+
/** Third-party wallets to display */
|
|
5
|
+
wallets: ThirdPartyWallet[];
|
|
6
|
+
/** Call when login succeeds */
|
|
7
|
+
handleSuccess: (result: LoginResult) => void;
|
|
8
|
+
/** Call when login fails */
|
|
9
|
+
handleError: (error: Error) => void;
|
|
10
|
+
/** Call to close the widget. Undefined if onClose prop wasn't provided. */
|
|
11
|
+
handleClose?: () => void;
|
|
12
|
+
}
|
|
13
|
+
interface WidgetConfigProviderProps extends MagicWidgetProps {
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
}
|
|
16
|
+
export declare function WidgetConfigProvider({ children, wallets, onSuccess, onError, onClose, closeOnSuccess, }: WidgetConfigProviderProps): React.JSX.Element;
|
|
17
|
+
/**
|
|
18
|
+
* Hook to access the widget configuration
|
|
19
|
+
* @throws Error if used outside of WidgetConfigProvider
|
|
20
|
+
*/
|
|
21
|
+
export declare function useWidgetConfig(): WidgetConfigContextValue;
|
|
22
|
+
export {};
|
|
@@ -158,6 +158,7 @@ export declare class MagicWidgetExtension extends Extension.Internal<'magicWidge
|
|
|
158
158
|
"recovery-code-sent-handle": () => void;
|
|
159
159
|
"invalid-recovery-code": () => void;
|
|
160
160
|
"recovery-code-success": () => void;
|
|
161
|
+
"max-attempts-reached": () => void;
|
|
161
162
|
"Auth/id-token-created": (idToken: string) => void;
|
|
162
163
|
"Wallet/wallet-info-fetched": () => void;
|
|
163
164
|
"verify-email-otp": (otp: string) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ThirdPartyWallet } from '../types';
|
|
2
2
|
export interface UseWalletConnectResult {
|
|
3
3
|
connectWallet: () => Promise<void>;
|
|
4
4
|
isPending: boolean;
|
|
@@ -9,4 +9,4 @@ export interface UseWalletConnectResult {
|
|
|
9
9
|
isConnectedToSelectedProvider: boolean;
|
|
10
10
|
disconnect: () => void;
|
|
11
11
|
}
|
|
12
|
-
export declare function useWalletConnect(provider:
|
|
12
|
+
export declare function useWalletConnect(provider: ThirdPartyWallet): UseWalletConnectResult;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export * from './MagicWidget';
|
|
2
2
|
export * from './extension';
|
|
3
|
+
export { ThirdPartyWallets, OAuthProvider, type ThirdPartyWallet, type DisplayMode, type MagicWidgetProps, type LoginResult, type EmailLoginResult, type OAuthLoginResult, type WalletLoginResult, type OAuthUserInfo, } from './types';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { LoginProvider, OAuthProvider,
|
|
1
|
+
import { LoginProvider, OAuthProvider, ThirdPartyWallet } from './types';
|
|
2
2
|
export type View = 'login' | 'otp' | 'additional_providers' | 'wallet_pending' | 'oauth_pending' | 'email_otp_pending' | 'device_verification' | 'mfa_pending' | 'recovery_code' | 'lost_recovery_code' | 'login_success';
|
|
3
|
-
export type EmailLoginStatus = 'idle' | 'sending' | 'otp_sent' | 'verifying_otp' | 'invalid_otp' | 'expired_otp' | 'device_needs_approval' | 'device_verification_sent' | 'device_verification_expired' | 'device_approved' | 'mfa_required' | 'recovery_code' | 'success' | 'mfa_verifying' | 'mfa_invalid' | 'recovery_code_verifying' | 'lost_recovery_code' | 'error';
|
|
3
|
+
export type EmailLoginStatus = 'idle' | 'sending' | 'otp_sent' | 'verifying_otp' | 'invalid_otp' | 'expired_otp' | 'max_attempts_reached' | 'device_needs_approval' | 'device_verification_sent' | 'device_verification_expired' | 'device_approved' | 'mfa_required' | 'recovery_code' | 'success' | 'mfa_verifying' | 'mfa_invalid' | 'recovery_code_verifying' | 'lost_recovery_code' | 'error';
|
|
4
4
|
export interface WidgetState {
|
|
5
5
|
view: View;
|
|
6
6
|
email?: string;
|
|
@@ -19,6 +19,8 @@ export type WidgetAction = {
|
|
|
19
19
|
type: 'EMAIL_OTP_INVALID';
|
|
20
20
|
} | {
|
|
21
21
|
type: 'EMAIL_OTP_EXPIRED';
|
|
22
|
+
} | {
|
|
23
|
+
type: 'EMAIL_OTP_MAX_ATTEMPTS_REACHED';
|
|
22
24
|
} | {
|
|
23
25
|
type: 'EMAIL_OTP_VERIFYING';
|
|
24
26
|
} | {
|
|
@@ -39,6 +41,8 @@ export type WidgetAction = {
|
|
|
39
41
|
type: 'LOST_DEVICE';
|
|
40
42
|
} | {
|
|
41
43
|
type: 'RECOVERY_CODE_VERIFYING';
|
|
44
|
+
} | {
|
|
45
|
+
type: 'RECOVERY_CODE_INVALID';
|
|
42
46
|
} | {
|
|
43
47
|
type: 'LOST_RECOVERY_CODE';
|
|
44
48
|
} | {
|
|
@@ -55,7 +59,7 @@ export type WidgetAction = {
|
|
|
55
59
|
type: 'GO_TO_ADDITIONAL_PROVIDERS';
|
|
56
60
|
} | {
|
|
57
61
|
type: 'SELECT_WALLET';
|
|
58
|
-
provider:
|
|
62
|
+
provider: ThirdPartyWallet;
|
|
59
63
|
};
|
|
60
64
|
export declare const initialState: WidgetState;
|
|
61
65
|
export declare function widgetReducer(state: WidgetState, action: WidgetAction): WidgetState;
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { ComponentType } from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Available third-party wallet providers.
|
|
4
|
+
* Use these constants or pass string literals directly: 'metamask', 'coinbase', etc.
|
|
5
|
+
*/
|
|
6
|
+
export declare const ThirdPartyWallets: {
|
|
7
|
+
readonly METAMASK: "metamask";
|
|
8
|
+
readonly WALLETCONNECT: "walletconnect";
|
|
9
|
+
readonly COINBASE: "coinbase";
|
|
10
|
+
readonly PHANTOM: "phantom";
|
|
11
|
+
readonly RABBY: "rabby";
|
|
12
|
+
};
|
|
13
|
+
/** Type representing valid third-party wallet values */
|
|
14
|
+
export type ThirdPartyWallet = (typeof ThirdPartyWallets)[keyof typeof ThirdPartyWallets];
|
|
9
15
|
export interface ProviderMetadata {
|
|
10
16
|
displayName: string;
|
|
11
17
|
Icon: ComponentType<{
|
|
@@ -32,7 +38,7 @@ export declare enum OAuthProvider {
|
|
|
32
38
|
GITLAB = "gitlab",
|
|
33
39
|
TELEGRAM = "telegram"
|
|
34
40
|
}
|
|
35
|
-
export type LoginProvider = OAuthProvider |
|
|
41
|
+
export type LoginProvider = OAuthProvider | ThirdPartyWallet;
|
|
36
42
|
export interface ProviderConfig {
|
|
37
43
|
title: string;
|
|
38
44
|
description: string;
|
|
@@ -42,3 +48,114 @@ export interface ProviderConfig {
|
|
|
42
48
|
className?: string;
|
|
43
49
|
}>;
|
|
44
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* OAuth user information returned from social login
|
|
53
|
+
*/
|
|
54
|
+
export interface OAuthUserInfo {
|
|
55
|
+
/** The OAuth provider used (e.g., 'google', 'apple') */
|
|
56
|
+
provider: string;
|
|
57
|
+
name?: string;
|
|
58
|
+
email?: string;
|
|
59
|
+
picture?: string;
|
|
60
|
+
[key: string]: unknown;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Result returned on successful email login
|
|
64
|
+
*/
|
|
65
|
+
export interface EmailLoginResult {
|
|
66
|
+
method: 'email';
|
|
67
|
+
/** The DID token for authentication */
|
|
68
|
+
didToken: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Result returned on successful OAuth login
|
|
72
|
+
*/
|
|
73
|
+
export interface OAuthLoginResult {
|
|
74
|
+
method: 'oauth';
|
|
75
|
+
/** The DID token for authentication */
|
|
76
|
+
didToken: string;
|
|
77
|
+
/** OAuth provider information */
|
|
78
|
+
oauth: OAuthUserInfo;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Result returned on successful wallet login
|
|
82
|
+
*/
|
|
83
|
+
export interface WalletLoginResult {
|
|
84
|
+
method: 'wallet';
|
|
85
|
+
/** The connected wallet address */
|
|
86
|
+
walletAddress: string;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Discriminated union of all login result types.
|
|
90
|
+
* Check the `method` property to determine which fields are available.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* onSuccess={(result) => {
|
|
94
|
+
* if (result.method === 'email' || result.method === 'oauth') {
|
|
95
|
+
* sendToBackend(result.didToken);
|
|
96
|
+
* } else {
|
|
97
|
+
* console.log('Wallet:', result.walletAddress);
|
|
98
|
+
* }
|
|
99
|
+
* }}
|
|
100
|
+
*/
|
|
101
|
+
export type LoginResult = EmailLoginResult | OAuthLoginResult | WalletLoginResult;
|
|
102
|
+
/**
|
|
103
|
+
* How the widget is displayed on the page.
|
|
104
|
+
* - 'inline': Rendered in the document flow (default)
|
|
105
|
+
* - 'modal': Positioned as a modal dialog, slightly above center
|
|
106
|
+
*/
|
|
107
|
+
export type DisplayMode = 'inline' | 'modal';
|
|
108
|
+
export interface MagicWidgetProps {
|
|
109
|
+
/**
|
|
110
|
+
* How the widget is displayed on the page. Defaults to 'inline'.
|
|
111
|
+
* - 'inline': Rendered in the document flow
|
|
112
|
+
* - 'modal': Positioned as a modal dialog with backdrop
|
|
113
|
+
* @example displayMode="modal"
|
|
114
|
+
*/
|
|
115
|
+
displayMode?: DisplayMode;
|
|
116
|
+
/**
|
|
117
|
+
* Whether the widget modal is open. Defaults to true.
|
|
118
|
+
* @example isOpen={showLogin}
|
|
119
|
+
*/
|
|
120
|
+
isOpen?: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Callback fired when the widget is closed (e.g., user clicks X button).
|
|
123
|
+
* @example onClose={() => setShowLogin(false)}
|
|
124
|
+
*/
|
|
125
|
+
onClose?: () => void;
|
|
126
|
+
/**
|
|
127
|
+
* Automatically call onClose after successful login (with a 2 second delay to show success screen).
|
|
128
|
+
* Defaults to false.
|
|
129
|
+
* @example closeOnSuccess={true}
|
|
130
|
+
*/
|
|
131
|
+
closeOnSuccess?: boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Close the modal when clicking the backdrop. Only applies when displayMode="modal".
|
|
134
|
+
* Defaults to false.
|
|
135
|
+
* @example closeOnClickOutside={true}
|
|
136
|
+
*/
|
|
137
|
+
closeOnClickOutside?: boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Third-party wallets to display. None enabled by default.
|
|
140
|
+
* Accepts constants or string literals: 'metamask', 'walletconnect', 'coinbase', 'phantom', 'rabby'
|
|
141
|
+
* @example wallets={['metamask', 'coinbase']}
|
|
142
|
+
* @example wallets={[ThirdPartyWallets.METAMASK, ThirdPartyWallets.COINBASE]}
|
|
143
|
+
*/
|
|
144
|
+
wallets?: ThirdPartyWallet[];
|
|
145
|
+
/**
|
|
146
|
+
* Callback fired when login succeeds.
|
|
147
|
+
* The result type varies by login method - check `result.method` to determine the shape.
|
|
148
|
+
* @example
|
|
149
|
+
* onSuccess={(result) => {
|
|
150
|
+
* if (result.method === 'email' || result.method === 'oauth') {
|
|
151
|
+
* authenticate(result.didToken);
|
|
152
|
+
* }
|
|
153
|
+
* }}
|
|
154
|
+
*/
|
|
155
|
+
onSuccess?: (result: LoginResult) => void;
|
|
156
|
+
/**
|
|
157
|
+
* Callback fired when login fails
|
|
158
|
+
* @example onError={(error) => console.error(error.message)}
|
|
159
|
+
*/
|
|
160
|
+
onError?: (error: Error) => void;
|
|
161
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { WidgetAction } from '../reducer';
|
|
3
|
-
import {
|
|
3
|
+
import { ThirdPartyWallet } from '../types';
|
|
4
4
|
interface WalletPendingViewProps {
|
|
5
|
-
provider:
|
|
5
|
+
provider: ThirdPartyWallet;
|
|
6
6
|
dispatch: React.Dispatch<WidgetAction>;
|
|
7
7
|
}
|
|
8
8
|
export declare const WalletPendingView: ({ provider, dispatch }: WalletPendingViewProps) => React.JSX.Element;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ThirdPartyWallet } from '../types';
|
|
2
2
|
/**
|
|
3
|
-
* Map
|
|
3
|
+
* Map wallet types to wagmi connector IDs
|
|
4
4
|
*/
|
|
5
|
-
export declare const CONNECTOR_IDS: Record<
|
|
5
|
+
export declare const CONNECTOR_IDS: Record<ThirdPartyWallet, string>;
|
|
6
6
|
/**
|
|
7
7
|
* Alternative names to match connectors by name if ID doesn't match
|
|
8
8
|
*/
|
|
9
|
-
export declare const CONNECTOR_NAME_PATTERNS: Record<
|
|
9
|
+
export declare const CONNECTOR_NAME_PATTERNS: Record<ThirdPartyWallet, string>;
|