@dynamic-labs/sdk-react-core 3.1.1 → 3.1.3
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/CHANGELOG.md +14 -0
- package/package.cjs +2 -2
- package/package.js +2 -2
- package/package.json +11 -12
- package/src/lib/components/SendBalanceForm/SendBalanceForm.cjs +5 -1
- package/src/lib/components/SendBalanceForm/SendBalanceForm.js +5 -1
- package/src/lib/data/api/oauth/oauth.cjs +14 -0
- package/src/lib/data/api/oauth/oauth.d.ts +1 -0
- package/src/lib/data/api/oauth/oauth.js +14 -1
- package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.cjs +3 -2
- package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.d.ts +2 -1
- package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.js +3 -2
- package/src/lib/utils/hooks/useTelegramLogin/useTelegramLogin.cjs +39 -25
- package/src/lib/utils/hooks/useTelegramLogin/useTelegramLogin.d.ts +8 -1
- package/src/lib/utils/hooks/useTelegramLogin/useTelegramLogin.js +39 -25
- package/src/lib/utils/hooks/useWalletOptions/useWalletOptions.cjs +1 -0
- package/src/lib/utils/hooks/useWalletOptions/useWalletOptions.d.ts +1 -0
- package/src/lib/utils/hooks/useWalletOptions/useWalletOptions.js +1 -0
- package/src/lib/views/NoAccess/NoAccess.cjs +4 -1
- package/src/lib/views/NoAccess/NoAccess.js +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
|
|
2
|
+
### [3.1.3](https://github.com/dynamic-labs/DynamicAuth/compare/v3.1.2...v3.1.3) (2024-09-25)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* add isInstalledOnBrowser prop to wallet options in useWalletOptions ([#6977](https://github.com/dynamic-labs/DynamicAuth/issues/6977)) ([9436e48](https://github.com/dynamic-labs/DynamicAuth/commit/9436e48994663b62d1ef5afa0c37df436f68caae))
|
|
8
|
+
|
|
9
|
+
### [3.1.2](https://github.com/dynamic-labs/DynamicAuth/compare/v3.1.1...v3.1.2) (2024-09-23)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* issue where builtin stream module was a dependency ([#6985](https://github.com/dynamic-labs/DynamicAuth/issues/6985)) ([5ac1f6c](https://github.com/dynamic-labs/DynamicAuth/commit/5ac1f6c7b96f773d5f2f1899748c2a7fc84235ec))
|
|
15
|
+
|
|
2
16
|
### [3.1.1](https://github.com/dynamic-labs/DynamicAuth/compare/v3.1.0...v3.1.1) (2024-09-20)
|
|
3
17
|
|
|
4
18
|
|
package/package.cjs
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
|
-
var version = "3.1.
|
|
6
|
+
var version = "3.1.3";
|
|
7
7
|
var dependencies = {
|
|
8
|
-
"@dynamic-labs/sdk-api-core": "0.0.
|
|
8
|
+
"@dynamic-labs/sdk-api-core": "0.0.535",
|
|
9
9
|
"@hcaptcha/react-hcaptcha": "1.4.4",
|
|
10
10
|
"country-list": "2.3.0",
|
|
11
11
|
formik: "2.2.9",
|
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/sdk-react-core",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.3",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
|
|
7
7
|
"directory": "packages/sdk-react-core"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@dynamic-labs/sdk-api-core": "0.0.
|
|
10
|
+
"@dynamic-labs/sdk-api-core": "0.0.535",
|
|
11
11
|
"@hcaptcha/react-hcaptcha": "1.4.4",
|
|
12
12
|
"country-list": "2.3.0",
|
|
13
13
|
"formik": "2.2.9",
|
|
@@ -17,16 +17,15 @@
|
|
|
17
17
|
"react-i18next": "13.5.0",
|
|
18
18
|
"yup": "0.32.11",
|
|
19
19
|
"react-international-phone": "4.2.5",
|
|
20
|
-
"@dynamic-labs/iconic": "3.1.
|
|
21
|
-
"@dynamic-labs/logger": "3.1.
|
|
22
|
-
"@dynamic-labs/
|
|
23
|
-
"@dynamic-labs/
|
|
24
|
-
"@dynamic-labs/
|
|
25
|
-
"@dynamic-labs/
|
|
26
|
-
"@dynamic-labs/
|
|
27
|
-
"@dynamic-labs/
|
|
28
|
-
"@dynamic-labs/wallet-
|
|
29
|
-
"@dynamic-labs/wallet-connector-core": "3.1.1",
|
|
20
|
+
"@dynamic-labs/iconic": "3.1.3",
|
|
21
|
+
"@dynamic-labs/logger": "3.1.3",
|
|
22
|
+
"@dynamic-labs/multi-wallet": "3.1.3",
|
|
23
|
+
"@dynamic-labs/rpc-providers": "3.1.3",
|
|
24
|
+
"@dynamic-labs/store": "3.1.3",
|
|
25
|
+
"@dynamic-labs/types": "3.1.3",
|
|
26
|
+
"@dynamic-labs/utils": "3.1.3",
|
|
27
|
+
"@dynamic-labs/wallet-book": "3.1.3",
|
|
28
|
+
"@dynamic-labs/wallet-connector-core": "3.1.3",
|
|
30
29
|
"eventemitter3": "5.0.1"
|
|
31
30
|
},
|
|
32
31
|
"devDependencies": {
|
|
@@ -153,7 +153,7 @@ const SendBalanceForm = ({ initialValues, onSubmit, decimals = 18, validateAddre
|
|
|
153
153
|
}),
|
|
154
154
|
});
|
|
155
155
|
}, [decimals, validateAddress, validateAmount]);
|
|
156
|
-
return (jsxRuntime.jsx(formik.Formik, { initialValues: initialValues || sendBalanceFormInitialValues, validationSchema: sendBalanceFormValidationSchema, onSubmit: (values) => onSubmit(values), validateOnChange: false, validateOnBlur: false, children: ({ errors, touched, values, handleChange, setFieldValue, setErrors, }) => {
|
|
156
|
+
return (jsxRuntime.jsx(formik.Formik, { initialValues: initialValues || sendBalanceFormInitialValues, validationSchema: sendBalanceFormValidationSchema, onSubmit: (values) => onSubmit(values), validateOnChange: false, validateOnBlur: false, children: ({ errors, touched, values, handleChange, setFieldValue, setErrors, handleBlur, setFieldTouched, validateField, }) => {
|
|
157
157
|
var _a;
|
|
158
158
|
return (jsxRuntime.jsxs(formik.Form, { className: 'send-balance-form', children: [jsxRuntime.jsxs("div", { className: 'send-balance-page-layout__balance-container', children: [jsxRuntime.jsx(FormFieldLabel.FormFieldLabel, { children: "Select any token" }), jsxRuntime.jsx(TokensBalanceDropdown.TokensBalanceDropdown, { tokenBalances: tokenBalances !== null && tokenBalances !== void 0 ? tokenBalances : (currentToken && [currentToken]), currentToken: currentToken, setCurrentToken: setCurrentToken, isLoading: isLoading, setFieldValue: setFieldValue, setErrors: setErrors })] }), jsxRuntime.jsxs("div", { className: 'send-balance-form__amount-container', children: [jsxRuntime.jsx(formik.Field, { variant: 'regular', className: `send-balance-form__amount-container__field ${showFiat ? 'fiat' : ''}`, name: 'amount', id: 'amount', onChange: (e) => {
|
|
159
159
|
const newValue = e.target.value;
|
|
@@ -168,6 +168,10 @@ const SendBalanceForm = ({ initialValues, onSubmit, decimals = 18, validateAddre
|
|
|
168
168
|
return;
|
|
169
169
|
}
|
|
170
170
|
sendBalances.setSendBalanceVariable('amount', (currentToken === null || currentToken === void 0 ? void 0 : currentToken.price) ? Number(newValue) : undefined);
|
|
171
|
+
}, onBlur: (e) => {
|
|
172
|
+
handleBlur(e);
|
|
173
|
+
setFieldTouched('amount', true);
|
|
174
|
+
validateField('amount');
|
|
171
175
|
}, placeholder: t('dyn_send_transaction.data.amount.placeholder'), as: Input.Input, error: errors['amount'], copykey: 'dyn_send_transaction.data.amount.label', message: touched['amount'] &&
|
|
172
176
|
getDisplayErrorMessage(errors, t, 'amount', decimals), style: {
|
|
173
177
|
paddingLeft: `${leftSymbolPadding}px`,
|
|
@@ -149,7 +149,7 @@ const SendBalanceForm = ({ initialValues, onSubmit, decimals = 18, validateAddre
|
|
|
149
149
|
}),
|
|
150
150
|
});
|
|
151
151
|
}, [decimals, validateAddress, validateAmount]);
|
|
152
|
-
return (jsx(Formik, { initialValues: initialValues || sendBalanceFormInitialValues, validationSchema: sendBalanceFormValidationSchema, onSubmit: (values) => onSubmit(values), validateOnChange: false, validateOnBlur: false, children: ({ errors, touched, values, handleChange, setFieldValue, setErrors, }) => {
|
|
152
|
+
return (jsx(Formik, { initialValues: initialValues || sendBalanceFormInitialValues, validationSchema: sendBalanceFormValidationSchema, onSubmit: (values) => onSubmit(values), validateOnChange: false, validateOnBlur: false, children: ({ errors, touched, values, handleChange, setFieldValue, setErrors, handleBlur, setFieldTouched, validateField, }) => {
|
|
153
153
|
var _a;
|
|
154
154
|
return (jsxs(Form, { className: 'send-balance-form', children: [jsxs("div", { className: 'send-balance-page-layout__balance-container', children: [jsx(FormFieldLabel, { children: "Select any token" }), jsx(TokensBalanceDropdown, { tokenBalances: tokenBalances !== null && tokenBalances !== void 0 ? tokenBalances : (currentToken && [currentToken]), currentToken: currentToken, setCurrentToken: setCurrentToken, isLoading: isLoading, setFieldValue: setFieldValue, setErrors: setErrors })] }), jsxs("div", { className: 'send-balance-form__amount-container', children: [jsx(Field, { variant: 'regular', className: `send-balance-form__amount-container__field ${showFiat ? 'fiat' : ''}`, name: 'amount', id: 'amount', onChange: (e) => {
|
|
155
155
|
const newValue = e.target.value;
|
|
@@ -164,6 +164,10 @@ const SendBalanceForm = ({ initialValues, onSubmit, decimals = 18, validateAddre
|
|
|
164
164
|
return;
|
|
165
165
|
}
|
|
166
166
|
setSendBalanceVariable('amount', (currentToken === null || currentToken === void 0 ? void 0 : currentToken.price) ? Number(newValue) : undefined);
|
|
167
|
+
}, onBlur: (e) => {
|
|
168
|
+
handleBlur(e);
|
|
169
|
+
setFieldTouched('amount', true);
|
|
170
|
+
validateField('amount');
|
|
167
171
|
}, placeholder: t('dyn_send_transaction.data.amount.placeholder'), as: Input, error: errors['amount'], copykey: 'dyn_send_transaction.data.amount.label', message: touched['amount'] &&
|
|
168
172
|
getDisplayErrorMessage(errors, t, 'amount', decimals), style: {
|
|
169
173
|
paddingLeft: `${leftSymbolPadding}px`,
|
|
@@ -143,6 +143,19 @@ const telegramSignIn = (environmentId, oauthResultRequest) => _tslib.__awaiter(v
|
|
|
143
143
|
return handleSignInError(e);
|
|
144
144
|
}
|
|
145
145
|
});
|
|
146
|
+
const isUserLinkedWithTelegram = (environmentId, oauthResultRequest) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
147
|
+
const telegramCheckAuthRequest = {
|
|
148
|
+
environmentId,
|
|
149
|
+
oauthResultRequest,
|
|
150
|
+
};
|
|
151
|
+
try {
|
|
152
|
+
yield api.sdkApi().telegramCheckAuth(telegramCheckAuthRequest);
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
catch (e) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
146
159
|
const telegramVerify = (environmentId, oauthResultRequest) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
147
160
|
const telegramVerifyRequest = {
|
|
148
161
|
environmentId,
|
|
@@ -195,6 +208,7 @@ exports.farcasterSignIn = farcasterSignIn;
|
|
|
195
208
|
exports.farcasterVerify = farcasterVerify;
|
|
196
209
|
exports.getOAuthResult = getOAuthResult;
|
|
197
210
|
exports.initAuth = initAuth;
|
|
211
|
+
exports.isUserLinkedWithTelegram = isUserLinkedWithTelegram;
|
|
198
212
|
exports.signInOAuth = signInOAuth;
|
|
199
213
|
exports.telegramSignIn = telegramSignIn;
|
|
200
214
|
exports.telegramVerify = telegramVerify;
|
|
@@ -13,4 +13,5 @@ export declare const getOAuthResult: (environmentId: string, providerType: Provi
|
|
|
13
13
|
export declare const farcasterSignIn: (environmentId: string, farcasterSignInRequest: FarcasterSignInRequest) => Promise<UserProfile | undefined>;
|
|
14
14
|
export declare const farcasterVerify: (farcasterVerifyRequest: FarcasterVerifyRequest) => Promise<UserProfile | undefined>;
|
|
15
15
|
export declare const telegramSignIn: (environmentId: string, oauthResultRequest: OauthResultRequest) => Promise<UserProfile | undefined>;
|
|
16
|
+
export declare const isUserLinkedWithTelegram: (environmentId: string, oauthResultRequest: OauthResultRequest) => Promise<boolean | undefined>;
|
|
16
17
|
export declare const telegramVerify: (environmentId: string, oauthResultRequest: OauthResultRequest) => Promise<UserProfile | undefined>;
|
|
@@ -139,6 +139,19 @@ const telegramSignIn = (environmentId, oauthResultRequest) => __awaiter(void 0,
|
|
|
139
139
|
return handleSignInError(e);
|
|
140
140
|
}
|
|
141
141
|
});
|
|
142
|
+
const isUserLinkedWithTelegram = (environmentId, oauthResultRequest) => __awaiter(void 0, void 0, void 0, function* () {
|
|
143
|
+
const telegramCheckAuthRequest = {
|
|
144
|
+
environmentId,
|
|
145
|
+
oauthResultRequest,
|
|
146
|
+
};
|
|
147
|
+
try {
|
|
148
|
+
yield sdkApi().telegramCheckAuth(telegramCheckAuthRequest);
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
catch (e) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
142
155
|
const telegramVerify = (environmentId, oauthResultRequest) => __awaiter(void 0, void 0, void 0, function* () {
|
|
143
156
|
const telegramVerifyRequest = {
|
|
144
157
|
environmentId,
|
|
@@ -187,4 +200,4 @@ const handleSignInError = (e) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
187
200
|
return undefined;
|
|
188
201
|
});
|
|
189
202
|
|
|
190
|
-
export { farcasterSignIn, farcasterVerify, getOAuthResult, initAuth, signInOAuth, telegramSignIn, telegramVerify, unlinkOAuth, verifyOAuth };
|
|
203
|
+
export { farcasterSignIn, farcasterVerify, getOAuthResult, initAuth, isUserLinkedWithTelegram, signInOAuth, telegramSignIn, telegramVerify, unlinkOAuth, verifyOAuth };
|
|
@@ -187,7 +187,7 @@ const useSocialAuth = ({ sessionTimeout, onSettled, onError, onFarcasterUrl, })
|
|
|
187
187
|
verifyFunction: () => apiCall(),
|
|
188
188
|
});
|
|
189
189
|
}), [handleError, initAuth, onSettled]);
|
|
190
|
-
const completeConnection = React.useCallback((_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ authMode, provider, state, authCode, captchaToken, verifier, telegramAuthToken, }) {
|
|
190
|
+
const completeConnection = React.useCallback((_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ authMode, provider, state, authCode, captchaToken, verifier, telegramAuthToken, forceCreateUser = false, }) {
|
|
191
191
|
try {
|
|
192
192
|
let sessionPublicKey = undefined;
|
|
193
193
|
if (shouldRegisterSessionKeysOnSignin()) {
|
|
@@ -197,10 +197,11 @@ const useSocialAuth = ({ sessionTimeout, onSettled, onError, onFarcasterUrl, })
|
|
|
197
197
|
if (authMode === 'signin') {
|
|
198
198
|
if (provider === sdkApiCore.ProviderEnum.Telegram && telegramAuthToken) {
|
|
199
199
|
const apiCall = () => oauth.telegramSignIn(environmentId, {
|
|
200
|
+
forceCreateUser,
|
|
200
201
|
sessionPublicKey,
|
|
201
202
|
telegramAuthToken,
|
|
202
203
|
});
|
|
203
|
-
yield signInAccount(provider, apiCall);
|
|
204
|
+
return yield signInAccount(provider, apiCall);
|
|
204
205
|
}
|
|
205
206
|
else if (provider === sdkApiCore.ProviderEnum.Telegram) {
|
|
206
207
|
const apiCall = () => oauth.telegramSignIn(environmentId, {
|
|
@@ -18,7 +18,7 @@ export type ConnectSocialAccountProps = {
|
|
|
18
18
|
};
|
|
19
19
|
export declare const useSocialAuth: ({ sessionTimeout, onSettled, onError, onFarcasterUrl, }: UseSocialAuthProps) => {
|
|
20
20
|
readonly checkValidProvider: (provider: ProviderEnum, authMode: SocialAuthMode) => boolean;
|
|
21
|
-
readonly completeConnection: ({ authMode, provider, state, authCode, captchaToken, verifier, telegramAuthToken, }: {
|
|
21
|
+
readonly completeConnection: ({ authMode, provider, state, authCode, captchaToken, verifier, telegramAuthToken, forceCreateUser, }: {
|
|
22
22
|
authMode: SocialAuthMode;
|
|
23
23
|
provider: ProviderEnum;
|
|
24
24
|
state: string;
|
|
@@ -26,6 +26,7 @@ export declare const useSocialAuth: ({ sessionTimeout, onSettled, onError, onFar
|
|
|
26
26
|
authCode?: string | undefined;
|
|
27
27
|
verifier?: string | undefined;
|
|
28
28
|
telegramAuthToken?: string | undefined;
|
|
29
|
+
forceCreateUser?: boolean | undefined;
|
|
29
30
|
}) => Promise<void>;
|
|
30
31
|
readonly connectSocialAccount: ({ authMode, provider, validator, captchaToken, redirectUrl, telegramAuthToken, }: ConnectSocialAccountProps) => Promise<void>;
|
|
31
32
|
readonly error: SocialOAuthError | undefined;
|
|
@@ -183,7 +183,7 @@ const useSocialAuth = ({ sessionTimeout, onSettled, onError, onFarcasterUrl, })
|
|
|
183
183
|
verifyFunction: () => apiCall(),
|
|
184
184
|
});
|
|
185
185
|
}), [handleError, initAuth$1, onSettled]);
|
|
186
|
-
const completeConnection = useCallback((_a) => __awaiter(void 0, [_a], void 0, function* ({ authMode, provider, state, authCode, captchaToken, verifier, telegramAuthToken, }) {
|
|
186
|
+
const completeConnection = useCallback((_a) => __awaiter(void 0, [_a], void 0, function* ({ authMode, provider, state, authCode, captchaToken, verifier, telegramAuthToken, forceCreateUser = false, }) {
|
|
187
187
|
try {
|
|
188
188
|
let sessionPublicKey = undefined;
|
|
189
189
|
if (shouldRegisterSessionKeysOnSignin()) {
|
|
@@ -193,10 +193,11 @@ const useSocialAuth = ({ sessionTimeout, onSettled, onError, onFarcasterUrl, })
|
|
|
193
193
|
if (authMode === 'signin') {
|
|
194
194
|
if (provider === ProviderEnum.Telegram && telegramAuthToken) {
|
|
195
195
|
const apiCall = () => telegramSignIn(environmentId, {
|
|
196
|
+
forceCreateUser,
|
|
196
197
|
sessionPublicKey,
|
|
197
198
|
telegramAuthToken,
|
|
198
199
|
});
|
|
199
|
-
yield signInAccount(provider, apiCall);
|
|
200
|
+
return yield signInAccount(provider, apiCall);
|
|
200
201
|
}
|
|
201
202
|
else if (provider === ProviderEnum.Telegram) {
|
|
202
203
|
const apiCall = () => telegramSignIn(environmentId, {
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
6
|
var _tslib = require('../../../../../_virtual/_tslib.cjs');
|
|
7
|
-
var React = require('react');
|
|
8
7
|
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
9
8
|
require('../../constants/values.cjs');
|
|
10
9
|
require('@dynamic-labs/utils');
|
|
@@ -16,12 +15,14 @@ require('@dynamic-labs/iconic');
|
|
|
16
15
|
require('@dynamic-labs/wallet-connector-core');
|
|
17
16
|
require('react/jsx-runtime');
|
|
18
17
|
require('../../../context/ViewContext/ViewContext.cjs');
|
|
18
|
+
require('react');
|
|
19
19
|
require('@dynamic-labs/wallet-book');
|
|
20
20
|
require('../../../store/state/loadingAndLifecycle.cjs');
|
|
21
21
|
require('../../../shared/consts/index.cjs');
|
|
22
22
|
var isProviderEnabled = require('../../functions/isProviderEnabled/isProviderEnabled.cjs');
|
|
23
23
|
require('../../../config/ApiEndpoint.cjs');
|
|
24
24
|
require('../../../store/state/user/user.cjs');
|
|
25
|
+
var oauth = require('../../../data/api/oauth/oauth.cjs');
|
|
25
26
|
require('../../../locale/locale.cjs');
|
|
26
27
|
require('../../../store/state/projectSettings/projectSettings.cjs');
|
|
27
28
|
require('../../../context/DynamicContext/DynamicContext.cjs');
|
|
@@ -94,35 +95,48 @@ require('../../../store/state/tokenBalances.cjs');
|
|
|
94
95
|
var useInternalDynamicContext = require('../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext.cjs');
|
|
95
96
|
|
|
96
97
|
const useTelegramLogin = () => {
|
|
97
|
-
const { sdkHasLoaded, user, projectSettings } = useInternalDynamicContext.useInternalDynamicContext();
|
|
98
|
+
const { sdkHasLoaded, user, projectSettings, environmentId } = useInternalDynamicContext.useInternalDynamicContext();
|
|
98
99
|
const providers = (projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers) || [];
|
|
99
100
|
const { completeConnection } = useSocialAuth.useSocialAuth({
|
|
100
101
|
sessionTimeout: 20000,
|
|
101
102
|
});
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
103
|
+
const getTelegramAuthToken = () => {
|
|
104
|
+
// in non-browser environments like Node.js
|
|
105
|
+
// or during server-side rendering (e.g., with frameworks like Next.js).
|
|
106
|
+
if (typeof window === 'undefined') {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const search = new URLSearchParams(window.location.search);
|
|
110
|
+
return search.get('telegramAuthToken') || undefined;
|
|
111
|
+
};
|
|
112
|
+
const canProceedWithTelegram = (telegramAuthToken) => isProviderEnabled.isProviderEnabled(providers, sdkApiCore.ProviderEnum.Telegram) &&
|
|
113
|
+
sdkHasLoaded &&
|
|
114
|
+
!user &&
|
|
115
|
+
telegramAuthToken;
|
|
116
|
+
const isAuthWithTelegram = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
117
|
+
const telegramAuthToken = getTelegramAuthToken();
|
|
118
|
+
if (!canProceedWithTelegram(telegramAuthToken)) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
return oauth.isUserLinkedWithTelegram(environmentId, { telegramAuthToken });
|
|
122
|
+
});
|
|
123
|
+
const telegramSignIn = (...args_1) => _tslib.__awaiter(void 0, [...args_1], void 0, function* ({ forceCreateUser = false, } = {}) {
|
|
124
|
+
const telegramAuthToken = getTelegramAuthToken();
|
|
125
|
+
if (!canProceedWithTelegram(telegramAuthToken)) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
yield completeConnection({
|
|
129
|
+
authMode: 'signin',
|
|
130
|
+
forceCreateUser,
|
|
131
|
+
provider: sdkApiCore.ProviderEnum.Telegram,
|
|
132
|
+
state: '',
|
|
133
|
+
telegramAuthToken,
|
|
123
134
|
});
|
|
124
|
-
|
|
125
|
-
|
|
135
|
+
});
|
|
136
|
+
return {
|
|
137
|
+
isAuthWithTelegram,
|
|
138
|
+
telegramSignIn,
|
|
139
|
+
};
|
|
126
140
|
};
|
|
127
141
|
|
|
128
142
|
exports.useTelegramLogin = useTelegramLogin;
|
|
@@ -1 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
interface TelegramConfig {
|
|
2
|
+
forceCreateUser?: boolean;
|
|
3
|
+
}
|
|
4
|
+
export declare const useTelegramLogin: () => {
|
|
5
|
+
isAuthWithTelegram: () => Promise<boolean | undefined>;
|
|
6
|
+
telegramSignIn: ({ forceCreateUser, }?: TelegramConfig) => Promise<void>;
|
|
7
|
+
};
|
|
8
|
+
export {};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
3
|
-
import { useEffect } from 'react';
|
|
4
3
|
import { ProviderEnum } from '@dynamic-labs/sdk-api-core';
|
|
5
4
|
import '../../constants/values.js';
|
|
6
5
|
import '@dynamic-labs/utils';
|
|
@@ -12,12 +11,14 @@ import '@dynamic-labs/iconic';
|
|
|
12
11
|
import '@dynamic-labs/wallet-connector-core';
|
|
13
12
|
import 'react/jsx-runtime';
|
|
14
13
|
import '../../../context/ViewContext/ViewContext.js';
|
|
14
|
+
import 'react';
|
|
15
15
|
import '@dynamic-labs/wallet-book';
|
|
16
16
|
import '../../../store/state/loadingAndLifecycle.js';
|
|
17
17
|
import '../../../shared/consts/index.js';
|
|
18
18
|
import { isProviderEnabled } from '../../functions/isProviderEnabled/isProviderEnabled.js';
|
|
19
19
|
import '../../../config/ApiEndpoint.js';
|
|
20
20
|
import '../../../store/state/user/user.js';
|
|
21
|
+
import { isUserLinkedWithTelegram } from '../../../data/api/oauth/oauth.js';
|
|
21
22
|
import '../../../locale/locale.js';
|
|
22
23
|
import '../../../store/state/projectSettings/projectSettings.js';
|
|
23
24
|
import '../../../context/DynamicContext/DynamicContext.js';
|
|
@@ -90,35 +91,48 @@ import '../../../store/state/tokenBalances.js';
|
|
|
90
91
|
import { useInternalDynamicContext } from '../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext.js';
|
|
91
92
|
|
|
92
93
|
const useTelegramLogin = () => {
|
|
93
|
-
const { sdkHasLoaded, user, projectSettings } = useInternalDynamicContext();
|
|
94
|
+
const { sdkHasLoaded, user, projectSettings, environmentId } = useInternalDynamicContext();
|
|
94
95
|
const providers = (projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers) || [];
|
|
95
96
|
const { completeConnection } = useSocialAuth({
|
|
96
97
|
sessionTimeout: 20000,
|
|
97
98
|
});
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
99
|
+
const getTelegramAuthToken = () => {
|
|
100
|
+
// in non-browser environments like Node.js
|
|
101
|
+
// or during server-side rendering (e.g., with frameworks like Next.js).
|
|
102
|
+
if (typeof window === 'undefined') {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const search = new URLSearchParams(window.location.search);
|
|
106
|
+
return search.get('telegramAuthToken') || undefined;
|
|
107
|
+
};
|
|
108
|
+
const canProceedWithTelegram = (telegramAuthToken) => isProviderEnabled(providers, ProviderEnum.Telegram) &&
|
|
109
|
+
sdkHasLoaded &&
|
|
110
|
+
!user &&
|
|
111
|
+
telegramAuthToken;
|
|
112
|
+
const isAuthWithTelegram = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
113
|
+
const telegramAuthToken = getTelegramAuthToken();
|
|
114
|
+
if (!canProceedWithTelegram(telegramAuthToken)) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
return isUserLinkedWithTelegram(environmentId, { telegramAuthToken });
|
|
118
|
+
});
|
|
119
|
+
const telegramSignIn = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* ({ forceCreateUser = false, } = {}) {
|
|
120
|
+
const telegramAuthToken = getTelegramAuthToken();
|
|
121
|
+
if (!canProceedWithTelegram(telegramAuthToken)) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
yield completeConnection({
|
|
125
|
+
authMode: 'signin',
|
|
126
|
+
forceCreateUser,
|
|
127
|
+
provider: ProviderEnum.Telegram,
|
|
128
|
+
state: '',
|
|
129
|
+
telegramAuthToken,
|
|
119
130
|
});
|
|
120
|
-
|
|
121
|
-
|
|
131
|
+
});
|
|
132
|
+
return {
|
|
133
|
+
isAuthWithTelegram,
|
|
134
|
+
telegramSignIn,
|
|
135
|
+
};
|
|
122
136
|
};
|
|
123
137
|
|
|
124
138
|
export { useTelegramLogin };
|
|
@@ -104,7 +104,10 @@ require('qrcode');
|
|
|
104
104
|
const NoAccess = () => {
|
|
105
105
|
const { deniedAddress, setDeniedAddress, setDeniedOauthProvider, deniedOauthProvider, deniedOauthUsername, } = AccessDeniedContext.useAccessDeniedContext();
|
|
106
106
|
const { t } = reactI18next.useTranslation();
|
|
107
|
-
|
|
107
|
+
// deniedOauthProvider can be undefined
|
|
108
|
+
const accessIcon = deniedOauthProvider
|
|
109
|
+
? iconic.findSocialIcon(deniedOauthProvider)
|
|
110
|
+
: undefined;
|
|
108
111
|
const { selectedWalletConnector: walletConnector, socialMediaIconUrl, notInTheListImageUrl, accessDeniedButton, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
109
112
|
const { displayedDestination: email } = VerificationContext.useVerification();
|
|
110
113
|
const { goToInitialView } = ViewContext.useViewContext();
|
|
@@ -100,7 +100,10 @@ import 'qrcode';
|
|
|
100
100
|
const NoAccess = () => {
|
|
101
101
|
const { deniedAddress, setDeniedAddress, setDeniedOauthProvider, deniedOauthProvider, deniedOauthUsername, } = useAccessDeniedContext();
|
|
102
102
|
const { t } = useTranslation();
|
|
103
|
-
|
|
103
|
+
// deniedOauthProvider can be undefined
|
|
104
|
+
const accessIcon = deniedOauthProvider
|
|
105
|
+
? findSocialIcon(deniedOauthProvider)
|
|
106
|
+
: undefined;
|
|
104
107
|
const { selectedWalletConnector: walletConnector, socialMediaIconUrl, notInTheListImageUrl, accessDeniedButton, } = useInternalDynamicContext();
|
|
105
108
|
const { displayedDestination: email } = useVerification();
|
|
106
109
|
const { goToInitialView } = useViewContext();
|