Skip to content

Commit

Permalink
Export EIP-6963 Types
Browse files Browse the repository at this point in the history
  • Loading branch information
danforbes committed Sep 18, 2024
1 parent 5a7e302 commit 3d31777
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 19 deletions.
38 changes: 38 additions & 0 deletions packages/web3-types/src/eip6963_types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
This file is part of web3.js.
web3.js is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
web3.js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/

import type { Web3APISpec } from './web3_api_types.js';
import type { EIP1193Provider } from './web3_base_provider.js';

export interface EIP6963ProviderInfo {
uuid: string;
name: string;
icon: string;
rdns: string;
}

export interface EIP6963ProviderDetail<API = Web3APISpec> {
info: EIP6963ProviderInfo;
provider: EIP1193Provider<API>;
}

export type EIP6963ProviderResponse = Map<string, EIP6963ProviderDetail>;

export interface EIP6963ProvidersMapUpdateEvent extends CustomEvent {
type: string;
detail: EIP6963ProviderResponse;
}
1 change: 1 addition & 0 deletions packages/web3-types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ export * from './web3_api_types.js';
export * from './web3_base_provider.js';
export * from './web3_base_wallet.js';
export * from './web3_deferred_promise_type.js';
export * from './eip6963_types.js';
25 changes: 6 additions & 19 deletions packages/web3/src/web3_eip6963.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,18 @@ You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/

import { Web3APISpec, EIP1193Provider } from 'web3-types';
import type {
EIP6963ProviderDetail,
EIP6963ProvidersMapUpdateEvent,
EIP6963ProviderResponse,
Web3APISpec,
} from 'web3-types';

export enum Eip6963EventName {
eip6963announceProvider = 'eip6963:announceProvider',
eip6963requestProvider = 'eip6963:requestProvider',
}

export interface EIP6963ProviderInfo {
uuid: string;
name: string;
icon: string;
rdns: string;
}

export interface EIP6963ProviderDetail<API = Web3APISpec> {
info: EIP6963ProviderInfo;
provider: EIP1193Provider<API>;
}

export type EIP6963ProviderResponse = Map<string, EIP6963ProviderDetail>;

export interface EIP6963AnnounceProviderEvent<API = Web3APISpec> extends CustomEvent {
type: Eip6963EventName.eip6963announceProvider;
detail: EIP6963ProviderDetail<API>;
Expand All @@ -48,10 +39,6 @@ export interface EIP6963RequestProviderEvent extends Event {
export const eip6963ProvidersMap: EIP6963ProviderResponse = new Map();

export const web3ProvidersMapUpdated = 'web3:providersMapUpdated';
export interface EIP6963ProvidersMapUpdateEvent extends CustomEvent {
type: string;
detail: EIP6963ProviderResponse;
}

export const requestEIP6963Providers = async (): Promise<EIP6963ProviderResponse> =>
new Promise((resolve, reject) => {
Expand Down

0 comments on commit 3d31777

Please sign in to comment.