-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(reference): act-1327 - added support eip-6963 (#1389)
* feat(reference): act-1327 - added support eip-6963 * feat(reference): remove selecte wallets
- Loading branch information
1 parent
f624894
commit c3a9e47
Showing
6 changed files
with
144 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
declare global{ | ||
interface WindowEventMap { | ||
"eip6963:announceProvider": CustomEvent | ||
} | ||
} | ||
|
||
export interface EIP6963ProviderInfo { | ||
walletId: string; | ||
uuid: string; | ||
name: string; | ||
icon: string; | ||
} | ||
|
||
export interface EIP1193Provider { | ||
isStatus?: boolean; | ||
host?: string; | ||
path?: string; | ||
sendAsync?: (request: { method: string, params?: Array<unknown> }, callback: (error: Error | null, response: unknown) => void) => void; | ||
send?: (request: { method: string, params?: Array<unknown> }, callback: (error: Error | null, response: unknown) => void) => void; | ||
request: (request: { method: string, params?: Array<unknown> }) => Promise<unknown>; | ||
} | ||
|
||
export interface EIP6963ProviderDetail { | ||
info: EIP6963ProviderInfo; | ||
provider: EIP1193Provider; | ||
} | ||
|
||
type EIP6963AnnounceProviderEvent = { | ||
detail: { | ||
info: EIP6963ProviderInfo; | ||
provider: EIP1193Provider; | ||
} | ||
} | ||
|
||
let providers: EIP6963ProviderDetail[] = [] | ||
export const store = { | ||
value: ()=> providers, | ||
subscribe: (callback: ()=> void) => { | ||
function onAnnouncement(event: EIP6963AnnounceProviderEvent){ | ||
if(providers.map(p => p.info.uuid).includes(event.detail.info.uuid)) return | ||
providers = [...providers, event.detail] | ||
callback() | ||
} | ||
window.addEventListener("eip6963:announceProvider", onAnnouncement); | ||
window.dispatchEvent(new Event("eip6963:requestProvider")); | ||
|
||
return () => window.removeEventListener("eip6963:announceProvider", onAnnouncement) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { useSyncExternalStore } from "react"; | ||
import { store } from "./store"; | ||
|
||
export const useSyncProviders = ()=> useSyncExternalStore(store.subscribe, store.value, store.value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters