Open
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The auth codebase had accumulated significant duplication across components, hooks, and utilities. Identical logic lived in multiple files — meaning bug fixes or behavior changes had to be applied in 2-3 places, with divergence risk on each. This PR consolidates repeated patterns into shared abstractions, reducing maintenance burden and making the codebase easier to reason about.
How
Duplicate hook file removal
src/shared/connection/hook.tsandhooks.tswere byte-for-byte identical implementations ofuseCurrentConnectionData. Deletedhook.tsand pointed the two consumers (useTrackReferral,useAuthFlow) athooks.ts. The barrelindex.tsalready re-exported fromhooks.ts, so all other consumers were unaffected.Dead styled-component cleanup (
Transfer.styled.ts)Eight styled components (
ButtonsContainer,CancelButton,ConfirmButton,LoadingContainer,LoadingText,ProgressContainer,ProgressSpinner,ProgressTrack) were defined inTransfer.styled.tsbut never imported — each had been superseded by component-specific.styled.tsfiles. Removed them to eliminate confusion about which definition is canonical.Auth client error parsing and recovery flow (
src/shared/auth/utils.ts)The HTTP and WebSocket auth clients contained identical error-mapping logic (string matching → typed error classes) and identical recovery validation (sender mismatch, expiration check, method-based analytics tracking, error reporting). Extracted four functions into
utils.ts:throwAuthServerError— maps error strings toRequestFulfilledError,RequestNotFoundError,ExpiredRequestError,IpValidationError, or genericErrorvalidateRecoverResponse— checks sender mismatch and expirationtrackRecoverMethod— fires the correct analytics event based ondcl_personal_signvseth_sendTransactionhandleRecoverError— reports to Sentry while excluding fulfilled requests (expected state)Both
httpClient.tsandwsClient.tsnow call these instead of duplicating the logic. The WebSocket client'srequest()method already parsed the response inline, sothrowAuthServerErrorreplaced the if/else chain directly.State parameter decoding (
src/shared/utils/stateParameter.ts)Three separate functions (
extractRedirectToFromSearchParameters,extractReferrerFromSearchParameters,extractMobileDataFromState) all performed the sameatob → JSON.parse → JSON.parse(customData)decoding on the OAuthstateURL parameter. ExtractedextractFromStateParameter<T>(searchParams, field)andextractMultipleFromStateParameteras generic utilities. The three call sites inlocations.tsandmobile.tsnow use these instead of inlining the decode logic.Setup page shared hooks
SetupPageandAvatarSetupPageshared ~60% of their logic but implemented it independently. Extracted three hooks:useRequestIdFromRedirect— both pages parsed theredirectToquery param with the same regex (/^\/?auth\/requests\/([a-zA-Z0-9-]+)$/) to extract a request ID. Now a singleuseMemo-based hook.useSetupFormValidation(name, email, agree)— both pages validated username (empty, length, spaces, special chars), email (contains @), and terms checkbox with identicaluseMemoblocks. Now returns{ nameError, emailError, agreeError }.usePostSignupActions(referrer)— both pages duplicated referral tracking on init (POST) and deploy (PATCH), plus newsletter subscription with silent error handling. Now exposestrackReferralOnInit,trackReferralOnDeploy, andsubscribeEmail.Both pages were updated to use these hooks, removing ~80 lines of duplicated validation/tracking code.
Transfer view component consolidation
The three transfer view components (
TransferConfirmView,TransferCanceledView,TransferCompletedView) all extracted the same derived state (isTip,recipientAvatar) and performed the same type assertions (transferData as MANATransferData/NFTTransferData) 15+ times across the three files.Created
useTransferViewData(props)which returns{ isTip, recipientAvatar, tipData, giftData, transferData }— the hook narrows the discriminated union once, so view components accesstipData!.sceneNameinstead of(transferData as MANATransferData).sceneNamethroughout.Also consolidated
TransferCanceledViewPropsandTransferCompletedViewProps(which were identical types) into a sharedBaseTransferViewProps, withTransferConfirmViewPropsextending it withisLoading/onApprove/onDeny.ConnectionOptions type consolidation
The
ConnectionOptionstype ({ primary, secondary?, extraOptions? }) was defined identically inuseWalletOptions.ts,targetConfig.ts, and inline inConnection.types.ts. Moved the canonical definition toConnection.types.tsand updated the other two files to import it.Page initialization hook (
useRequireAuth)Five+ pages repeated the same initialization pattern: destructure
useCurrentConnectionData(), destructureuseContext(FeatureFlagsContext), then guard withif (isConnecting || !initializedFlags) return. CreateduseRequireAuth()which combines both and returns{ isReady, isAuthenticated, account, identity, provider, flags, variants, ... }. Applied toSetupPageandAvatarSetupPage— the other pages have more specialized initialization patterns that don't benefit as cleanly from the abstraction.Shared error display components (
src/components/shared/ErrorDisplay.styled.ts)ErrorContainer,ErrorText, andWarningIconwere defined with identical styles inAvatarSetupPage.styled.tsandCharacterCounter.styled.ts.ErrorMessageIconwas separately defined inRecoverError.styled.ts. Consolidated all four into a single shared file. The consuming styled files now re-export from the shared source.Shared gradient background constants (
src/components/shared/GradientBackground.styled.ts)LoginPage.styled.tsandMobileAuthPage.styled.tsboth defined a&::beforepseudo-element with identical positioning (position: fixed,width: 100%,height: 350%,top: -100%,transform: rotate(180deg)) and similar gradient values. Extracted the shared pseudo-element base and the four gradient variants (desktop linear, mobile linear, desktop radial, mobile radial) as named constants. Both pages now compose these instead of duplicating the positioning styles.