Skip to content

Commit

Permalink
feat(requestEIP6963Providers): return-type (#7239)
Browse files Browse the repository at this point in the history
* feat(requestEIP6963Providers): return-type

Add return type to requestEIP6963Providers function signature.

Closes #7238

* Update Changelog
  • Loading branch information
danforbes authored Sep 9, 2024
1 parent 75df267 commit 2f24244
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, EIP6963ProviderDetail>`. Return type for the static `Web3.requestEIP6963Providers` is now `Promise<EIP6963ProviderResponse>`. (#7239)

## [Unreleased]
8 changes: 5 additions & 3 deletions packages/web3/src/web3_eip6963.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export interface EIP6963ProviderDetail<API = Web3APISpec> {
provider: EIP1193Provider<API>;
}

export type EIP6963ProviderResponse = Map<string, EIP6963ProviderDetail>;

export interface EIP6963AnnounceProviderEvent<API = Web3APISpec> extends CustomEvent {
type: Eip6963EventName.eip6963announceProvider;
detail: EIP6963ProviderDetail<API>;
Expand All @@ -44,15 +46,15 @@ export interface EIP6963RequestProviderEvent extends Event {
type: Eip6963EventName.eip6963requestProvider;
}

export const eip6963ProvidersMap: Map<string, EIP6963ProviderDetail> = new Map();
export const eip6963ProvidersMap: EIP6963ProviderResponse = new Map();

export const web3ProvidersMapUpdated = "web3:providersMapUpdated";
export interface EIP6963ProvidersMapUpdateEvent extends CustomEvent {
type: string;
detail: Map<string, EIP6963ProviderDetail>;
detail: EIP6963ProviderResponse;
}

export const requestEIP6963Providers = async () =>
export const requestEIP6963Providers = async (): Promise<EIP6963ProviderResponse> =>
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"));
Expand Down

1 comment on commit 2f24244

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 2f24244 Previous: 75df267 Ratio
processingTx 23756 ops/sec (±7.52%) 22160 ops/sec (±8.48%) 0.93
processingContractDeploy 40022 ops/sec (±7.39%) 40358 ops/sec (±7.56%) 1.01
processingContractMethodSend 16888 ops/sec (±7.21%) 16223 ops/sec (±6.92%) 0.96
processingContractMethodCall 27258 ops/sec (±8.42%) 27644 ops/sec (±6.21%) 1.01
abiEncode 44502 ops/sec (±6.85%) 44173 ops/sec (±8.18%) 0.99
abiDecode 31804 ops/sec (±6.33%) 32205 ops/sec (±6.05%) 1.01
sign 1546 ops/sec (±4.08%) 1600 ops/sec (±0.98%) 1.03
verify 372 ops/sec (±0.57%) 369 ops/sec (±0.62%) 0.99

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.