-
Notifications
You must be signed in to change notification settings - Fork 2
feat(iframe): implement wallet_getCapabilities method
#525
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
base: master
Are you sure you want to change the base?
Changes from all commits
82591f7
2a30c90
d91952e
5486ce0
be88f94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,13 @@ | ||||||||||
| import { HappyMethodNames } from "@happy.tech/common" | ||||||||||
| import { EIP1193UserRejectedRequestError, type Msgs, type ProviderMsgsFromApp } from "@happy.tech/wallet-common" | ||||||||||
| import { isAddress } from "viem" | ||||||||||
| import { isAddress } from "@happy.tech/common" | ||||||||||
| import { | ||||||||||
| EIP1193UserRejectedRequestError, | ||||||||||
| EIP1474InvalidInput, | ||||||||||
| type Msgs, | ||||||||||
| type ProviderMsgsFromApp, | ||||||||||
| } from "@happy.tech/wallet-common" | ||||||||||
| import { HappyWalletCapability } from "@happy.tech/wallet-common" | ||||||||||
| import type { Capabilities } from "viem" | ||||||||||
| import { sendBoop } from "#src/requests/utils/boop" | ||||||||||
| import { checkAndChecksumAddress, checkAuthenticated, checkedTx } from "#src/requests/utils/checks" | ||||||||||
| import { sendToPublicClient } from "#src/requests/utils/sendToClient" | ||||||||||
|
|
@@ -93,6 +100,34 @@ export async function dispatchedPermissionlessRequest(request: ProviderMsgsFromA | |||||||||
| // If this is permissionless, we're already on the right chain so we simply succeed. | ||||||||||
| return null | ||||||||||
|
|
||||||||||
| case "wallet_getCapabilities": { | ||||||||||
| checkAuthenticated() | ||||||||||
| if (!request.payload?.params?.[0] || !request.payload?.params?.[1]) { | ||||||||||
| throw new EIP1474InvalidInput("Missing payload parameters") | ||||||||||
| } | ||||||||||
| checkAndChecksumAddress(request.payload.params[0]) | ||||||||||
|
|
||||||||||
| const currentChainId = getCurrentChain().chainId | ||||||||||
| if (request.payload.params[1].length > 1) { | ||||||||||
|
Contributor
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. i guess should also check if the length is one, and if any of the chains are happyChain/currentChain (if they only request mainnet right now, it would not behave correctly) |
||||||||||
| const requestedChainIds = request.payload.params[1] | ||||||||||
| for (const chainId of requestedChainIds) { | ||||||||||
| if (chainId !== currentChainId) { | ||||||||||
| console.warn( | ||||||||||
| `Unsupported chain ID requested: ${chainId}. The Happy Wallet is a HappyChain exclusive 🤠!`, | ||||||||||
| ) | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| const capabilities: Capabilities = { | ||||||||||
| [currentChainId]: Object.fromEntries( | ||||||||||
| Object.values(HappyWalletCapability).map((capability) => [capability, { supported: true }]), | ||||||||||
| ), | ||||||||||
|
Comment on lines
+123
to
+125
Contributor
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. you could compute this once at a global level, instead on each request // support/wallet-common/lib/interfaces/eip5792.ts
export const walletCapabilities = Object.fromEntries(
Object.values(HappyWalletCapability)
.map((capability) => [capability, { supported: true }])
)
Suggested change
|
||||||||||
| } | ||||||||||
|
|
||||||||||
| return capabilities | ||||||||||
| } | ||||||||||
|
|
||||||||||
| case HappyMethodNames.REQUEST_SESSION_KEY: { | ||||||||||
| getCheckedUser() | ||||||||||
| const target = checkAndChecksumAddress(request.payload.params[0]) | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export enum HappyWalletCapability { | ||
| BoopPaymaster = "boopPaymaster", | ||
|
Contributor
Author
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. only capability we currently support! |
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.