-
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
d167d28
commit 1d59e10
Showing
5 changed files
with
186 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,47 @@ | ||
const EXTENSION_QUERY = 'hedera-extension-query-' | ||
const EXTENSION_CONNECT = 'hedera-extension-connect-' | ||
const EXTENSION_OPEN = 'hedera-extension-open-' | ||
const EXTENSION_RESPONSE = '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) => { | ||
if (event?.data?.type == EXTENSION_RESPONSE && event.data.metadata) { | ||
onFound(event.data.metadata) | ||
} | ||
}, | ||
false, | ||
) | ||
|
||
setTimeout(() => { | ||
ids.forEach((id) => { | ||
extensionQuery(id) | ||
}) | ||
}, 200) | ||
} | ||
|
||
export const extensionQuery = (id: string) => { | ||
window.postMessage({ type: EXTENSION_QUERY + id }, '*') | ||
} | ||
|
||
export const extensionConnect = (id: string, pairingString: string) => { | ||
window.postMessage({ type: EXTENSION_CONNECT + id, pairingString }, '*') | ||
} | ||
|
||
export const extensionOpen = (id: string) => { | ||
window.postMessage({ type: EXTENSION_OPEN + 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