From 47c2eb73e4a9267403be500c941159567aafeffe Mon Sep 17 00:00:00 2001 From: janniks Date: Fri, 17 Nov 2023 12:47:43 +0100 Subject: [PATCH] refactor: fix default installed handling --- packages/connect-ui/src/components.d.ts | 10 ++-- .../connect-ui/src/components/modal/modal.tsx | 54 ++++++++++--------- .../connect-ui/src/components/modal/readme.md | 10 ++-- packages/connect-ui/src/providers.ts | 47 ++++++++++++---- packages/connect/src/index.ts | 7 +++ .../connect/src/stories/Connect.stories.tsx | 6 +-- packages/connect/src/stories/ConnectPage.tsx | 2 + packages/connect/src/ui.ts | 48 ++++++++--------- tsconfig.json | 3 +- 9 files changed, 109 insertions(+), 78 deletions(-) diff --git a/packages/connect-ui/src/components.d.ts b/packages/connect-ui/src/components.d.ts index 4ce137ee..e8177053 100644 --- a/packages/connect-ui/src/components.d.ts +++ b/packages/connect-ui/src/components.d.ts @@ -5,12 +5,12 @@ * It contains typing information for all components that exist in this project. */ import { HTMLStencilElement, JSXBase } from "@stencil/core/internal"; -import { StxProvider } from "./providers"; +import { WebBTCProvider } from "./providers"; export namespace Components { interface ConnectModal { "callback": Function; - "defaultProviders": StxProvider[]; - "registeredProviders": StxProvider[]; + "defaultProviders": WebBTCProvider[]; + "installedProviders": WebBTCProvider[]; } } declare global { @@ -27,8 +27,8 @@ declare global { declare namespace LocalJSX { interface ConnectModal { "callback"?: Function; - "defaultProviders"?: StxProvider[]; - "registeredProviders"?: StxProvider[]; + "defaultProviders"?: WebBTCProvider[]; + "installedProviders"?: WebBTCProvider[]; } interface IntrinsicElements { "connect-modal": ConnectModal; diff --git a/packages/connect-ui/src/components/modal/modal.tsx b/packages/connect-ui/src/components/modal/modal.tsx index f014077b..16e2a7b5 100644 --- a/packages/connect-ui/src/components/modal/modal.tsx +++ b/packages/connect-ui/src/components/modal/modal.tsx @@ -1,5 +1,5 @@ import { Component, Element, Prop, h } from '@stencil/core'; -import { StxProvider } from '../../providers'; +import { WebBTCProvider } from '../../providers'; import { setSelectedProvider } from '../../session'; import CloseIcon from './assets/close-icon.svg'; import { getBrowser, getPlatform } from './utils'; @@ -11,8 +11,8 @@ import { getBrowser, getPlatform } from './utils'; shadow: true, }) export class Modal { - @Prop() defaultProviders: StxProvider[]; - @Prop() registeredProviders: StxProvider[]; + @Prop() defaultProviders: WebBTCProvider[]; + @Prop() installedProviders: WebBTCProvider[]; @Prop() callback: Function; @@ -30,8 +30,8 @@ export class Modal { } // todo: nice to have: - // getComment(provider: StxProvider, browser: string, isMobile?: string) { - // if (!provider.urls) return null; + // getComment(provider: WebBTCProvider, browser: string, isMobile?: string) { + // if (!provider) return null; // const hasExtension = this.getBrowserUrl(provider); // const hasMobile = this.getMobileUrl(provider); @@ -44,25 +44,25 @@ export class Modal { // return null; // } - getBrowserUrl(provider: StxProvider) { - return provider.urls?.chromeWebStore ?? provider.urls?.mozillaWebStore; + getBrowserUrl(provider: WebBTCProvider) { + return provider.chromeWebStoreUrl ?? provider.mozillaAddOnsUrl; } - getMobileUrl(provider: StxProvider) { - return provider.urls?.iOSAppStore ?? provider.urls?.androidAppStore; + getMobileUrl(provider: WebBTCProvider) { + return provider.iOSAppStoreUrl ?? provider.googlePlayStoreUrl; } - getInstallUrl(provider: StxProvider, browser: string) { + getInstallUrl(provider: WebBTCProvider, browser: string) { if (browser === 'Chrome') { - return provider.urls?.chromeWebStore ?? this.getMobileUrl(provider) ?? provider.urls?.about; + return provider.chromeWebStoreUrl ?? this.getMobileUrl(provider) ?? provider.webUrl; } else if (browser === 'Firefox') { - return provider.urls?.mozillaWebStore ?? this.getMobileUrl(provider) ?? provider.urls?.about; + return provider.mozillaAddOnsUrl ?? this.getMobileUrl(provider) ?? provider.webUrl; } else if (browser === 'IOS') { - return provider.urls?.iOSAppStore ?? this.getBrowserUrl(provider) ?? provider.urls?.about; + return provider.iOSAppStoreUrl ?? this.getBrowserUrl(provider) ?? provider.webUrl; } else if (browser === 'Android') { - return provider.urls?.androidAppStore ?? this.getBrowserUrl(provider) ?? provider.urls?.about; + return provider.googlePlayStoreUrl ?? this.getBrowserUrl(provider) ?? provider.webUrl; } else { - return this.getBrowserUrl(provider) ?? provider.urls?.about ?? this.getMobileUrl(provider); + return this.getBrowserUrl(provider) ?? provider.webUrl ?? this.getMobileUrl(provider); } } @@ -70,6 +70,10 @@ export class Modal { const browser = getBrowser(); const mobile = getPlatform(); + const notInstalledProviders = this.defaultProviders.filter( + p => this.installedProviders.findIndex(i => i.id === p.id) === -1 // keep providers NOT already in installed list + ); + return (