Keep account validation and persistence inside one guarded submission. Recheck modal identity before committing, persist a copied hoster candidate, and publish renderer state only after saveConfig succeeds.
30 lines
982 B
JavaScript
30 lines
982 B
JavaScript
(function (scope) {
|
|
async function submitValidatedAccount({ validate, commit, isCurrent }) {
|
|
let validation;
|
|
try {
|
|
validation = await validate();
|
|
} catch (error) {
|
|
return { status: 'error', error };
|
|
}
|
|
|
|
if (!isCurrent()) return { status: 'stale', validation };
|
|
if (validation && validation.status === 'otp_required') {
|
|
return { status: 'otp_required', validation };
|
|
}
|
|
if (!validation || (validation.status !== 'ok' && validation.status !== 'warn')) {
|
|
return { status: 'rejected', validation };
|
|
}
|
|
|
|
try {
|
|
await commit(validation);
|
|
return { status: 'committed', validation };
|
|
} catch (error) {
|
|
return { status: 'error', error, validation };
|
|
}
|
|
}
|
|
|
|
const accountSubmit = { submitValidatedAccount };
|
|
if (typeof module !== 'undefined' && module.exports) module.exports = accountSubmit;
|
|
if (scope) scope.AccountSubmit = accountSubmit;
|
|
})(typeof window !== 'undefined' ? window : globalThis);
|