Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(common): support local config for runPopup #26

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wise-boxes-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@joyid/common": minor
---

feat(common): support local config for `runPopup`
7 changes: 4 additions & 3 deletions packages/common/src/sdk/popup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable prefer-const */
import type {
AuthResponseData,
DappConfig,
DappRequestType,
SignCkbTxResponseData,
SignCotaNFTResponseData,
Expand Down Expand Up @@ -51,7 +52,7 @@ export const openPopup = (url: string = ''): Window | null => {
)
}

interface PopupRerurnType {
export interface PopupRerurnType {
[DappRequestType.Auth]: AuthResponseData
[DappRequestType.SignMessage]: SignMessageResponseData
[DappRequestType.SignEvm]: SignEvmTxResponseData
Expand All @@ -72,7 +73,7 @@ interface PopupRerurnType {
}

export const runPopup = async <T extends DappRequestType>(
config: PopupConfigOptions<T>
config: PopupConfigOptions<T> & Partial<DappConfig>
): Promise<PopupRerurnType[T]> =>
new Promise<PopupRerurnType[T]>((resolve, reject) => {
if (isStandaloneBrowser()) {
Expand Down Expand Up @@ -100,7 +101,7 @@ export const runPopup = async <T extends DappRequestType>(
)

popupEventListener = (e: MessageEvent) => {
const { joyidAppURL } = getConfig()
const joyidAppURL = config.joyidAppURL ?? getConfig().joyidAppURL
if (joyidAppURL == null) {
throw new Error('joyidAppURL is not set in the config')
}
Expand Down
Loading