-
Notifications
You must be signed in to change notification settings - Fork 115
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
Wallet Standard/Adapter Error Dialog #1125
Open
Funkatronics
wants to merge
6
commits into
main
Choose a base branch
from
error-dialog
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
81bd642
dialog refactor
Funkatronics a880027
Merge branch 'main' into error-dialog
Funkatronics fd64d7d
working errors and session closure
Funkatronics f7da54b
fix remote cancellation
Funkatronics 696d6df
Merge branch 'main' of https://github.com/solana-mobile/mobile-wallet…
Funkatronics a8f5970
update error modal design
Funkatronics 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
539 changes: 281 additions & 258 deletions
539
js/packages/mobile-wallet-adapter-protocol-web3js/src/transact.ts
Large diffs are not rendered by default.
Oops, something went wrong.
355 changes: 181 additions & 174 deletions
355
js/packages/mobile-wallet-adapter-protocol/src/createMobileWalletProxy.ts
Large diffs are not rendered by default.
Oops, something went wrong.
200 changes: 101 additions & 99 deletions
200
js/packages/mobile-wallet-adapter-protocol/src/errors.ts
This file contains 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,99 +1,101 @@ | ||
// Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/ | ||
export const SolanaMobileWalletAdapterErrorCode = { | ||
ERROR_ASSOCIATION_PORT_OUT_OF_RANGE: 'ERROR_ASSOCIATION_PORT_OUT_OF_RANGE', | ||
ERROR_REFLECTOR_ID_OUT_OF_RANGE: 'ERROR_REFLECTOR_ID_OUT_OF_RANGE', | ||
ERROR_FORBIDDEN_WALLET_BASE_URL: 'ERROR_FORBIDDEN_WALLET_BASE_URL', | ||
ERROR_SECURE_CONTEXT_REQUIRED: 'ERROR_SECURE_CONTEXT_REQUIRED', | ||
ERROR_SESSION_CLOSED: 'ERROR_SESSION_CLOSED', | ||
ERROR_SESSION_TIMEOUT: 'ERROR_SESSION_TIMEOUT', | ||
ERROR_WALLET_NOT_FOUND: 'ERROR_WALLET_NOT_FOUND', | ||
ERROR_INVALID_PROTOCOL_VERSION: 'ERROR_INVALID_PROTOCOL_VERSION', | ||
} as const; | ||
type SolanaMobileWalletAdapterErrorCodeEnum = | ||
typeof SolanaMobileWalletAdapterErrorCode[keyof typeof SolanaMobileWalletAdapterErrorCode]; | ||
|
||
type ErrorDataTypeMap = { | ||
[SolanaMobileWalletAdapterErrorCode.ERROR_ASSOCIATION_PORT_OUT_OF_RANGE]: { | ||
port: number; | ||
}; | ||
[SolanaMobileWalletAdapterErrorCode.ERROR_REFLECTOR_ID_OUT_OF_RANGE]: { | ||
id: number; | ||
}; | ||
[SolanaMobileWalletAdapterErrorCode.ERROR_FORBIDDEN_WALLET_BASE_URL]: undefined; | ||
[SolanaMobileWalletAdapterErrorCode.ERROR_SECURE_CONTEXT_REQUIRED]: undefined; | ||
[SolanaMobileWalletAdapterErrorCode.ERROR_SESSION_CLOSED]: { | ||
closeEvent: CloseEvent; | ||
}; | ||
[SolanaMobileWalletAdapterErrorCode.ERROR_SESSION_TIMEOUT]: undefined; | ||
[SolanaMobileWalletAdapterErrorCode.ERROR_WALLET_NOT_FOUND]: undefined; | ||
[SolanaMobileWalletAdapterErrorCode.ERROR_INVALID_PROTOCOL_VERSION]: undefined; | ||
}; | ||
|
||
export class SolanaMobileWalletAdapterError<TErrorCode extends SolanaMobileWalletAdapterErrorCodeEnum> extends Error { | ||
data: ErrorDataTypeMap[TErrorCode] | undefined; | ||
code: TErrorCode; | ||
constructor( | ||
...args: ErrorDataTypeMap[TErrorCode] extends Record<string, unknown> | ||
? [code: TErrorCode, message: string, data: ErrorDataTypeMap[TErrorCode]] | ||
: [code: TErrorCode, message: string] | ||
) { | ||
const [code, message, data] = args; | ||
super(message); | ||
this.code = code; | ||
this.data = data; | ||
this.name = 'SolanaMobileWalletAdapterError'; | ||
} | ||
} | ||
|
||
type JSONRPCErrorCode = number; | ||
|
||
// Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/ | ||
export const SolanaMobileWalletAdapterProtocolErrorCode = { | ||
// Keep these in sync with `mobilewalletadapter/common/ProtocolContract.java`. | ||
ERROR_AUTHORIZATION_FAILED: -1, | ||
ERROR_INVALID_PAYLOADS: -2, | ||
ERROR_NOT_SIGNED: -3, | ||
ERROR_NOT_SUBMITTED: -4, | ||
ERROR_TOO_MANY_PAYLOADS: -5, | ||
ERROR_ATTEST_ORIGIN_ANDROID: -100, | ||
} as const; | ||
type SolanaMobileWalletAdapterProtocolErrorCodeEnum = | ||
typeof SolanaMobileWalletAdapterProtocolErrorCode[keyof typeof SolanaMobileWalletAdapterProtocolErrorCode]; | ||
|
||
type ProtocolErrorDataTypeMap = { | ||
[SolanaMobileWalletAdapterProtocolErrorCode.ERROR_AUTHORIZATION_FAILED]: undefined; | ||
[SolanaMobileWalletAdapterProtocolErrorCode.ERROR_INVALID_PAYLOADS]: undefined; | ||
[SolanaMobileWalletAdapterProtocolErrorCode.ERROR_NOT_SIGNED]: undefined; | ||
[SolanaMobileWalletAdapterProtocolErrorCode.ERROR_NOT_SUBMITTED]: undefined; | ||
[SolanaMobileWalletAdapterProtocolErrorCode.ERROR_TOO_MANY_PAYLOADS]: undefined; | ||
[SolanaMobileWalletAdapterProtocolErrorCode.ERROR_ATTEST_ORIGIN_ANDROID]: { | ||
attest_origin_uri: string; | ||
challenge: string; | ||
context: string; | ||
}; | ||
}; | ||
|
||
export class SolanaMobileWalletAdapterProtocolError< | ||
TErrorCode extends SolanaMobileWalletAdapterProtocolErrorCodeEnum, | ||
> extends Error { | ||
data: ProtocolErrorDataTypeMap[TErrorCode] | undefined; | ||
code: TErrorCode | JSONRPCErrorCode; | ||
jsonRpcMessageId: number; | ||
constructor( | ||
...args: ProtocolErrorDataTypeMap[TErrorCode] extends Record<string, unknown> | ||
? [ | ||
jsonRpcMessageId: number, | ||
code: TErrorCode | JSONRPCErrorCode, | ||
message: string, | ||
data: ProtocolErrorDataTypeMap[TErrorCode], | ||
] | ||
: [jsonRpcMessageId: number, code: TErrorCode | JSONRPCErrorCode, message: string] | ||
) { | ||
const [jsonRpcMessageId, code, message, data] = args; | ||
super(message); | ||
this.code = code; | ||
this.data = data; | ||
this.jsonRpcMessageId = jsonRpcMessageId; | ||
this.name = 'SolanaMobileWalletAdapterProtocolError'; | ||
} | ||
} | ||
// Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/ | ||
export const SolanaMobileWalletAdapterErrorCode = { | ||
ERROR_ASSOCIATION_PORT_OUT_OF_RANGE: 'ERROR_ASSOCIATION_PORT_OUT_OF_RANGE', | ||
ERROR_REFLECTOR_ID_OUT_OF_RANGE: 'ERROR_REFLECTOR_ID_OUT_OF_RANGE', | ||
ERROR_FORBIDDEN_WALLET_BASE_URL: 'ERROR_FORBIDDEN_WALLET_BASE_URL', | ||
ERROR_SECURE_CONTEXT_REQUIRED: 'ERROR_SECURE_CONTEXT_REQUIRED', | ||
ERROR_SESSION_CLOSED: 'ERROR_SESSION_CLOSED', | ||
ERROR_SESSION_TIMEOUT: 'ERROR_SESSION_TIMEOUT', | ||
ERROR_WALLET_NOT_FOUND: 'ERROR_WALLET_NOT_FOUND', | ||
ERROR_INVALID_PROTOCOL_VERSION: 'ERROR_INVALID_PROTOCOL_VERSION', | ||
ERROR_BROWSER_NOT_SUPPORTED: 'ERROR_BROWSER_NOT_SUPPORTED', | ||
} as const; | ||
type SolanaMobileWalletAdapterErrorCodeEnum = | ||
typeof SolanaMobileWalletAdapterErrorCode[keyof typeof SolanaMobileWalletAdapterErrorCode]; | ||
|
||
type ErrorDataTypeMap = { | ||
[SolanaMobileWalletAdapterErrorCode.ERROR_ASSOCIATION_PORT_OUT_OF_RANGE]: { | ||
port: number; | ||
}; | ||
[SolanaMobileWalletAdapterErrorCode.ERROR_REFLECTOR_ID_OUT_OF_RANGE]: { | ||
id: number; | ||
}; | ||
[SolanaMobileWalletAdapterErrorCode.ERROR_FORBIDDEN_WALLET_BASE_URL]: undefined; | ||
[SolanaMobileWalletAdapterErrorCode.ERROR_SECURE_CONTEXT_REQUIRED]: undefined; | ||
[SolanaMobileWalletAdapterErrorCode.ERROR_SESSION_CLOSED]: { | ||
closeEvent: CloseEvent; | ||
}; | ||
[SolanaMobileWalletAdapterErrorCode.ERROR_SESSION_TIMEOUT]: undefined; | ||
[SolanaMobileWalletAdapterErrorCode.ERROR_WALLET_NOT_FOUND]: undefined; | ||
[SolanaMobileWalletAdapterErrorCode.ERROR_INVALID_PROTOCOL_VERSION]: undefined; | ||
[SolanaMobileWalletAdapterErrorCode.ERROR_BROWSER_NOT_SUPPORTED]: undefined; | ||
}; | ||
|
||
export class SolanaMobileWalletAdapterError<TErrorCode extends SolanaMobileWalletAdapterErrorCodeEnum> extends Error { | ||
data: ErrorDataTypeMap[TErrorCode] | undefined; | ||
code: TErrorCode; | ||
constructor( | ||
...args: ErrorDataTypeMap[TErrorCode] extends Record<string, unknown> | ||
? [code: TErrorCode, message: string, data: ErrorDataTypeMap[TErrorCode]] | ||
: [code: TErrorCode, message: string] | ||
) { | ||
const [code, message, data] = args; | ||
super(message); | ||
this.code = code; | ||
this.data = data; | ||
this.name = 'SolanaMobileWalletAdapterError'; | ||
} | ||
} | ||
|
||
type JSONRPCErrorCode = number; | ||
|
||
// Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/ | ||
export const SolanaMobileWalletAdapterProtocolErrorCode = { | ||
// Keep these in sync with `mobilewalletadapter/common/ProtocolContract.java`. | ||
ERROR_AUTHORIZATION_FAILED: -1, | ||
ERROR_INVALID_PAYLOADS: -2, | ||
ERROR_NOT_SIGNED: -3, | ||
ERROR_NOT_SUBMITTED: -4, | ||
ERROR_TOO_MANY_PAYLOADS: -5, | ||
ERROR_ATTEST_ORIGIN_ANDROID: -100, | ||
} as const; | ||
type SolanaMobileWalletAdapterProtocolErrorCodeEnum = | ||
typeof SolanaMobileWalletAdapterProtocolErrorCode[keyof typeof SolanaMobileWalletAdapterProtocolErrorCode]; | ||
|
||
type ProtocolErrorDataTypeMap = { | ||
[SolanaMobileWalletAdapterProtocolErrorCode.ERROR_AUTHORIZATION_FAILED]: undefined; | ||
[SolanaMobileWalletAdapterProtocolErrorCode.ERROR_INVALID_PAYLOADS]: undefined; | ||
[SolanaMobileWalletAdapterProtocolErrorCode.ERROR_NOT_SIGNED]: undefined; | ||
[SolanaMobileWalletAdapterProtocolErrorCode.ERROR_NOT_SUBMITTED]: undefined; | ||
[SolanaMobileWalletAdapterProtocolErrorCode.ERROR_TOO_MANY_PAYLOADS]: undefined; | ||
[SolanaMobileWalletAdapterProtocolErrorCode.ERROR_ATTEST_ORIGIN_ANDROID]: { | ||
attest_origin_uri: string; | ||
challenge: string; | ||
context: string; | ||
}; | ||
}; | ||
|
||
export class SolanaMobileWalletAdapterProtocolError< | ||
TErrorCode extends SolanaMobileWalletAdapterProtocolErrorCodeEnum, | ||
> extends Error { | ||
data: ProtocolErrorDataTypeMap[TErrorCode] | undefined; | ||
code: TErrorCode | JSONRPCErrorCode; | ||
jsonRpcMessageId: number; | ||
constructor( | ||
...args: ProtocolErrorDataTypeMap[TErrorCode] extends Record<string, unknown> | ||
? [ | ||
jsonRpcMessageId: number, | ||
code: TErrorCode | JSONRPCErrorCode, | ||
message: string, | ||
data: ProtocolErrorDataTypeMap[TErrorCode], | ||
] | ||
: [jsonRpcMessageId: number, code: TErrorCode | JSONRPCErrorCode, message: string] | ||
) { | ||
const [jsonRpcMessageId, code, message, data] = args; | ||
super(message); | ||
this.code = code; | ||
this.data = data; | ||
this.jsonRpcMessageId = jsonRpcMessageId; | ||
this.name = 'SolanaMobileWalletAdapterProtocolError'; | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -34,7 +34,7 @@ function getDetectionPromise() { | |
const timeoutId = setTimeout(() => { | ||
cleanup(); | ||
reject(); | ||
}, 2000); | ||
}, 3000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed the timeout for the MWA intent navigation from 2s to 3s. Helps with UX when the browser asks if the user wants to navigate away. |
||
}); | ||
} | ||
|
||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird diff!!!!
the only thing added here is the
ERROR_BROWSER_NOT_SUPPORTED
error that is used to indicate when we suspect the adapter/wallet is used on an incompatible browser.