Add extra error state to EditUsernameModalBody

This commit is contained in:
Fedor Indutny 2024-02-21 11:00:29 -08:00 committed by GitHub
parent 47fd4125fe
commit e12b5fd0af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 16 additions and 5 deletions

View file

@ -5643,6 +5643,10 @@
"messageformat": "Numbers with more than 2 digits cant start with 0",
"description": "Shown if user has attempted to enter a username with leading 0 in discriminator"
},
"icu:ProfileEditor--username--too-many-attempts": {
"messageformat": "Too many attempts made, please try again later",
"description": "Shown if user has made too many attempts to pick a username and has to wait before retrying"
},
"icu:ProfileEditor--username--unavailable": {
"messageformat": "This username is not available",
"description": "Shown if the username is not available for registration"

View file

@ -53,6 +53,7 @@ export default {
CheckCharacters: UsernameReservationError.CheckCharacters,
UsernameNotAvailable: UsernameReservationError.UsernameNotAvailable,
General: UsernameReservationError.General,
TooManyAttempts: UsernameReservationError.TooManyAttempts,
},
},
reservation: {

View file

@ -208,6 +208,9 @@ export function EditUsernameModalBody({
'icu:ProfileEditor--username--check-discriminator-leading-zero'
);
}
if (error === UsernameReservationError.TooManyAttempts) {
return i18n('icu:ProfileEditor--username--too-many-attempts');
}
// Displayed through confirmation modal below
if (
error === UsernameReservationError.General ||

View file

@ -138,11 +138,10 @@ export async function reserveUsername(
return { ok: false, error: ReserveUsernameError.Conflict };
}
if (error.code === 413 || error.code === 429) {
const time = findRetryAfterTimeFromError(error);
log.warn(`reserveUsername: got ${error.code}, waiting ${time}ms`);
await sleep(time, abortSignal);
return reserveUsername(options);
return {
ok: false,
error: ReserveUsernameError.TooManyAttempts,
};
}
}
if (error instanceof LibSignalErrorBase) {

View file

@ -476,6 +476,8 @@ export function reducer(
stateError = UsernameReservationError.AllZeroDiscriminator;
} else if (error === ReserveUsernameError.LeadingZeroDiscriminator) {
stateError = UsernameReservationError.LeadingZeroDiscriminator;
} else if (error === ReserveUsernameError.TooManyAttempts) {
stateError = UsernameReservationError.TooManyAttempts;
} else {
throw missingCaseError(error);
}

View file

@ -43,4 +43,5 @@ export enum UsernameReservationError {
NotEnoughDiscriminator = 'NotEnoughDiscriminator',
AllZeroDiscriminator = 'AllZeroDiscriminator',
LeadingZeroDiscriminator = 'LeadingZeroDiscriminator',
TooManyAttempts = 'TooManyAttempts',
}

View file

@ -19,6 +19,7 @@ export enum ReserveUsernameError {
NotEnoughDiscriminator = 'NotEnoughDiscriminator',
AllZeroDiscriminator = 'AllZeroDiscriminator',
LeadingZeroDiscriminator = 'LeadingZeroDiscriminator',
TooManyAttempts = 'TooManyAttempts',
}
export enum ConfirmUsernameResult {