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: pass selected provider when not persisting selection #351

Merged
merged 3 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions .changeset/ninety-zebras-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@stacks/connect-ui': patch
'@stacks/connect': patch
---

Fix bug that would revert to undefined wallet popup behavior.
4 changes: 2 additions & 2 deletions packages/connect-ui/src/components/modal/modal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, Element, Prop, h } from '@stencil/core';
import { WebBTCProvider } from '../../providers';
import { WebBTCProvider, getProviderFromId } from '../../providers';
import { setSelectedProviderId } from '../../session';
import CloseIcon from './assets/close-icon.svg';
import { getBrowser, getPlatform } from './utils';
Expand All @@ -23,7 +23,7 @@ export class Modal {
handleSelectProvider(providerId: string) {
if (this.persistSelection) setSelectedProviderId(providerId);
this.modalEl.remove();
this.callback();
this.callback(getProviderFromId(providerId));
}

handleCloseModal() {
Expand Down
6 changes: 5 additions & 1 deletion packages/connect-ui/src/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ export const getInstalledProviders = (defaultProviders: WebBTCProvider[] = []) =
if (registeredProviders.find(rp => rp.id === dp.id)) return false;

// check if default provider is installed (even if not registered)
const provider = dp.id.split('.').reduce((acc, part) => acc?.[part], window);
const provider = getProviderFromId(dp.id);
janniks marked this conversation as resolved.
Show resolved Hide resolved
return !!provider;
});

return registeredProviders.concat(additionalInstalledProviders);
};

export const getProviderFromId = (id: string | undefined) => {
janniks marked this conversation as resolved.
Show resolved Hide resolved
return id?.split('.').reduce((acc, part) => acc?.[part], window);
};
2 changes: 1 addition & 1 deletion packages/connect/src/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function wrapConnectCall<O extends ActionOptions>(
element.defaultProviders = defaultProviders;
element.installedProviders = installedProviders;
element.persistSelection = persistSelection;
element.callback = () => action(o);
element.callback = (passedProvider: StacksProvider | undefined) => action(o, passedProvider);
janniks marked this conversation as resolved.
Show resolved Hide resolved

document.body.appendChild(element);

Expand Down
6 changes: 2 additions & 4 deletions packages/connect/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { getSelectedProviderId } from '@stacks/connect-ui';
import { getSelectedProviderId, getProviderFromId } from '@stacks/connect-ui';

export function getStacksProvider() {
const providerId = getSelectedProviderId();
const provider = providerId?.split('.').reduce((acc, part) => acc?.[part], window);

const provider = getProviderFromId(getSelectedProviderId());
return provider || window.StacksProvider || window.BlockstackProvider;
}

Expand Down
Loading