From 34812173c0f1826f0cb390e8640a9a2ae0f6faf7 Mon Sep 17 00:00:00 2001
From: Victoria <39459423+VictoriaVM@users.noreply.github.com>
Date: Fri, 30 Aug 2024 11:46:50 +0300
Subject: [PATCH] improved providers filter
---
src/components/bc-connector-list.ts | 61 +++++++++++++++++++++++------
src/components/bc-start.ts | 11 ++++--
src/types/ConnectorFilter.ts | 3 +-
3 files changed, 59 insertions(+), 16 deletions(-)
diff --git a/src/components/bc-connector-list.ts b/src/components/bc-connector-list.ts
index b4275e1..520c259 100644
--- a/src/components/bc-connector-list.ts
+++ b/src/components/bc-connector-list.ts
@@ -10,24 +10,61 @@ import './connectors/index.js';
@customElement('bc-connector-list')
export class ConnectorList extends withTwind()(BitcoinConnectElement) {
override render() {
- // TODO: find a better way to filter these when multiple filters exist
- // TODO: allow re-ordering connectors
const connectors: TemplateResult<1>[] = [];
- connectors.push(html``);
- connectors.push(html``);
- connectors.push(html``);
- connectors.push(html``);
- connectors.push(html``);
- if (!this._filters || this._filters.indexOf('nwc') === -1) {
+
+ if (this._filters?.length && this._filters?.indexOf('nwc') === -1) {
+ // Only certain providers listed in order they are mentioned in the filters list
+ this._filters.forEach((name) => {
+ switch (name) {
+ case 'alby':
+ connectors.push(html``);
+ break;
+ case 'mutiny':
+ connectors.push(html``);
+ break;
+ case 'umbrel':
+ connectors.push(html``);
+ break;
+ case 'nostr':
+ connectors.push(html``);
+ break;
+ case 'lnfi':
+ connectors.push(html``);
+ break;
+ case 'extension':
+ // TODO: is there a better way to check if a desktop extension exists?
+ if (window.webln) {
+ connectors.push(html``);
+ }
+ break;
+ case 'lnbits':
+ connectors.push(html``);
+ break;
+ case 'lnc':
+ connectors.push(html``);
+ break;
+ }
+ })
+ } else if (this._filters?.length && this._filters?.indexOf('nwc') !== -1) {
+ // Only nwc providers listed
+ connectors.push(html``);
+ connectors.push(html``);
+ connectors.push(html``);
+ connectors.push(html``);
+ connectors.push(html``);
+ } else {
+ // All providers listed
+ connectors.push(html``);
+ connectors.push(html``);
+ connectors.push(html``);
+ connectors.push(html``);
+ connectors.push(html``);
// TODO: is there a better way to check if a desktop extension exists?
if (window.webln) {
- connectors.push(
- html``
- );
+ connectors.push(html``);
}
connectors.push(html``);
connectors.push(html``);
-
}
return html`
diff --git a/src/components/bc-start.ts b/src/components/bc-start.ts
index 4a0e6f0..c15005d 100644
--- a/src/components/bc-start.ts
+++ b/src/components/bc-start.ts
@@ -9,6 +9,7 @@ import {disconnectSection} from './templates/disconnectSection';
import './bc-balance';
import store from '../state/store';
import './bc-currency-switcher';
+import {ConnectorFilterOptions} from "../types/ConnectorFilter";
// TODO: split up this component into disconnected and connected
@customElement('bc-start')
@@ -23,14 +24,17 @@ export class Start extends withTwind()(BitcoinConnectElement) {
store.getState().bitcoinConnectConfig.showBalance &&
store.getState().supports('getBalance');
- // TODO: handle unsubscribe
+ // TODO: handle unsubscribe
store.subscribe((store) => {
this._showBalance =
store.bitcoinConnectConfig.showBalance && store.supports('getBalance');
+ this._filters = store.bitcoinConnectConfig.filters;
});
}
override render() {
+ const isOneProviderOption = this._filters?.length === 1 && this._filters[0] !== 'nwc' && ConnectorFilterOptions.includes(this._filters[0]);
+
return html`
@@ -60,8 +64,9 @@ export class Start extends withTwind()(BitcoinConnectElement) {
'text-neutral-primary'
]} w-64 max-w-full text-center"
>
- How would you like to
- connect${this._appName ? `\nto ${this._appName}` : ''}?
+ ${isOneProviderOption
+ ? 'Please connect your wallet'
+ : 'How would you like to connect'}${this._appName ? `\nto ${this._appName}` : ''}${isOneProviderOption ? '' : '?'}
diff --git a/src/types/ConnectorFilter.ts b/src/types/ConnectorFilter.ts
index 1a19c3a..3224783 100644
--- a/src/types/ConnectorFilter.ts
+++ b/src/types/ConnectorFilter.ts
@@ -1 +1,2 @@
-export type ConnectorFilter = 'nwc';
+export type ConnectorFilter = 'nwc' | 'alby' | 'mutiny' | 'umbrel' | 'nostr' | 'lnfi' | 'extension' | 'lnbits' | 'lnc';
+export const ConnectorFilterOptions = ['nwc', 'alby', 'mutiny', 'umbrel', 'nostr', 'lnfi', 'extension', 'lnbits', 'lnc'];