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

fix the tryGetWindowKeys method to get the currently injected wallet #256

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fish-yan
Copy link

fix method

export function tryGetWindowKeys(): string[] {
    const window = getWindow();
    if (!window) {
        return [];
    }

    try {
        return Object.keys(window);
    } catch {
        return [];
    }
}

to

export function tryGetWindowKeys(): [string, any][] {
    const window = getWindow();
    if (!window) {
        return [];
    }

    try {
        return Object.entries(window);
    } catch {
        return [];
    }
}

in injected-provider.ts file
windowKeys is to get the keys and entries of the window.

export class InjectedProvider<T extends string = string> implements InternalProvider {

    ...

    public static getCurrentlyInjectedWallets(): WalletInfoCurrentlyInjected[] {
        if (!this.window) {
            return [];
        }

        const windowKeys = tryGetWindowKeys();
        const wallets = windowKeys.filter(([_, value]) =>
            isJSBridgeWithMetadata(value)
        ) as unknown as [string, { tonconnect: InjectedWalletApi }][];

    ...

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant