eocene-auth-sdk 0.4.0 → 0.5.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/dist/index.d.ts +123 -10
- package/dist/index.js +664 -47
- package/dist/index.js.map +1 -1
- package/dist/styles.css +73 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2600,6 +2600,16 @@ function normalizeErrorCode(body, status) {
|
|
|
2600
2600
|
if (raw === "PLAN_USER_LIMIT" || raw === "plan_user_limit") return "plan_user_limit";
|
|
2601
2601
|
if (raw === "PLAN_PROJECT_LIMIT" || raw === "plan_project_limit") return "plan_project_limit";
|
|
2602
2602
|
if (raw === "RATE_LIMITED" || raw === "rate_limited") return "rate_limited";
|
|
2603
|
+
if (raw === "reset_cooldown") return "reset_cooldown";
|
|
2604
|
+
if (raw === "reset_code_invalid") return "reset_code_invalid";
|
|
2605
|
+
if (raw === "reset_code_expired") return "reset_code_expired";
|
|
2606
|
+
if (raw === "reset_code_locked") return "reset_code_locked";
|
|
2607
|
+
if (raw === "reset_channel_unavailable") return "reset_channel_unavailable";
|
|
2608
|
+
if (raw === "reset_delivery_failed") return "reset_delivery_failed";
|
|
2609
|
+
if (raw === "password_not_enabled") return "password_not_enabled";
|
|
2610
|
+
if (raw === "recovery_contact_required") return "recovery_contact_required";
|
|
2611
|
+
if (raw === "invalid_recovery_email") return "invalid_recovery_email";
|
|
2612
|
+
if (raw === "password_too_short") return "password_too_short";
|
|
2603
2613
|
if (raw === "password_locked" || raw.includes("password_locked")) return "password_locked";
|
|
2604
2614
|
if (raw === "password_invalid") return "password_invalid";
|
|
2605
2615
|
if (raw.includes("at least 6")) return "password_too_short";
|
|
@@ -2887,7 +2897,8 @@ var WaasClient = class {
|
|
|
2887
2897
|
walletId: me.wallet?.walletId,
|
|
2888
2898
|
address: me.wallet?.address,
|
|
2889
2899
|
epoch: me.wallet?.epoch,
|
|
2890
|
-
passwordEnabled: me.wallet?.passwordEnabled ?? false
|
|
2900
|
+
passwordEnabled: me.wallet?.passwordEnabled ?? false,
|
|
2901
|
+
recovery: me.wallet?.recovery
|
|
2891
2902
|
};
|
|
2892
2903
|
return this.getState();
|
|
2893
2904
|
}
|
|
@@ -2897,29 +2908,71 @@ var WaasClient = class {
|
|
|
2897
2908
|
headers: this.authHeaders()
|
|
2898
2909
|
});
|
|
2899
2910
|
}
|
|
2900
|
-
async ensureWallet() {
|
|
2911
|
+
async ensureWallet(opts) {
|
|
2901
2912
|
this.requireSession();
|
|
2913
|
+
const hasInitData = Boolean(opts?.telegramInitData);
|
|
2902
2914
|
const out = await this.authed(`${this.controlBaseUrl}/wallet/ensure`, {
|
|
2903
2915
|
method: "POST",
|
|
2904
|
-
headers: this.authHeaders()
|
|
2916
|
+
headers: hasInitData ? { ...this.authHeaders(), "content-type": "application/json" } : this.authHeaders(),
|
|
2917
|
+
body: hasInitData ? JSON.stringify({ telegramInitData: opts.telegramInitData }) : void 0
|
|
2905
2918
|
});
|
|
2906
2919
|
this.state = {
|
|
2907
2920
|
...this.state,
|
|
2908
2921
|
walletId: out.walletId,
|
|
2909
2922
|
address: out.address,
|
|
2910
2923
|
epoch: out.epoch,
|
|
2911
|
-
passwordEnabled: out.passwordEnabled
|
|
2924
|
+
passwordEnabled: out.passwordEnabled,
|
|
2925
|
+
recovery: out.recovery ?? this.state?.recovery
|
|
2926
|
+
};
|
|
2927
|
+
return {
|
|
2928
|
+
walletId: out.walletId,
|
|
2929
|
+
address: out.address,
|
|
2930
|
+
passwordEnabled: out.passwordEnabled,
|
|
2931
|
+
recovery: out.recovery
|
|
2912
2932
|
};
|
|
2913
|
-
return { walletId: out.walletId, address: out.address, passwordEnabled: out.passwordEnabled };
|
|
2914
2933
|
}
|
|
2915
|
-
async setPassword(password, currentPassword) {
|
|
2934
|
+
async setPassword(password, currentPassword, recoveryBind) {
|
|
2916
2935
|
this.requireSession();
|
|
2917
|
-
await this.authed(`${this.controlBaseUrl}/wallet/password/set`, {
|
|
2936
|
+
const out = await this.authed(`${this.controlBaseUrl}/wallet/password/set`, {
|
|
2918
2937
|
method: "POST",
|
|
2919
2938
|
headers: { ...this.authHeaders(), "content-type": "application/json" },
|
|
2920
|
-
body: JSON.stringify({
|
|
2939
|
+
body: JSON.stringify({
|
|
2940
|
+
password,
|
|
2941
|
+
currentPassword,
|
|
2942
|
+
recoveryEmail: recoveryBind?.recoveryEmail,
|
|
2943
|
+
recoveryCode: recoveryBind?.recoveryCode
|
|
2944
|
+
})
|
|
2921
2945
|
});
|
|
2922
|
-
if (this.state)
|
|
2946
|
+
if (this.state) {
|
|
2947
|
+
this.state.passwordEnabled = true;
|
|
2948
|
+
if (out.recovery) this.state.recovery = out.recovery;
|
|
2949
|
+
}
|
|
2950
|
+
}
|
|
2951
|
+
async requestRecoveryEmailBind(email) {
|
|
2952
|
+
this.requireSession();
|
|
2953
|
+
return this.authed(
|
|
2954
|
+
`${this.controlBaseUrl}/wallet/recovery/email/request`,
|
|
2955
|
+
{
|
|
2956
|
+
method: "POST",
|
|
2957
|
+
headers: { ...this.authHeaders(), "content-type": "application/json" },
|
|
2958
|
+
body: JSON.stringify({ email })
|
|
2959
|
+
}
|
|
2960
|
+
);
|
|
2961
|
+
}
|
|
2962
|
+
async confirmRecoveryEmailBind(code, email) {
|
|
2963
|
+
this.requireSession();
|
|
2964
|
+
const out = await this.authed(
|
|
2965
|
+
`${this.controlBaseUrl}/wallet/recovery/email/confirm`,
|
|
2966
|
+
{
|
|
2967
|
+
method: "POST",
|
|
2968
|
+
headers: { ...this.authHeaders(), "content-type": "application/json" },
|
|
2969
|
+
body: JSON.stringify({ code, email })
|
|
2970
|
+
}
|
|
2971
|
+
);
|
|
2972
|
+
if (this.state && out.recovery) {
|
|
2973
|
+
this.state.recovery = out.recovery;
|
|
2974
|
+
}
|
|
2975
|
+
return out;
|
|
2923
2976
|
}
|
|
2924
2977
|
async clearPassword(password) {
|
|
2925
2978
|
this.requireSession();
|
|
@@ -2930,6 +2983,36 @@ var WaasClient = class {
|
|
|
2930
2983
|
});
|
|
2931
2984
|
if (this.state) this.state.passwordEnabled = false;
|
|
2932
2985
|
}
|
|
2986
|
+
async requestPasswordReset(channel, email) {
|
|
2987
|
+
this.requireSession();
|
|
2988
|
+
const payload = {};
|
|
2989
|
+
if (channel) payload.channel = channel;
|
|
2990
|
+
if (email && email.trim()) payload.email = email.trim();
|
|
2991
|
+
return this.authed(
|
|
2992
|
+
`${this.controlBaseUrl}/wallet/password/reset/request`,
|
|
2993
|
+
{
|
|
2994
|
+
method: "POST",
|
|
2995
|
+
headers: { ...this.authHeaders(), "content-type": "application/json" },
|
|
2996
|
+
body: JSON.stringify(payload)
|
|
2997
|
+
}
|
|
2998
|
+
);
|
|
2999
|
+
}
|
|
3000
|
+
async confirmPasswordReset(code, newPassword) {
|
|
3001
|
+
this.requireSession();
|
|
3002
|
+
const out = await this.authed(
|
|
3003
|
+
`${this.controlBaseUrl}/wallet/password/reset/confirm`,
|
|
3004
|
+
{
|
|
3005
|
+
method: "POST",
|
|
3006
|
+
headers: { ...this.authHeaders(), "content-type": "application/json" },
|
|
3007
|
+
body: JSON.stringify({ code, newPassword })
|
|
3008
|
+
}
|
|
3009
|
+
);
|
|
3010
|
+
if (this.state) {
|
|
3011
|
+
this.state.passwordEnabled = out.passwordEnabled;
|
|
3012
|
+
if (out.recovery) this.state.recovery = out.recovery;
|
|
3013
|
+
}
|
|
3014
|
+
return out;
|
|
3015
|
+
}
|
|
2933
3016
|
async signMessage(message, opts) {
|
|
2934
3017
|
const digest = hashPersonalMessage(message);
|
|
2935
3018
|
return this.signDigestHex(digestToHex(digest), opts);
|
|
@@ -3113,7 +3196,8 @@ var AuthClient = class {
|
|
|
3113
3196
|
email: s.email,
|
|
3114
3197
|
address: s.address,
|
|
3115
3198
|
walletId: s.walletId,
|
|
3116
|
-
passwordEnabled: s.passwordEnabled
|
|
3199
|
+
passwordEnabled: s.passwordEnabled,
|
|
3200
|
+
recovery: s.recovery
|
|
3117
3201
|
};
|
|
3118
3202
|
}
|
|
3119
3203
|
/** Current EIP-1193 chain. Changes via wallet_switchEthereumChain. */
|
|
@@ -3226,7 +3310,9 @@ var AuthClient = class {
|
|
|
3226
3310
|
}
|
|
3227
3311
|
}
|
|
3228
3312
|
}
|
|
3229
|
-
const wallet = await this.client.ensureWallet(
|
|
3313
|
+
const wallet = await this.client.ensureWallet({
|
|
3314
|
+
telegramInitData: getTelegramInitData() ?? void 0
|
|
3315
|
+
});
|
|
3230
3316
|
this.persist();
|
|
3231
3317
|
this.active = true;
|
|
3232
3318
|
this.provider = null;
|
|
@@ -3257,7 +3343,7 @@ var AuthClient = class {
|
|
|
3257
3343
|
throw new Error(body.error ?? `telegram miniapp login HTTP ${res.status}`);
|
|
3258
3344
|
}
|
|
3259
3345
|
await this.client.loginWithSessionToken(body.sessionToken);
|
|
3260
|
-
const wallet = await this.client.ensureWallet();
|
|
3346
|
+
const wallet = await this.client.ensureWallet({ telegramInitData: data });
|
|
3261
3347
|
this.persist();
|
|
3262
3348
|
this.active = true;
|
|
3263
3349
|
this.provider = null;
|
|
@@ -3272,7 +3358,9 @@ var AuthClient = class {
|
|
|
3272
3358
|
if (!sessionToken) throw new Error("missing waas_session in callback");
|
|
3273
3359
|
const provider = params.get("waas_provider") ?? void 0;
|
|
3274
3360
|
await this.client.loginWithSessionToken(decodeURIComponent(sessionToken));
|
|
3275
|
-
const wallet = await this.client.ensureWallet(
|
|
3361
|
+
const wallet = await this.client.ensureWallet({
|
|
3362
|
+
telegramInitData: getTelegramInitData() ?? void 0
|
|
3363
|
+
});
|
|
3276
3364
|
this.persist();
|
|
3277
3365
|
this.active = true;
|
|
3278
3366
|
this.provider = null;
|
|
@@ -3356,7 +3444,9 @@ var AuthClient = class {
|
|
|
3356
3444
|
const result = await res.json().catch(() => ({}));
|
|
3357
3445
|
if (!res.ok || !result.sessionToken) throw new Error(`session refresh HTTP ${res.status}`);
|
|
3358
3446
|
await this.client.loginWithSessionToken(result.sessionToken);
|
|
3359
|
-
await this.client.ensureWallet(
|
|
3447
|
+
await this.client.ensureWallet({
|
|
3448
|
+
telegramInitData: getTelegramInitData() ?? void 0
|
|
3449
|
+
});
|
|
3360
3450
|
this.persist();
|
|
3361
3451
|
this.active = true;
|
|
3362
3452
|
this.provider = null;
|
|
@@ -3386,14 +3476,52 @@ var AuthClient = class {
|
|
|
3386
3476
|
this.markActive(false);
|
|
3387
3477
|
}
|
|
3388
3478
|
}
|
|
3389
|
-
async setPassword(password, currentPassword) {
|
|
3390
|
-
await this.client.setPassword(password, currentPassword);
|
|
3479
|
+
async setPassword(password, currentPassword, recoveryBind) {
|
|
3480
|
+
await this.client.setPassword(password, currentPassword, recoveryBind);
|
|
3391
3481
|
this.persist();
|
|
3392
3482
|
}
|
|
3393
3483
|
async clearPassword(password) {
|
|
3394
3484
|
await this.client.clearPassword(password);
|
|
3395
3485
|
this.persist();
|
|
3396
3486
|
}
|
|
3487
|
+
async requestRecoveryEmailBind(email) {
|
|
3488
|
+
return this.client.requestRecoveryEmailBind(email);
|
|
3489
|
+
}
|
|
3490
|
+
async confirmRecoveryEmailBind(code, email) {
|
|
3491
|
+
const out = await this.client.confirmRecoveryEmailBind(code, email);
|
|
3492
|
+
this.persist();
|
|
3493
|
+
return out;
|
|
3494
|
+
}
|
|
3495
|
+
async requestPasswordReset(channel, email) {
|
|
3496
|
+
return this.client.requestPasswordReset(channel, email);
|
|
3497
|
+
}
|
|
3498
|
+
async confirmPasswordReset(code, newPassword) {
|
|
3499
|
+
const out = await this.client.confirmPasswordReset(code, newPassword);
|
|
3500
|
+
this.persist();
|
|
3501
|
+
return out;
|
|
3502
|
+
}
|
|
3503
|
+
async refreshUser() {
|
|
3504
|
+
const s = this.client.getState();
|
|
3505
|
+
if (!s?.sessionToken) return null;
|
|
3506
|
+
try {
|
|
3507
|
+
const me = await this.client.fetchMe();
|
|
3508
|
+
const cur = this.client.getState();
|
|
3509
|
+
if (cur && me.wallet) {
|
|
3510
|
+
this.client.hydrate({
|
|
3511
|
+
...cur,
|
|
3512
|
+
email: me.email ?? cur.email,
|
|
3513
|
+
walletId: me.wallet.walletId,
|
|
3514
|
+
address: me.wallet.address,
|
|
3515
|
+
epoch: me.wallet.epoch,
|
|
3516
|
+
passwordEnabled: me.wallet.passwordEnabled,
|
|
3517
|
+
recovery: me.wallet.recovery
|
|
3518
|
+
});
|
|
3519
|
+
this.persist();
|
|
3520
|
+
}
|
|
3521
|
+
} catch {
|
|
3522
|
+
}
|
|
3523
|
+
return this.getUser();
|
|
3524
|
+
}
|
|
3397
3525
|
};
|
|
3398
3526
|
|
|
3399
3527
|
// src/provider/createProvider.ts
|
|
@@ -3412,6 +3540,27 @@ function formatAuthError(e, labels) {
|
|
|
3412
3540
|
if (e.code === "plan_project_limit") {
|
|
3413
3541
|
return "Project limit reached on this Eocene account.";
|
|
3414
3542
|
}
|
|
3543
|
+
if (e.code === "reset_code_invalid") return labels.passwordSettingsResetCodeInvalid;
|
|
3544
|
+
if (e.code === "reset_code_expired") return labels.passwordSettingsResetCodeExpired;
|
|
3545
|
+
if (e.code === "reset_code_locked") return labels.passwordSettingsResetCodeLocked;
|
|
3546
|
+
if (e.code === "reset_cooldown") {
|
|
3547
|
+
return labels.passwordSettingsResetCooldown.replace(
|
|
3548
|
+
"{seconds}",
|
|
3549
|
+
String(e.retryAfterSec ?? 60)
|
|
3550
|
+
);
|
|
3551
|
+
}
|
|
3552
|
+
if (e.code === "reset_channel_unavailable") {
|
|
3553
|
+
return labels.passwordSettingsResetChannelUnavailable;
|
|
3554
|
+
}
|
|
3555
|
+
if (e.code === "reset_delivery_failed") {
|
|
3556
|
+
return e.message || labels.passwordSettingsResetDeliveryFailed;
|
|
3557
|
+
}
|
|
3558
|
+
if (e.code === "recovery_contact_required") {
|
|
3559
|
+
return labels.passwordSettingsRecoveryRequired;
|
|
3560
|
+
}
|
|
3561
|
+
if (e.code === "invalid_recovery_email") {
|
|
3562
|
+
return labels.passwordSettingsInvalidRecoveryEmail;
|
|
3563
|
+
}
|
|
3415
3564
|
return formatSignAuthError(
|
|
3416
3565
|
{
|
|
3417
3566
|
code: e.code,
|
|
@@ -3673,28 +3822,100 @@ function AuthLoginPanel({
|
|
|
3673
3822
|
function SetPasswordModal({
|
|
3674
3823
|
open,
|
|
3675
3824
|
passwordEnabled,
|
|
3825
|
+
initialMode,
|
|
3826
|
+
recovery,
|
|
3676
3827
|
labels,
|
|
3677
3828
|
busy,
|
|
3829
|
+
sendingResetCode = false,
|
|
3830
|
+
resetSent = null,
|
|
3831
|
+
sendingRecoveryBindCode = false,
|
|
3832
|
+
recoveryBindSent = null,
|
|
3678
3833
|
error,
|
|
3679
3834
|
onSubmitSet,
|
|
3680
3835
|
onSubmitClear,
|
|
3836
|
+
onRequestResetCode,
|
|
3837
|
+
onSubmitReset,
|
|
3838
|
+
onRequestRecoveryEmailBind,
|
|
3839
|
+
onConfirmRecoveryEmailBind,
|
|
3681
3840
|
onClose
|
|
3682
3841
|
}) {
|
|
3683
3842
|
const [password, setPassword] = useState("");
|
|
3684
3843
|
const [confirm, setConfirm] = useState("");
|
|
3685
3844
|
const [current, setCurrent] = useState("");
|
|
3845
|
+
const [code, setCode] = useState("");
|
|
3846
|
+
const [recoveryEmail, setRecoveryEmail] = useState("");
|
|
3847
|
+
const [recoveryCode, setRecoveryCode] = useState("");
|
|
3848
|
+
const [selectedChannel, setSelectedChannel] = useState(
|
|
3849
|
+
void 0
|
|
3850
|
+
);
|
|
3686
3851
|
const [mode, setMode] = useState("set");
|
|
3852
|
+
const [cooldownLeft, setCooldownLeft] = useState(0);
|
|
3853
|
+
const [bindCooldownLeft, setBindCooldownLeft] = useState(0);
|
|
3687
3854
|
useEffect(() => {
|
|
3688
3855
|
if (!open) return;
|
|
3689
3856
|
setPassword("");
|
|
3690
3857
|
setConfirm("");
|
|
3691
3858
|
setCurrent("");
|
|
3692
|
-
|
|
3693
|
-
|
|
3859
|
+
setCode("");
|
|
3860
|
+
setRecoveryEmail("");
|
|
3861
|
+
setRecoveryCode("");
|
|
3862
|
+
setSelectedChannel(recovery?.defaultChannel ?? void 0);
|
|
3863
|
+
setMode(passwordEnabled && initialMode ? initialMode : "set");
|
|
3864
|
+
}, [open, passwordEnabled, initialMode, recovery?.defaultChannel]);
|
|
3865
|
+
useEffect(() => {
|
|
3866
|
+
if (!open || !resetSent) {
|
|
3867
|
+
setCooldownLeft(0);
|
|
3868
|
+
return;
|
|
3869
|
+
}
|
|
3870
|
+
const update = () => {
|
|
3871
|
+
const rem = Math.max(
|
|
3872
|
+
0,
|
|
3873
|
+
Math.ceil((resetSent.sentAt + resetSent.cooldownSec * 1e3 - Date.now()) / 1e3)
|
|
3874
|
+
);
|
|
3875
|
+
setCooldownLeft(rem);
|
|
3876
|
+
};
|
|
3877
|
+
update();
|
|
3878
|
+
const timer = window.setInterval(update, 1e3);
|
|
3879
|
+
return () => window.clearInterval(timer);
|
|
3880
|
+
}, [open, resetSent]);
|
|
3881
|
+
useEffect(() => {
|
|
3882
|
+
if (!open || !recoveryBindSent) {
|
|
3883
|
+
setBindCooldownLeft(0);
|
|
3884
|
+
return;
|
|
3885
|
+
}
|
|
3886
|
+
const update = () => {
|
|
3887
|
+
const rem = Math.max(
|
|
3888
|
+
0,
|
|
3889
|
+
Math.ceil(
|
|
3890
|
+
(recoveryBindSent.sentAt + recoveryBindSent.cooldownSec * 1e3 - Date.now()) / 1e3
|
|
3891
|
+
)
|
|
3892
|
+
);
|
|
3893
|
+
setBindCooldownLeft(rem);
|
|
3894
|
+
};
|
|
3895
|
+
update();
|
|
3896
|
+
const timer = window.setInterval(update, 1e3);
|
|
3897
|
+
return () => window.clearInterval(timer);
|
|
3898
|
+
}, [open, recoveryBindSent]);
|
|
3694
3899
|
if (!open) return null;
|
|
3900
|
+
const hasBoundRecovery = Boolean(recovery?.hasRecovery);
|
|
3901
|
+
const needsRecoveryBind = Boolean(
|
|
3902
|
+
mode === "set" && !hasBoundRecovery && onRequestRecoveryEmailBind
|
|
3903
|
+
);
|
|
3904
|
+
const needsResetEmailInput = Boolean(mode === "reset" && !hasBoundRecovery);
|
|
3695
3905
|
const mismatch = password.length > 0 && confirm.length > 0 && password !== confirm;
|
|
3696
|
-
const
|
|
3906
|
+
const normalizedCode = code.trim();
|
|
3907
|
+
const validCode = /^\d{6}$/.test(normalizedCode);
|
|
3908
|
+
const normalizedBindCode = recoveryCode.trim();
|
|
3909
|
+
const validBindCode = /^\d{6}$/.test(normalizedBindCode);
|
|
3910
|
+
const validRecoveryEmail = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(recoveryEmail.trim());
|
|
3911
|
+
const canSet = password.length >= 6 && password === confirm && (!passwordEnabled || current.length > 0) && (!needsRecoveryBind || validRecoveryEmail && validBindCode) && !busy;
|
|
3912
|
+
const canBindEmailOnly = needsRecoveryBind && validRecoveryEmail && validBindCode && password.length === 0 && Boolean(onConfirmRecoveryEmailBind) && !busy;
|
|
3697
3913
|
const canClear = passwordEnabled && current.length > 0 && !busy;
|
|
3914
|
+
const canResetSet = passwordEnabled && validCode && password.length >= 6 && password === confirm && (!needsResetEmailInput || validRecoveryEmail) && !busy;
|
|
3915
|
+
const canResetClear = passwordEnabled && validCode && (!needsResetEmailInput || validRecoveryEmail) && !busy;
|
|
3916
|
+
const resetHintText = mode === "reset" && resetSent ? (resetSent.channel === "telegram" ? labels.passwordSettingsCodeSentTelegram : labels.passwordSettingsCodeSentEmail).replace("{target}", resetSent.maskedTarget) : mode === "reset" ? needsResetEmailInput ? labels.passwordSettingsBindEmailHint : labels.passwordSettingsResetHint : needsRecoveryBind ? recoveryBindSent ? labels.passwordSettingsCodeSentEmail.replace("{target}", recoveryBindSent.maskedTarget) : labels.passwordSettingsBindEmailHint : passwordEnabled ? labels.passwordSettingsEnabledHint : labels.passwordSettingsDisabledHint;
|
|
3917
|
+
const dualChannels = Boolean(recovery?.channels && recovery.channels.length > 1);
|
|
3918
|
+
const effectiveResetChannel = selectedChannel ?? recovery?.defaultChannel ?? void 0;
|
|
3698
3919
|
return /* @__PURE__ */ jsxs("div", { className: "auth-sdk-root", role: "presentation", children: [
|
|
3699
3920
|
/* @__PURE__ */ jsx("div", { className: "auth-sdk-backdrop", onClick: busy ? void 0 : onClose, "aria-hidden": true }),
|
|
3700
3921
|
/* @__PURE__ */ jsxs(
|
|
@@ -3712,7 +3933,7 @@ function SetPasswordModal({
|
|
|
3712
3933
|
/* @__PURE__ */ jsx("h2", { id: "auth-sdk-password-title", className: "auth-sdk-sign-title", children: labels.passwordSettingsTitle })
|
|
3713
3934
|
] })
|
|
3714
3935
|
] }),
|
|
3715
|
-
/* @__PURE__ */ jsx("p", { className: "auth-sdk-sign-subtitle", children:
|
|
3936
|
+
/* @__PURE__ */ jsx("p", { className: "auth-sdk-sign-subtitle", children: resetHintText }),
|
|
3716
3937
|
passwordEnabled ? /* @__PURE__ */ jsxs("div", { className: "auth-sdk-mode-tabs", role: "tablist", children: [
|
|
3717
3938
|
/* @__PURE__ */ jsx(
|
|
3718
3939
|
"button",
|
|
@@ -3737,14 +3958,87 @@ function SetPasswordModal({
|
|
|
3737
3958
|
disabled: busy,
|
|
3738
3959
|
children: labels.passwordSettingsClear
|
|
3739
3960
|
}
|
|
3740
|
-
)
|
|
3961
|
+
),
|
|
3962
|
+
onRequestResetCode && onSubmitReset ? /* @__PURE__ */ jsx(
|
|
3963
|
+
"button",
|
|
3964
|
+
{
|
|
3965
|
+
type: "button",
|
|
3966
|
+
role: "tab",
|
|
3967
|
+
className: `auth-sdk-mode-tab${mode === "reset" ? " is-active" : ""}`,
|
|
3968
|
+
"aria-selected": mode === "reset",
|
|
3969
|
+
onClick: () => setMode("reset"),
|
|
3970
|
+
disabled: busy,
|
|
3971
|
+
children: labels.passwordSettingsReset
|
|
3972
|
+
}
|
|
3973
|
+
) : null
|
|
3741
3974
|
] }) : null,
|
|
3742
3975
|
mode === "set" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3743
|
-
|
|
3744
|
-
/* @__PURE__ */
|
|
3976
|
+
needsRecoveryBind ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3977
|
+
/* @__PURE__ */ jsxs("div", { className: "auth-sdk-password", children: [
|
|
3978
|
+
/* @__PURE__ */ jsx("span", { children: labels.passwordSettingsBindEmailLabel }),
|
|
3979
|
+
/* @__PURE__ */ jsxs("div", { className: "auth-sdk-code-row", children: [
|
|
3980
|
+
/* @__PURE__ */ jsx(
|
|
3981
|
+
"input",
|
|
3982
|
+
{
|
|
3983
|
+
type: "email",
|
|
3984
|
+
autoComplete: "email",
|
|
3985
|
+
placeholder: labels.passwordSettingsBindEmailPlaceholder,
|
|
3986
|
+
value: recoveryEmail,
|
|
3987
|
+
onChange: (e) => setRecoveryEmail(e.target.value),
|
|
3988
|
+
disabled: busy,
|
|
3989
|
+
autoFocus: !passwordEnabled
|
|
3990
|
+
}
|
|
3991
|
+
),
|
|
3992
|
+
/* @__PURE__ */ jsx(
|
|
3993
|
+
"button",
|
|
3994
|
+
{
|
|
3995
|
+
type: "button",
|
|
3996
|
+
className: "auth-sdk-code-send-btn",
|
|
3997
|
+
disabled: busy || sendingRecoveryBindCode || bindCooldownLeft > 0 || !validRecoveryEmail,
|
|
3998
|
+
onClick: () => void onRequestRecoveryEmailBind?.(recoveryEmail.trim()),
|
|
3999
|
+
children: sendingRecoveryBindCode ? labels.passwordSettingsSendingCode : bindCooldownLeft > 0 ? labels.passwordSettingsResendCooldown.replace(
|
|
4000
|
+
"{seconds}",
|
|
4001
|
+
String(bindCooldownLeft)
|
|
4002
|
+
) : recoveryBindSent ? labels.passwordSettingsResendCode : labels.passwordSettingsSendCode
|
|
4003
|
+
}
|
|
4004
|
+
)
|
|
4005
|
+
] })
|
|
4006
|
+
] }),
|
|
4007
|
+
/* @__PURE__ */ jsxs("label", { className: "auth-sdk-password", children: [
|
|
4008
|
+
/* @__PURE__ */ jsx("span", { children: labels.passwordSettingsCodeLabel }),
|
|
4009
|
+
/* @__PURE__ */ jsx(
|
|
4010
|
+
"input",
|
|
4011
|
+
{
|
|
4012
|
+
type: "text",
|
|
4013
|
+
inputMode: "numeric",
|
|
4014
|
+
maxLength: 6,
|
|
4015
|
+
autoComplete: "one-time-code",
|
|
4016
|
+
placeholder: labels.passwordSettingsCodePlaceholder,
|
|
4017
|
+
value: recoveryCode,
|
|
4018
|
+
onChange: (e) => setRecoveryCode(e.target.value.replace(/\D+/g, "").slice(0, 6)),
|
|
4019
|
+
disabled: busy
|
|
4020
|
+
}
|
|
4021
|
+
)
|
|
4022
|
+
] })
|
|
4023
|
+
] }) : null,
|
|
4024
|
+
passwordEnabled ? /* @__PURE__ */ jsxs("div", { className: "auth-sdk-password", children: [
|
|
4025
|
+
/* @__PURE__ */ jsxs("div", { className: "auth-sdk-password-label-row", children: [
|
|
4026
|
+
/* @__PURE__ */ jsx("label", { htmlFor: "auth-sdk-pw-current", children: labels.passwordSettingsCurrentLabel }),
|
|
4027
|
+
onRequestResetCode && onSubmitReset ? /* @__PURE__ */ jsx(
|
|
4028
|
+
"button",
|
|
4029
|
+
{
|
|
4030
|
+
type: "button",
|
|
4031
|
+
className: "auth-sdk-forgot-btn",
|
|
4032
|
+
onClick: () => setMode("reset"),
|
|
4033
|
+
disabled: busy,
|
|
4034
|
+
children: labels.signForgotPassword
|
|
4035
|
+
}
|
|
4036
|
+
) : null
|
|
4037
|
+
] }),
|
|
3745
4038
|
/* @__PURE__ */ jsx(
|
|
3746
4039
|
"input",
|
|
3747
4040
|
{
|
|
4041
|
+
id: "auth-sdk-pw-current",
|
|
3748
4042
|
type: "password",
|
|
3749
4043
|
autoComplete: "current-password",
|
|
3750
4044
|
placeholder: labels.passwordSettingsCurrentPlaceholder,
|
|
@@ -3766,7 +4060,7 @@ function SetPasswordModal({
|
|
|
3766
4060
|
value: password,
|
|
3767
4061
|
onChange: (e) => setPassword(e.target.value),
|
|
3768
4062
|
disabled: busy,
|
|
3769
|
-
autoFocus: !passwordEnabled
|
|
4063
|
+
autoFocus: !passwordEnabled && !needsRecoveryBind
|
|
3770
4064
|
}
|
|
3771
4065
|
)
|
|
3772
4066
|
] }),
|
|
@@ -3785,11 +4079,24 @@ function SetPasswordModal({
|
|
|
3785
4079
|
)
|
|
3786
4080
|
] }),
|
|
3787
4081
|
mismatch ? /* @__PURE__ */ jsx("p", { className: "auth-sdk-sign-error", children: labels.passwordSettingsMismatch }) : null
|
|
3788
|
-
] }) : /* @__PURE__ */ jsxs("
|
|
3789
|
-
/* @__PURE__ */
|
|
4082
|
+
] }) : mode === "clear" ? /* @__PURE__ */ jsxs("div", { className: "auth-sdk-password", children: [
|
|
4083
|
+
/* @__PURE__ */ jsxs("div", { className: "auth-sdk-password-label-row", children: [
|
|
4084
|
+
/* @__PURE__ */ jsx("label", { htmlFor: "auth-sdk-pw-clear-current", children: labels.passwordSettingsCurrentLabel }),
|
|
4085
|
+
onRequestResetCode && onSubmitReset ? /* @__PURE__ */ jsx(
|
|
4086
|
+
"button",
|
|
4087
|
+
{
|
|
4088
|
+
type: "button",
|
|
4089
|
+
className: "auth-sdk-forgot-btn",
|
|
4090
|
+
onClick: () => setMode("reset"),
|
|
4091
|
+
disabled: busy,
|
|
4092
|
+
children: labels.signForgotPassword
|
|
4093
|
+
}
|
|
4094
|
+
) : null
|
|
4095
|
+
] }),
|
|
3790
4096
|
/* @__PURE__ */ jsx(
|
|
3791
4097
|
"input",
|
|
3792
4098
|
{
|
|
4099
|
+
id: "auth-sdk-pw-clear-current",
|
|
3793
4100
|
type: "password",
|
|
3794
4101
|
autoComplete: "current-password",
|
|
3795
4102
|
placeholder: labels.passwordSettingsCurrentPlaceholder,
|
|
@@ -3799,6 +4106,121 @@ function SetPasswordModal({
|
|
|
3799
4106
|
autoFocus: true
|
|
3800
4107
|
}
|
|
3801
4108
|
)
|
|
4109
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
4110
|
+
dualChannels ? /* @__PURE__ */ jsxs("div", { className: "auth-sdk-mode-tabs", role: "radiogroup", children: [
|
|
4111
|
+
/* @__PURE__ */ jsxs(
|
|
4112
|
+
"button",
|
|
4113
|
+
{
|
|
4114
|
+
type: "button",
|
|
4115
|
+
className: `auth-sdk-mode-tab${effectiveResetChannel === "email" ? " is-active" : ""}`,
|
|
4116
|
+
onClick: () => setSelectedChannel("email"),
|
|
4117
|
+
disabled: busy || sendingResetCode,
|
|
4118
|
+
children: [
|
|
4119
|
+
"Email",
|
|
4120
|
+
recovery?.maskedEmail ? ` (${recovery.maskedEmail})` : ""
|
|
4121
|
+
]
|
|
4122
|
+
}
|
|
4123
|
+
),
|
|
4124
|
+
/* @__PURE__ */ jsx(
|
|
4125
|
+
"button",
|
|
4126
|
+
{
|
|
4127
|
+
type: "button",
|
|
4128
|
+
className: `auth-sdk-mode-tab${effectiveResetChannel === "telegram" ? " is-active" : ""}`,
|
|
4129
|
+
onClick: () => setSelectedChannel("telegram"),
|
|
4130
|
+
disabled: busy || sendingResetCode,
|
|
4131
|
+
children: recovery?.maskedTelegram ?? "Telegram"
|
|
4132
|
+
}
|
|
4133
|
+
)
|
|
4134
|
+
] }) : null,
|
|
4135
|
+
needsResetEmailInput ? /* @__PURE__ */ jsxs("label", { className: "auth-sdk-password", children: [
|
|
4136
|
+
/* @__PURE__ */ jsx("span", { children: labels.passwordSettingsBindEmailLabel }),
|
|
4137
|
+
/* @__PURE__ */ jsx(
|
|
4138
|
+
"input",
|
|
4139
|
+
{
|
|
4140
|
+
type: "email",
|
|
4141
|
+
autoComplete: "email",
|
|
4142
|
+
placeholder: labels.passwordSettingsBindEmailPlaceholder,
|
|
4143
|
+
value: recoveryEmail,
|
|
4144
|
+
onChange: (e) => setRecoveryEmail(e.target.value),
|
|
4145
|
+
disabled: busy,
|
|
4146
|
+
autoFocus: true
|
|
4147
|
+
}
|
|
4148
|
+
)
|
|
4149
|
+
] }) : null,
|
|
4150
|
+
/* @__PURE__ */ jsxs("div", { className: "auth-sdk-password", children: [
|
|
4151
|
+
/* @__PURE__ */ jsx("span", { children: labels.passwordSettingsCodeLabel }),
|
|
4152
|
+
/* @__PURE__ */ jsxs("div", { className: "auth-sdk-code-row", children: [
|
|
4153
|
+
/* @__PURE__ */ jsx(
|
|
4154
|
+
"input",
|
|
4155
|
+
{
|
|
4156
|
+
type: "text",
|
|
4157
|
+
inputMode: "numeric",
|
|
4158
|
+
maxLength: 6,
|
|
4159
|
+
autoComplete: "one-time-code",
|
|
4160
|
+
placeholder: labels.passwordSettingsCodePlaceholder,
|
|
4161
|
+
value: code,
|
|
4162
|
+
onChange: (e) => setCode(e.target.value.replace(/\D+/g, "").slice(0, 6)),
|
|
4163
|
+
disabled: busy,
|
|
4164
|
+
autoFocus: !needsResetEmailInput
|
|
4165
|
+
}
|
|
4166
|
+
),
|
|
4167
|
+
/* @__PURE__ */ jsx(
|
|
4168
|
+
"button",
|
|
4169
|
+
{
|
|
4170
|
+
type: "button",
|
|
4171
|
+
className: "auth-sdk-code-send-btn",
|
|
4172
|
+
disabled: busy || sendingResetCode || cooldownLeft > 0 || needsResetEmailInput && !validRecoveryEmail,
|
|
4173
|
+
onClick: () => void onRequestResetCode?.(
|
|
4174
|
+
effectiveResetChannel,
|
|
4175
|
+
needsResetEmailInput ? recoveryEmail.trim() : void 0
|
|
4176
|
+
),
|
|
4177
|
+
children: sendingResetCode ? labels.passwordSettingsSendingCode : cooldownLeft > 0 ? labels.passwordSettingsResendCooldown.replace(
|
|
4178
|
+
"{seconds}",
|
|
4179
|
+
String(cooldownLeft)
|
|
4180
|
+
) : resetSent ? labels.passwordSettingsResendCode : labels.passwordSettingsSendCode
|
|
4181
|
+
}
|
|
4182
|
+
)
|
|
4183
|
+
] })
|
|
4184
|
+
] }),
|
|
4185
|
+
/* @__PURE__ */ jsxs("label", { className: "auth-sdk-password", children: [
|
|
4186
|
+
/* @__PURE__ */ jsx("span", { children: labels.passwordSettingsNewLabel }),
|
|
4187
|
+
/* @__PURE__ */ jsx(
|
|
4188
|
+
"input",
|
|
4189
|
+
{
|
|
4190
|
+
type: "password",
|
|
4191
|
+
autoComplete: "new-password",
|
|
4192
|
+
placeholder: labels.passwordSettingsNewPlaceholder,
|
|
4193
|
+
value: password,
|
|
4194
|
+
onChange: (e) => setPassword(e.target.value),
|
|
4195
|
+
disabled: busy
|
|
4196
|
+
}
|
|
4197
|
+
)
|
|
4198
|
+
] }),
|
|
4199
|
+
/* @__PURE__ */ jsxs("label", { className: "auth-sdk-password", children: [
|
|
4200
|
+
/* @__PURE__ */ jsx("span", { children: labels.passwordSettingsConfirmLabel }),
|
|
4201
|
+
/* @__PURE__ */ jsx(
|
|
4202
|
+
"input",
|
|
4203
|
+
{
|
|
4204
|
+
type: "password",
|
|
4205
|
+
autoComplete: "new-password",
|
|
4206
|
+
placeholder: labels.passwordSettingsConfirmPlaceholder,
|
|
4207
|
+
value: confirm,
|
|
4208
|
+
onChange: (e) => setConfirm(e.target.value),
|
|
4209
|
+
disabled: busy
|
|
4210
|
+
}
|
|
4211
|
+
)
|
|
4212
|
+
] }),
|
|
4213
|
+
mismatch ? /* @__PURE__ */ jsx("p", { className: "auth-sdk-sign-error", children: labels.passwordSettingsMismatch }) : null,
|
|
4214
|
+
validCode && password.length === 0 ? /* @__PURE__ */ jsx("div", { className: "auth-sdk-reset-clear-row", children: /* @__PURE__ */ jsx(
|
|
4215
|
+
"button",
|
|
4216
|
+
{
|
|
4217
|
+
type: "button",
|
|
4218
|
+
className: "auth-sdk-forgot-btn",
|
|
4219
|
+
disabled: !canResetClear,
|
|
4220
|
+
onClick: () => void onSubmitReset?.(normalizedCode, null),
|
|
4221
|
+
children: labels.passwordSettingsResetClearConfirm
|
|
4222
|
+
}
|
|
4223
|
+
) }) : null
|
|
3802
4224
|
] }),
|
|
3803
4225
|
error ? /* @__PURE__ */ jsx("p", { className: "auth-sdk-sign-error", children: error }) : null,
|
|
3804
4226
|
/* @__PURE__ */ jsxs("div", { className: "auth-sdk-actions", children: [
|
|
@@ -3812,16 +4234,28 @@ function SetPasswordModal({
|
|
|
3812
4234
|
children: labels.passwordSettingsCancel
|
|
3813
4235
|
}
|
|
3814
4236
|
),
|
|
3815
|
-
mode === "set" ? /* @__PURE__ */ jsx(
|
|
4237
|
+
mode === "set" ? canBindEmailOnly ? /* @__PURE__ */ jsx(
|
|
3816
4238
|
"button",
|
|
3817
4239
|
{
|
|
3818
4240
|
type: "button",
|
|
3819
4241
|
className: "auth-sdk-btn auth-sdk-btn-primary",
|
|
3820
|
-
|
|
3821
|
-
onClick: () => void onSubmitSet(password, passwordEnabled ? current : void 0),
|
|
4242
|
+
onClick: () => void onConfirmRecoveryEmailBind?.(normalizedBindCode, recoveryEmail.trim()),
|
|
3822
4243
|
children: busy ? labels.passwordSettingsSaving : labels.passwordSettingsSave
|
|
3823
4244
|
}
|
|
3824
4245
|
) : /* @__PURE__ */ jsx(
|
|
4246
|
+
"button",
|
|
4247
|
+
{
|
|
4248
|
+
type: "button",
|
|
4249
|
+
className: "auth-sdk-btn auth-sdk-btn-primary",
|
|
4250
|
+
disabled: !canSet,
|
|
4251
|
+
onClick: () => void onSubmitSet(
|
|
4252
|
+
password,
|
|
4253
|
+
passwordEnabled ? current : void 0,
|
|
4254
|
+
needsRecoveryBind ? { recoveryEmail: recoveryEmail.trim(), recoveryCode: normalizedBindCode } : void 0
|
|
4255
|
+
),
|
|
4256
|
+
children: busy ? labels.passwordSettingsSaving : labels.passwordSettingsSave
|
|
4257
|
+
}
|
|
4258
|
+
) : mode === "clear" ? /* @__PURE__ */ jsx(
|
|
3825
4259
|
"button",
|
|
3826
4260
|
{
|
|
3827
4261
|
type: "button",
|
|
@@ -3830,6 +4264,15 @@ function SetPasswordModal({
|
|
|
3830
4264
|
onClick: () => void onSubmitClear(current),
|
|
3831
4265
|
children: busy ? labels.passwordSettingsSaving : labels.passwordSettingsClearConfirm
|
|
3832
4266
|
}
|
|
4267
|
+
) : /* @__PURE__ */ jsx(
|
|
4268
|
+
"button",
|
|
4269
|
+
{
|
|
4270
|
+
type: "button",
|
|
4271
|
+
className: "auth-sdk-btn auth-sdk-btn-primary",
|
|
4272
|
+
disabled: !canResetSet,
|
|
4273
|
+
onClick: () => void onSubmitReset?.(normalizedCode, password),
|
|
4274
|
+
children: busy ? labels.passwordSettingsSaving : labels.passwordSettingsResetConfirm
|
|
4275
|
+
}
|
|
3833
4276
|
)
|
|
3834
4277
|
] })
|
|
3835
4278
|
]
|
|
@@ -3863,7 +4306,8 @@ function SignConfirmModal({
|
|
|
3863
4306
|
onPasswordChange,
|
|
3864
4307
|
onApprove,
|
|
3865
4308
|
onReject,
|
|
3866
|
-
onOpenSetPassword
|
|
4309
|
+
onOpenSetPassword,
|
|
4310
|
+
onOpenResetPassword
|
|
3867
4311
|
}) {
|
|
3868
4312
|
if (!open || !request) return null;
|
|
3869
4313
|
const isTyped = request.method === "eth_signTypedData_v4";
|
|
@@ -3872,6 +4316,7 @@ function SignConfirmModal({
|
|
|
3872
4316
|
const payloadLabel = isTyped ? labels.signPayloadLabelTyped : isTx ? labels.signPayloadLabelTx : labels.signPayloadLabel;
|
|
3873
4317
|
const needsPassword = request.passwordEnabled;
|
|
3874
4318
|
const canApprove = !locked && (needsPassword ? password.length > 0 && !busy : !busy);
|
|
4319
|
+
const handleForgotPassword = onOpenResetPassword ?? onOpenSetPassword;
|
|
3875
4320
|
return /* @__PURE__ */ jsxs("div", { className: "auth-sdk-root", role: "presentation", children: [
|
|
3876
4321
|
/* @__PURE__ */ jsx("div", { className: "auth-sdk-backdrop", onClick: busy ? void 0 : onReject, "aria-hidden": true }),
|
|
3877
4322
|
/* @__PURE__ */ jsxs(
|
|
@@ -3904,11 +4349,24 @@ function SignConfirmModal({
|
|
|
3904
4349
|
/* @__PURE__ */ jsx("span", { className: "auth-sdk-sign-msg-label", children: payloadLabel }),
|
|
3905
4350
|
/* @__PURE__ */ jsx("pre", { className: "auth-sdk-sign-body", children: truncateMessage(request.message) })
|
|
3906
4351
|
] }),
|
|
3907
|
-
needsPassword ? /* @__PURE__ */ jsxs("
|
|
3908
|
-
/* @__PURE__ */
|
|
4352
|
+
needsPassword ? /* @__PURE__ */ jsxs("div", { className: "auth-sdk-password", children: [
|
|
4353
|
+
/* @__PURE__ */ jsxs("div", { className: "auth-sdk-password-label-row", children: [
|
|
4354
|
+
/* @__PURE__ */ jsx("label", { htmlFor: "auth-sdk-sign-password-input", children: labels.signPasswordLabel }),
|
|
4355
|
+
handleForgotPassword ? /* @__PURE__ */ jsx(
|
|
4356
|
+
"button",
|
|
4357
|
+
{
|
|
4358
|
+
type: "button",
|
|
4359
|
+
className: "auth-sdk-forgot-btn",
|
|
4360
|
+
onClick: handleForgotPassword,
|
|
4361
|
+
disabled: busy,
|
|
4362
|
+
children: labels.signForgotPassword
|
|
4363
|
+
}
|
|
4364
|
+
) : null
|
|
4365
|
+
] }),
|
|
3909
4366
|
/* @__PURE__ */ jsx(
|
|
3910
4367
|
"input",
|
|
3911
4368
|
{
|
|
4369
|
+
id: "auth-sdk-sign-password-input",
|
|
3912
4370
|
type: "password",
|
|
3913
4371
|
autoComplete: "current-password",
|
|
3914
4372
|
placeholder: labels.signPasswordPlaceholder,
|
|
@@ -3980,6 +4438,7 @@ var DEFAULT_LABELS = {
|
|
|
3980
4438
|
signReject: "Reject",
|
|
3981
4439
|
signPasswordLabel: "Wallet password",
|
|
3982
4440
|
signPasswordPlaceholder: "Enter password",
|
|
4441
|
+
signForgotPassword: "Forgot password?",
|
|
3983
4442
|
signSetPasswordOptional: "Optional \u2014 protect future signatures with a password.",
|
|
3984
4443
|
signSetPasswordButton: "Set password",
|
|
3985
4444
|
signPasswordIncorrect: "Incorrect password",
|
|
@@ -4010,6 +4469,29 @@ var DEFAULT_LABELS = {
|
|
|
4010
4469
|
passwordSettingsDisabledHint: "Optional. When set, signing will ask for this password.",
|
|
4011
4470
|
passwordSettingsChange: "Change",
|
|
4012
4471
|
passwordSettingsClear: "Remove",
|
|
4472
|
+
passwordSettingsReset: "Reset",
|
|
4473
|
+
passwordSettingsResetHint: "Receive a 6-digit verification code via your bound email or Telegram to reset your wallet password.",
|
|
4474
|
+
passwordSettingsSendCode: "Send code",
|
|
4475
|
+
passwordSettingsSendingCode: "Sending\u2026",
|
|
4476
|
+
passwordSettingsResendCode: "Resend",
|
|
4477
|
+
passwordSettingsResendCooldown: "Resend ({seconds}s)",
|
|
4478
|
+
passwordSettingsCodeSentEmail: "Verification code sent to {target}",
|
|
4479
|
+
passwordSettingsCodeSentTelegram: "Verification code sent via {target}",
|
|
4480
|
+
passwordSettingsCodeLabel: "Verification code",
|
|
4481
|
+
passwordSettingsCodePlaceholder: "6-digit code",
|
|
4482
|
+
passwordSettingsResetConfirm: "Reset password",
|
|
4483
|
+
passwordSettingsResetClearConfirm: "Verify & remove password",
|
|
4484
|
+
passwordSettingsResetCodeInvalid: "Incorrect verification code",
|
|
4485
|
+
passwordSettingsResetCodeExpired: "Verification code expired. Please request a new code.",
|
|
4486
|
+
passwordSettingsResetCodeLocked: "Too many incorrect attempts. Please request a new code.",
|
|
4487
|
+
passwordSettingsResetCooldown: "Please wait {seconds}s before requesting another code.",
|
|
4488
|
+
passwordSettingsResetChannelUnavailable: "No verified email or Telegram account is linked to this wallet.",
|
|
4489
|
+
passwordSettingsResetDeliveryFailed: "Failed to send verification code. Please try again.",
|
|
4490
|
+
passwordSettingsBindEmailLabel: "Recovery email",
|
|
4491
|
+
passwordSettingsBindEmailPlaceholder: "Enter email for password recovery",
|
|
4492
|
+
passwordSettingsBindEmailHint: "Your login method has no email or Telegram linked. Verify a recovery email to enable wallet password.",
|
|
4493
|
+
passwordSettingsRecoveryRequired: "Please verify a recovery email first",
|
|
4494
|
+
passwordSettingsInvalidRecoveryEmail: "Please enter a valid email address",
|
|
4013
4495
|
passwordSettingsCurrentLabel: "Current password",
|
|
4014
4496
|
passwordSettingsCurrentPlaceholder: "Current password",
|
|
4015
4497
|
passwordSettingsNewLabel: "New password",
|
|
@@ -4042,8 +4524,14 @@ function AuthProvider({
|
|
|
4042
4524
|
const [signBusy, setSignBusy] = useState(false);
|
|
4043
4525
|
const [signError, setSignError] = useState(null);
|
|
4044
4526
|
const [passwordSettingsOpen, setPasswordSettingsOpen] = useState(false);
|
|
4527
|
+
const [passwordInitialMode, setPasswordInitialMode] = useState("set");
|
|
4045
4528
|
const [passwordBusy, setPasswordBusy] = useState(false);
|
|
4529
|
+
const [sendingResetCode, setSendingResetCode] = useState(false);
|
|
4530
|
+
const [resetSent, setResetSent] = useState(null);
|
|
4531
|
+
const [sendingRecoveryBindCode, setSendingRecoveryBindCode] = useState(false);
|
|
4532
|
+
const [recoveryBindSent, setRecoveryBindSent] = useState(null);
|
|
4046
4533
|
const [passwordError, setPasswordError] = useState(null);
|
|
4534
|
+
const [passwordVersion, setPasswordVersion] = useState(0);
|
|
4047
4535
|
const pendingSignRef = useRef(null);
|
|
4048
4536
|
const defaultModalApproval = useCallback((req) => {
|
|
4049
4537
|
return new Promise((resolve) => {
|
|
@@ -4198,8 +4686,9 @@ function AuthProvider({
|
|
|
4198
4686
|
const getProvider = useCallback(() => clientRef.current.getProvider(), []);
|
|
4199
4687
|
const getConnectorShim = useCallback(() => clientRef.current.getConnectorShim(), []);
|
|
4200
4688
|
const setPassword = useCallback(
|
|
4201
|
-
async (pw, currentPassword) => {
|
|
4202
|
-
await clientRef.current.setPassword(pw, currentPassword);
|
|
4689
|
+
async (pw, currentPassword, recoveryBind) => {
|
|
4690
|
+
await clientRef.current.setPassword(pw, currentPassword, recoveryBind);
|
|
4691
|
+
setPasswordVersion((v) => v + 1);
|
|
4203
4692
|
bump();
|
|
4204
4693
|
},
|
|
4205
4694
|
[bump]
|
|
@@ -4207,19 +4696,51 @@ function AuthProvider({
|
|
|
4207
4696
|
const clearPassword = useCallback(
|
|
4208
4697
|
async (pw) => {
|
|
4209
4698
|
await clientRef.current.clearPassword(pw);
|
|
4699
|
+
setPasswordVersion((v) => v + 1);
|
|
4210
4700
|
bump();
|
|
4211
4701
|
},
|
|
4212
4702
|
[bump]
|
|
4213
4703
|
);
|
|
4214
|
-
const
|
|
4215
|
-
|
|
4216
|
-
|
|
4704
|
+
const requestPasswordReset = useCallback(
|
|
4705
|
+
async (channel, email) => {
|
|
4706
|
+
return clientRef.current.requestPasswordReset(channel, email);
|
|
4707
|
+
},
|
|
4708
|
+
[]
|
|
4709
|
+
);
|
|
4710
|
+
const confirmPasswordReset = useCallback(
|
|
4711
|
+
async (code, newPassword) => {
|
|
4712
|
+
const out = await clientRef.current.confirmPasswordReset(code, newPassword);
|
|
4713
|
+
setPasswordVersion((v) => v + 1);
|
|
4714
|
+
bump();
|
|
4715
|
+
return out;
|
|
4716
|
+
},
|
|
4717
|
+
[bump]
|
|
4718
|
+
);
|
|
4719
|
+
const requestRecoveryEmailBind = useCallback(async (email) => {
|
|
4720
|
+
return clientRef.current.requestRecoveryEmailBind(email);
|
|
4217
4721
|
}, []);
|
|
4722
|
+
const confirmRecoveryEmailBind = useCallback(
|
|
4723
|
+
async (code, email) => {
|
|
4724
|
+
const out = await clientRef.current.confirmRecoveryEmailBind(code, email);
|
|
4725
|
+
bump();
|
|
4726
|
+
return out;
|
|
4727
|
+
},
|
|
4728
|
+
[bump]
|
|
4729
|
+
);
|
|
4730
|
+
const openPasswordSettings = useCallback(
|
|
4731
|
+
(initialMode) => {
|
|
4732
|
+
setPasswordError(null);
|
|
4733
|
+
setPasswordInitialMode(initialMode ?? "set");
|
|
4734
|
+
setPasswordSettingsOpen(true);
|
|
4735
|
+
void clientRef.current?.refreshUser().then(() => bump());
|
|
4736
|
+
},
|
|
4737
|
+
[bump]
|
|
4738
|
+
);
|
|
4218
4739
|
const closePasswordSettings = useCallback(() => {
|
|
4219
|
-
if (passwordBusy) return;
|
|
4740
|
+
if (passwordBusy || sendingResetCode || sendingRecoveryBindCode) return;
|
|
4220
4741
|
setPasswordSettingsOpen(false);
|
|
4221
4742
|
setPasswordError(null);
|
|
4222
|
-
}, [passwordBusy]);
|
|
4743
|
+
}, [passwordBusy, sendingResetCode, sendingRecoveryBindCode]);
|
|
4223
4744
|
const client = clientRef.current;
|
|
4224
4745
|
const authenticated = client.isAuthenticated();
|
|
4225
4746
|
const user = client.getUser();
|
|
@@ -4248,12 +4769,12 @@ function AuthProvider({
|
|
|
4248
4769
|
}
|
|
4249
4770
|
resolvePending({ approved: true });
|
|
4250
4771
|
}, [signBusy, password, resolvePending]);
|
|
4251
|
-
const
|
|
4772
|
+
const markPendingSignPasswordState = useCallback((enabled) => {
|
|
4252
4773
|
const entry = pendingSignRef.current;
|
|
4253
4774
|
if (!entry) return;
|
|
4254
4775
|
const next = {
|
|
4255
4776
|
...entry,
|
|
4256
|
-
request: { ...entry.request, passwordEnabled:
|
|
4777
|
+
request: { ...entry.request, passwordEnabled: enabled, authError: void 0 }
|
|
4257
4778
|
};
|
|
4258
4779
|
pendingSignRef.current = next;
|
|
4259
4780
|
setPendingSign(next);
|
|
@@ -4275,23 +4796,61 @@ function AuthProvider({
|
|
|
4275
4796
|
if (signBusy) return;
|
|
4276
4797
|
resolvePending(false);
|
|
4277
4798
|
},
|
|
4278
|
-
onOpenSetPassword: openPasswordSettings
|
|
4799
|
+
onOpenSetPassword: () => openPasswordSettings("set"),
|
|
4800
|
+
onOpenResetPassword: () => openPasswordSettings("reset")
|
|
4279
4801
|
};
|
|
4280
4802
|
const onSubmitSet = useCallback(
|
|
4281
|
-
async (pw, currentPassword) => {
|
|
4803
|
+
async (pw, currentPassword, recoveryBind) => {
|
|
4804
|
+
setPasswordBusy(true);
|
|
4805
|
+
setPasswordError(null);
|
|
4806
|
+
try {
|
|
4807
|
+
await setPassword(pw, currentPassword, recoveryBind);
|
|
4808
|
+
setRecoveryBindSent(null);
|
|
4809
|
+
setPasswordSettingsOpen(false);
|
|
4810
|
+
if (pendingSignRef.current) markPendingSignPasswordState(true);
|
|
4811
|
+
} catch (e) {
|
|
4812
|
+
setPasswordError(formatAuthError(e, labels));
|
|
4813
|
+
} finally {
|
|
4814
|
+
setPasswordBusy(false);
|
|
4815
|
+
}
|
|
4816
|
+
},
|
|
4817
|
+
[setPassword, markPendingSignPasswordState, labels]
|
|
4818
|
+
);
|
|
4819
|
+
const onRequestRecoveryEmailBind = useCallback(
|
|
4820
|
+
async (email) => {
|
|
4821
|
+
setSendingRecoveryBindCode(true);
|
|
4822
|
+
setPasswordError(null);
|
|
4823
|
+
try {
|
|
4824
|
+
const out = await requestRecoveryEmailBind(email);
|
|
4825
|
+
setRecoveryBindSent({
|
|
4826
|
+
channel: "email",
|
|
4827
|
+
maskedTarget: out.maskedTarget,
|
|
4828
|
+
cooldownSec: out.cooldownSec,
|
|
4829
|
+
sentAt: Date.now()
|
|
4830
|
+
});
|
|
4831
|
+
} catch (e) {
|
|
4832
|
+
setPasswordError(formatAuthError(e, labels));
|
|
4833
|
+
} finally {
|
|
4834
|
+
setSendingRecoveryBindCode(false);
|
|
4835
|
+
}
|
|
4836
|
+
},
|
|
4837
|
+
[requestRecoveryEmailBind, labels]
|
|
4838
|
+
);
|
|
4839
|
+
const onConfirmRecoveryEmailBind = useCallback(
|
|
4840
|
+
async (code, email) => {
|
|
4282
4841
|
setPasswordBusy(true);
|
|
4283
4842
|
setPasswordError(null);
|
|
4284
4843
|
try {
|
|
4285
|
-
await
|
|
4844
|
+
await confirmRecoveryEmailBind(code, email);
|
|
4845
|
+
setRecoveryBindSent(null);
|
|
4286
4846
|
setPasswordSettingsOpen(false);
|
|
4287
|
-
if (pendingSignRef.current) markPendingSignNeedsPassword();
|
|
4288
4847
|
} catch (e) {
|
|
4289
4848
|
setPasswordError(formatAuthError(e, labels));
|
|
4290
4849
|
} finally {
|
|
4291
4850
|
setPasswordBusy(false);
|
|
4292
4851
|
}
|
|
4293
4852
|
},
|
|
4294
|
-
[
|
|
4853
|
+
[confirmRecoveryEmailBind, labels]
|
|
4295
4854
|
);
|
|
4296
4855
|
const onSubmitClear = useCallback(
|
|
4297
4856
|
async (pw) => {
|
|
@@ -4300,22 +4859,70 @@ function AuthProvider({
|
|
|
4300
4859
|
try {
|
|
4301
4860
|
await clearPassword(pw);
|
|
4302
4861
|
setPasswordSettingsOpen(false);
|
|
4862
|
+
if (pendingSignRef.current) markPendingSignPasswordState(false);
|
|
4863
|
+
} catch (e) {
|
|
4864
|
+
setPasswordError(formatAuthError(e, labels));
|
|
4865
|
+
} finally {
|
|
4866
|
+
setPasswordBusy(false);
|
|
4867
|
+
}
|
|
4868
|
+
},
|
|
4869
|
+
[clearPassword, markPendingSignPasswordState, labels]
|
|
4870
|
+
);
|
|
4871
|
+
const onRequestResetCode = useCallback(
|
|
4872
|
+
async (channel, email) => {
|
|
4873
|
+
setSendingResetCode(true);
|
|
4874
|
+
setPasswordError(null);
|
|
4875
|
+
try {
|
|
4876
|
+
const out = await requestPasswordReset(channel, email);
|
|
4877
|
+
setResetSent({
|
|
4878
|
+
channel: out.channel,
|
|
4879
|
+
maskedTarget: out.maskedTarget,
|
|
4880
|
+
cooldownSec: out.cooldownSec,
|
|
4881
|
+
sentAt: Date.now()
|
|
4882
|
+
});
|
|
4883
|
+
} catch (e) {
|
|
4884
|
+
setPasswordError(formatAuthError(e, labels));
|
|
4885
|
+
} finally {
|
|
4886
|
+
setSendingResetCode(false);
|
|
4887
|
+
}
|
|
4888
|
+
},
|
|
4889
|
+
[requestPasswordReset, labels]
|
|
4890
|
+
);
|
|
4891
|
+
const onSubmitReset = useCallback(
|
|
4892
|
+
async (code, newPassword) => {
|
|
4893
|
+
setPasswordBusy(true);
|
|
4894
|
+
setPasswordError(null);
|
|
4895
|
+
try {
|
|
4896
|
+
const out = await confirmPasswordReset(code, newPassword);
|
|
4897
|
+
setResetSent(null);
|
|
4898
|
+
setPasswordSettingsOpen(false);
|
|
4899
|
+
if (pendingSignRef.current) markPendingSignPasswordState(out.passwordEnabled);
|
|
4303
4900
|
} catch (e) {
|
|
4304
4901
|
setPasswordError(formatAuthError(e, labels));
|
|
4305
4902
|
} finally {
|
|
4306
4903
|
setPasswordBusy(false);
|
|
4307
4904
|
}
|
|
4308
4905
|
},
|
|
4309
|
-
[
|
|
4906
|
+
[confirmPasswordReset, markPendingSignPasswordState, labels]
|
|
4310
4907
|
);
|
|
4311
4908
|
const passwordProps = {
|
|
4312
4909
|
open: passwordSettingsOpen,
|
|
4313
4910
|
passwordEnabled,
|
|
4911
|
+
initialMode: passwordInitialMode,
|
|
4912
|
+
recovery: user?.recovery ?? null,
|
|
4314
4913
|
labels,
|
|
4315
4914
|
busy: passwordBusy,
|
|
4915
|
+
sendingResetCode,
|
|
4916
|
+
resetSent,
|
|
4917
|
+
sendingRecoveryBindCode,
|
|
4918
|
+
recoveryBindSent,
|
|
4316
4919
|
error: passwordError,
|
|
4317
4920
|
onSubmitSet,
|
|
4318
4921
|
onSubmitClear,
|
|
4922
|
+
onRequestResetCode,
|
|
4923
|
+
onSubmitReset,
|
|
4924
|
+
onRequestRecoveryEmailBind,
|
|
4925
|
+
onConfirmRecoveryEmailBind,
|
|
4319
4926
|
onClose: closePasswordSettings
|
|
4320
4927
|
};
|
|
4321
4928
|
const value = useMemo(
|
|
@@ -4325,6 +4932,7 @@ function AuthProvider({
|
|
|
4325
4932
|
address,
|
|
4326
4933
|
user,
|
|
4327
4934
|
passwordEnabled,
|
|
4935
|
+
passwordVersion,
|
|
4328
4936
|
login,
|
|
4329
4937
|
loginTelegramMiniApp,
|
|
4330
4938
|
logout,
|
|
@@ -4337,6 +4945,10 @@ function AuthProvider({
|
|
|
4337
4945
|
getConnectorShim,
|
|
4338
4946
|
setPassword,
|
|
4339
4947
|
clearPassword,
|
|
4948
|
+
requestPasswordReset,
|
|
4949
|
+
confirmPasswordReset,
|
|
4950
|
+
requestRecoveryEmailBind,
|
|
4951
|
+
confirmRecoveryEmailBind,
|
|
4340
4952
|
openPasswordSettings,
|
|
4341
4953
|
closePasswordSettings,
|
|
4342
4954
|
client,
|
|
@@ -4350,6 +4962,7 @@ function AuthProvider({
|
|
|
4350
4962
|
address,
|
|
4351
4963
|
user,
|
|
4352
4964
|
passwordEnabled,
|
|
4965
|
+
passwordVersion,
|
|
4353
4966
|
login,
|
|
4354
4967
|
loginTelegramMiniApp,
|
|
4355
4968
|
logout,
|
|
@@ -4362,6 +4975,10 @@ function AuthProvider({
|
|
|
4362
4975
|
getConnectorShim,
|
|
4363
4976
|
setPassword,
|
|
4364
4977
|
clearPassword,
|
|
4978
|
+
requestPasswordReset,
|
|
4979
|
+
confirmPasswordReset,
|
|
4980
|
+
requestRecoveryEmailBind,
|
|
4981
|
+
confirmRecoveryEmailBind,
|
|
4365
4982
|
openPasswordSettings,
|
|
4366
4983
|
closePasswordSettings,
|
|
4367
4984
|
client,
|