- Consolidated duplicate UndoManagers to single instance - Fixed connection promise to only resolve on 'connected' status - Fixed WebSocketProvider import (WebsocketProvider) - Added proper doc.destroy() cleanup - Renamed isPresenceInitialized property to avoid conflict Co-Authored-By: Paperclip <noreply@paperclip.ing>
59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
import type { Account } from '../../accounts/types.js'
|
|
import type { Client } from '../../clients/createClient.js'
|
|
import type { Transport } from '../../clients/transports/createTransport.js'
|
|
import type { ErrorType } from '../../errors/utils.js'
|
|
import type { Chain } from '../../types/chain.js'
|
|
import type { WalletPermission } from '../../types/eip1193.js'
|
|
import type { Prettify } from '../../types/utils.js'
|
|
import type { RequestErrorType } from '../../utils/buildRequest.js'
|
|
|
|
export type RequestPermissionsParameters = Prettify<
|
|
{
|
|
eth_accounts: Record<string, any>
|
|
} & {
|
|
[key: string]: Record<string, any>
|
|
}
|
|
>
|
|
export type RequestPermissionsReturnType = WalletPermission[]
|
|
|
|
export type RequestPermissionsErrorType = RequestErrorType | ErrorType
|
|
|
|
/**
|
|
* Requests permissions for a wallet.
|
|
*
|
|
* - Docs: https://viem.sh/docs/actions/wallet/requestPermissions
|
|
* - JSON-RPC Methods: [`wallet_requestPermissions`](https://eips.ethereum.org/EIPS/eip-2255)
|
|
*
|
|
* @param client - Client to use
|
|
* @param parameters - {@link RequestPermissionsParameters}
|
|
* @returns The wallet permissions. {@link RequestPermissionsReturnType}
|
|
*
|
|
* @example
|
|
* import { createWalletClient, custom } from 'viem'
|
|
* import { mainnet } from 'viem/chains'
|
|
* import { requestPermissions } from 'viem/wallet'
|
|
*
|
|
* const client = createWalletClient({
|
|
* chain: mainnet,
|
|
* transport: custom(window.ethereum),
|
|
* })
|
|
* const permissions = await requestPermissions(client, {
|
|
* eth_accounts: {}
|
|
* })
|
|
*/
|
|
export async function requestPermissions<
|
|
chain extends Chain | undefined,
|
|
account extends Account | undefined = undefined,
|
|
>(
|
|
client: Client<Transport, chain, account>,
|
|
permissions: RequestPermissionsParameters,
|
|
) {
|
|
return client.request(
|
|
{
|
|
method: 'wallet_requestPermissions',
|
|
params: [permissions],
|
|
},
|
|
{ retryCount: 0 },
|
|
)
|
|
}
|