-
Notifications
You must be signed in to change notification settings - Fork 262
Feat/account linking improvements #2506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
35e0a64
chore: refactor account linking errors
lwin-kyaw f91e514
feat: handle acount linking errors and format to Proper error message
lwin-kyaw 89c47aa
feat: handle user rejected error
lwin-kyaw 120cc18
feat: handle disconnect on account link failure
lwin-kyaw f593f50
feat: de-duplicates primary accounts in LinkedAccount list
lwin-kyaw 1cb301e
chore: addressed comments
lwin-kyaw 2e0238c
Merge remote-tracking branch 'origin/master' into feat/account-linkin…
lwin-kyaw 7766e95
fix: wagmi rehydration fix on linked accounts
lwin-kyaw a4353b6
fix: fixed rehydration for linked injected wallets
lwin-kyaw 6c19b6d
fix: fixed build and test
lwin-kyaw f4de37f
chore: addressed comments
lwin-kyaw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import { ErrorCodes, Web3AuthError } from "../base"; | ||
|
|
||
| export class AccountLinkingError extends Web3AuthError { | ||
| protected static messages: ErrorCodes = { | ||
| 5000: "Custom", | ||
| 5401: "Account linking request failed", | ||
| 5402: "Citadel server URL is not configured", | ||
| 5403: "Primary identity token is not available", | ||
| 5404: "Failed to obtain wallet proof token", | ||
| 5405: "Connector is not supported for wallet linking", | ||
| 5406: "Cannot unlink active account", | ||
| 5407: "Account not linked", | ||
| 5408: "Cannot unlink primary account", | ||
| }; | ||
|
|
||
| public constructor(code: number, message?: string, cause?: unknown) { | ||
| super(code, message, cause); | ||
| Object.defineProperty(this, "name", { value: "AccountLinkingError", configurable: true }); | ||
| } | ||
|
|
||
| public static fromCode(code: number, extraMessage = "", cause?: unknown): AccountLinkingError { | ||
| return new AccountLinkingError(code, `${AccountLinkingError.messages[code]}. ${extraMessage}`, cause); | ||
| } | ||
|
|
||
| public static requestFailed(extraMessage = "", cause?: unknown): AccountLinkingError { | ||
| return AccountLinkingError.fromCode(5401, extraMessage, cause); | ||
| } | ||
|
|
||
| public static serverNotConfigured(extraMessage = "", cause?: unknown): AccountLinkingError { | ||
| return AccountLinkingError.fromCode(5402, extraMessage, cause); | ||
| } | ||
|
|
||
| public static primaryTokenNotAvailable(extraMessage = "", cause?: unknown): AccountLinkingError { | ||
| return AccountLinkingError.fromCode(5403, extraMessage, cause); | ||
| } | ||
|
|
||
| public static walletProofFailed(extraMessage = "", cause?: unknown): AccountLinkingError { | ||
| return AccountLinkingError.fromCode(5404, extraMessage, cause); | ||
| } | ||
|
|
||
| public static unsupportedConnector(extraMessage = "", cause?: unknown): AccountLinkingError { | ||
| return AccountLinkingError.fromCode(5405, extraMessage, cause); | ||
| } | ||
|
|
||
| public static cannotUnlinkActiveAccount(): AccountLinkingError { | ||
| return AccountLinkingError.fromCode(5406); | ||
| } | ||
|
|
||
| public static accountNotLinked(message = "", cause?: unknown): AccountLinkingError { | ||
| return AccountLinkingError.fromCode(5407, message, cause); | ||
| } | ||
|
|
||
| public static cannotUnlinkPrimaryAccount(): AccountLinkingError { | ||
| return AccountLinkingError.fromCode(5408); | ||
| } | ||
|
|
||
| public toString(): string { | ||
| return `[${this.code}] ${this.message}`; | ||
| } | ||
| } | ||
|
|
||
| export async function getAccountLinkingRequestError(error: unknown): Promise<AccountLinkingError> { | ||
| if (error instanceof AccountLinkingError) { | ||
| return error; | ||
| } | ||
|
|
||
| if (error instanceof Response) { | ||
| if (error.status === 409) { | ||
| return AccountLinkingError.requestFailed("This wallet address is already registered on this dApp"); | ||
| } | ||
|
|
||
| if (error.json && typeof error.json === "function") { | ||
| try { | ||
| const json = await error.json(); | ||
| return AccountLinkingError.requestFailed(json.message ?? "Failed to link account"); | ||
| } catch { | ||
| // continue | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return AccountLinkingError.requestFailed(error instanceof Error ? error.message : JSON.stringify(error), error); | ||
| } | ||
|
|
||
| export function formatAccountLinkingErrorMessage(error: unknown, fallbackMessage: string = "Unknown error during the operation."): string { | ||
| if (error instanceof AccountLinkingError) { | ||
| return error.toString(); | ||
| } | ||
|
|
||
| if (error instanceof Error) { | ||
| return error.message || fallbackMessage; | ||
| } | ||
|
|
||
| try { | ||
| const stringifiedError = JSON.stringify(error); | ||
| return stringifiedError; | ||
| } catch { | ||
| return fallbackMessage; | ||
| } | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| export * from "./errors"; | ||
| export * from "./interfaces"; | ||
| export * from "./rest"; |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.