Skip to content

Commit

Permalink
refactor: make showConnect not persist, less breaking
Browse files Browse the repository at this point in the history
  • Loading branch information
janniks committed Dec 8, 2023
1 parent 5284ddf commit e408293
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 2 additions & 0 deletions packages/connect-ui/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export namespace Components {
"callback": Function;
"defaultProviders": WebBTCProvider[];
"installedProviders": WebBTCProvider[];
"persistSelection": boolean;
}
}
declare global {
Expand All @@ -29,6 +30,7 @@ declare namespace LocalJSX {
"callback"?: Function;
"defaultProviders"?: WebBTCProvider[];
"installedProviders"?: WebBTCProvider[];
"persistSelection"?: boolean;
}
interface IntrinsicElements {
"connect-modal": ConnectModal;
Expand Down
4 changes: 3 additions & 1 deletion packages/connect-ui/src/components/modal/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ export class Modal {
@Prop() defaultProviders: WebBTCProvider[];
@Prop() installedProviders: WebBTCProvider[];

@Prop() persistSelection: boolean;

@Prop() callback: Function;

@Element() modalEl: HTMLConnectModalElement;

handleSelectProvider(providerId: string) {
setSelectedProviderId(providerId);
if (this.persistSelection) setSelectedProviderId(providerId);
this.modalEl.remove();
this.callback();
}
Expand Down
11 changes: 6 additions & 5 deletions packages/connect-ui/src/components/modal/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

## Properties

| Property | Attribute | Description | Type | Default |
| -------------------- | --------- | ----------- | ------------------ | ----------- |
| `callback` | -- | | `Function` | `undefined` |
| `defaultProviders` | -- | | `WebBTCProvider[]` | `undefined` |
| `installedProviders` | -- | | `WebBTCProvider[]` | `undefined` |
| Property | Attribute | Description | Type | Default |
| -------------------- | ------------------- | ----------- | ------------------ | ----------- |
| `callback` | -- | | `Function` | `undefined` |
| `defaultProviders` | -- | | `WebBTCProvider[]` | `undefined` |
| `installedProviders` | -- | | `WebBTCProvider[]` | `undefined` |
| `persistSelection` | `persist-selection` | | `boolean` | `undefined` |


----------------------------------------------
Expand Down
9 changes: 7 additions & 2 deletions packages/connect/src/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ export type ActionOptions = (
defaultProviders?: WebBTCProvider[];
};

function wrapConnectCall<O extends ActionOptions>(action: (o: O, p?: StacksProvider) => any) {
/** Helper higher-order function for creating connect methods that allow for wallet selection */
function wrapConnectCall<O extends ActionOptions>(
action: (o: O, p?: StacksProvider) => any,
persistSelection = true
) {
return function wrapped(o: O, p?: StacksProvider) {
if (p) return action(o, p); // if a provider is passed, use it

Expand All @@ -62,6 +66,7 @@ function wrapConnectCall<O extends ActionOptions>(action: (o: O, p?: StacksProvi
const element = document.createElement('connect-modal');
element.defaultProviders = defaultProviders;
element.installedProviders = installedProviders;
element.persistSelection = persistSelection;
element.callback = () => action(o);

document.body.appendChild(element);
Expand All @@ -77,7 +82,7 @@ function wrapConnectCall<O extends ActionOptions>(action: (o: O, p?: StacksProvi
}

/** A wrapper for selecting a wallet (if none is selected) and then calling the {@link authenticate} action. */
export const showConnect = wrapConnectCall(authenticate);
export const showConnect = wrapConnectCall(authenticate, false);

/** A wrapper for selecting a wallet (if none is selected) and then calling the {@link openSTXTransfer} action. */
export const showSTXTransfer = wrapConnectCall(openSTXTransfer);
Expand Down

2 comments on commit e408293

@vercel
Copy link

@vercel vercel bot commented on e408293 Dec 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

connect – ./

connect-storybook.vercel.app
connect-blockstack.vercel.app
connect-git-main-blockstack.vercel.app

@vercel
Copy link

@vercel vercel bot commented on e408293 Dec 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.