-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up to automatically pop up Chrome extensions
Added a new parameter to the `DAppConnector` constructor that allows defining the extension IDs that automatically pop up when pairing or sending requests to the wallet. This contribution includes additional functions that allow for checking whether a specific extension is installed and responding. The available extensions are listed under the `extensions` property of the `DAppConnector` class. To establish a session that will automatically activate the extension, use the `connectExtension` method instead of the `connect` method. Signed-off-by: Fran Fernandez <fran@kabila.app>
- Loading branch information
1 parent
e766b8c
commit ee68ef7
Showing
5 changed files
with
206 additions
and
2 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 @@ | ||
export enum EVENTS { | ||
extensionQuery = 'hedera-extension-query-', | ||
extensionConnect = 'hedera-extension-connect-', | ||
extensionOpen = 'hedera-extension-open-', | ||
extensionResponse = 'hedera-extension-response', | ||
} | ||
|
||
export type ExtensionData = { | ||
id: string | ||
name?: string | ||
icon?: string | ||
url?: string | ||
available: boolean | ||
} | ||
|
||
export const findExtensions = ( | ||
ids: string[], | ||
onFound: (_metadata: ExtensionData) => void, | ||
): void => { | ||
if (typeof window === 'undefined') return | ||
|
||
window.addEventListener( | ||
'message', | ||
(event): void => { | ||
if (event?.data?.type == EVENTS.extensionResponse && event.data.metadata) { | ||
onFound(event.data.metadata) | ||
} | ||
}, | ||
false, | ||
) | ||
|
||
setTimeout(() => { | ||
ids.forEach((id) => { | ||
extensionQuery(id) | ||
}) | ||
}, 200) | ||
} | ||
|
||
export const extensionQuery = (id: string) => { | ||
window.postMessage({ type: EVENTS.extensionQuery + id }, '*') | ||
} | ||
|
||
export const extensionConnect = (id: string, pairingString: string) => { | ||
window.postMessage({ type: EVENTS.extensionConnect + id, pairingString }, '*') | ||
} | ||
|
||
export const extensionOpen = (id: string) => { | ||
window.postMessage({ type: EVENTS.extensionOpen + id }, '*') | ||
} |
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