From 2f2424487a6ba2865b5a381f22f83500a3133cda Mon Sep 17 00:00:00 2001 From: Dan Forbes Date: Mon, 9 Sep 2024 06:53:01 -0700 Subject: [PATCH] feat(requestEIP6963Providers): return-type (#7239) * feat(requestEIP6963Providers): return-type Add return type to requestEIP6963Providers function signature. Closes #7238 * Update Changelog --- CHANGELOG.md | 4 ++++ packages/web3/src/web3_eip6963.ts | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f2e5ea09b0..48117f4e47c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2697,4 +2697,8 @@ If there are any bugs, improvements, optimizations or any new feature proposal f - Revert `TransactionFactory.registerTransactionType` if there is a version mistatch between `web3-eth` and `web3-eth-accounts` and fix nextjs problem. (#7216) +#### web3 + +- `Web3.providers` namespace exports `type EIP6963ProviderResponse = Map`. Return type for the static `Web3.requestEIP6963Providers` is now `Promise`. (#7239) + ## [Unreleased] diff --git a/packages/web3/src/web3_eip6963.ts b/packages/web3/src/web3_eip6963.ts index 787502a4125..d2169191b5c 100644 --- a/packages/web3/src/web3_eip6963.ts +++ b/packages/web3/src/web3_eip6963.ts @@ -35,6 +35,8 @@ export interface EIP6963ProviderDetail { provider: EIP1193Provider; } +export type EIP6963ProviderResponse = Map; + export interface EIP6963AnnounceProviderEvent extends CustomEvent { type: Eip6963EventName.eip6963announceProvider; detail: EIP6963ProviderDetail; @@ -44,15 +46,15 @@ export interface EIP6963RequestProviderEvent extends Event { type: Eip6963EventName.eip6963requestProvider; } -export const eip6963ProvidersMap: Map = new Map(); +export const eip6963ProvidersMap: EIP6963ProviderResponse = new Map(); export const web3ProvidersMapUpdated = "web3:providersMapUpdated"; export interface EIP6963ProvidersMapUpdateEvent extends CustomEvent { type: string; - detail: Map; + detail: EIP6963ProviderResponse; } -export const requestEIP6963Providers = async () => +export const requestEIP6963Providers = async (): Promise => new Promise((resolve, reject) => { if (typeof window === 'undefined') { reject(new Error("window object not available, EIP-6963 is intended to be used within a browser"));