diff --git a/packages/devnext/next.config.js b/packages/devnext/next.config.js index db2ad1ffe..84b2f4bbe 100644 --- a/packages/devnext/next.config.js +++ b/packages/devnext/next.config.js @@ -24,6 +24,7 @@ const nextConfig = withExpo({ '@expo/vector-icons', '@metamask/sdk-communication-layer', '@metamask/sdk', + '@metamask/sdk-install-modal-web', '@metamask/sdk-react', '@metamask/sdk-react-ui', '@metamask/sdk-ui', diff --git a/packages/devnext/package.json b/packages/devnext/package.json index d9cf940ed..c59769b5f 100644 --- a/packages/devnext/package.json +++ b/packages/devnext/package.json @@ -24,6 +24,7 @@ "@metamask/providers": "16.1.0", "@metamask/sdk": "workspace:^", "@metamask/sdk-communication-layer": "workspace:^", + "@metamask/sdk-install-modal-web": "workspace:^", "@metamask/sdk-lab": "workspace:^", "@metamask/sdk-react": "workspace:^", "@metamask/sdk-react-ui": "workspace:^", diff --git a/packages/devnext/tsconfig.json b/packages/devnext/tsconfig.json index fb57b2d9b..0bdeaf21b 100644 --- a/packages/devnext/tsconfig.json +++ b/packages/devnext/tsconfig.json @@ -23,6 +23,9 @@ "@metamask/sdk-communication-layer": [ "../sdk-communication-layer/src" ], + "@metamask/sdk-install-modal-web": [ + "../sdk-install-modal-web/src" + ], "@metamask/sdk-react": [ "../sdk-react/src" ], diff --git a/packages/devreact/tsconfig.json b/packages/devreact/tsconfig.json index 586f90306..ec2d5577e 100644 --- a/packages/devreact/tsconfig.json +++ b/packages/devreact/tsconfig.json @@ -23,6 +23,7 @@ "typeRoots": ["./types", "./node_modules/@types"], "paths": { "@metamask/sdk-communication-layer": ["../sdk-communication-layer/src"], + "@metamask/sdk-install-modal-web": ["../sdk-install-modal-web/src"], "@metamask/sdk-react": ["../sdk-react/src"], "@metamask/sdk-react-ui": ["../sdk-react-ui/src"], "@metamask/sdk": ["../sdk/src"], diff --git a/packages/sdk-install-modal-web/.eslintrc.js b/packages/sdk-install-modal-web/.eslintrc.js index 2c588227f..8c7f0495e 100644 --- a/packages/sdk-install-modal-web/.eslintrc.js +++ b/packages/sdk-install-modal-web/.eslintrc.js @@ -15,9 +15,6 @@ module.exports = { '**/coverage/**', 'postcss.config.js', 'jest-preload.js', - 'loader', - '.stencil', - 'stencil.config.ts', ], parserOptions: { diff --git a/packages/sdk-install-modal-web/.gitignore b/packages/sdk-install-modal-web/.gitignore index c79078fdb..618729973 100644 --- a/packages/sdk-install-modal-web/.gitignore +++ b/packages/sdk-install-modal-web/.gitignore @@ -54,32 +54,3 @@ node_modules/ # lock files yarn.lock package-lock.json - -# == Stencil == -dist/ -www/ -loader/ - -*~ -*.sw[mnpcod] -*.log -*.lock -*.tmp -*.tmp.* -log.txt -*.sublime-project -*.sublime-workspace - -.stencil/ -.idea/ -.vscode/ -.sass-cache/ -.versions/ -node_modules/ -$RECYCLE.BIN/ - -.DS_Store -Thumbs.db -UserInterfaceState.xcuserstate -.env -# ==== \ No newline at end of file diff --git a/packages/sdk-install-modal-web/package.json b/packages/sdk-install-modal-web/package.json index 1633967ff..d136b757c 100644 --- a/packages/sdk-install-modal-web/package.json +++ b/packages/sdk-install-modal-web/package.json @@ -13,52 +13,26 @@ }, "author": "MetaMask", "packageManager": "yarn@3.5.0", - "main": "dist/index.cjs.js", - "module": "dist/index.js", - "unpkg": "dist/sdk-install-modal-web/index.esm.js", - "types": "dist/types/index.d.ts", - "collection": "dist/collection/collection-manifest.json", - "collection:main": "dist/collection/index.js", + "main": "dist/cjs/index.js", + "module": "dist/es/index.js", + "unpkg": "dist/umd/index.js", + "browser": "dist/es/index.js", + "types": "dist/types/src/index.d.ts", "files": [ - "./dist", - "./loader" + "/dist" ], - "exports": { - ".": { - "import": "./dist/sdk-install-modal-web/index.esm.js", - "require": "./dist/cjs/sdk-install-modal-web.cjs.js" - }, - "./mm-install-modal": { - "import": "./dist/components/mm-install-modal.js", - "types": "./dist/components/mm-install-modal.d.ts" - }, - "./mm-pending-modal": { - "import": "./dist/components/mm-pending-modal.js", - "types": "./dist/components/mm-pending-modal.d.ts" - }, - "./mm-select-modal": { - "import": "./dist/components/mm-select-modal.js", - "types": "./dist/components/mm-select-modal.d.ts" - }, - "./loader": { - "import": "./loader/index.js", - "require": "./loader/index.cjs", - "types": "./loader/index.d.ts" - } - }, "scripts": { - "allow-scripts": "", - "generate": "stencil generate", "build:types": "tsc --project tsconfig.json --emitDeclarationOnly --outDir dist/types", "build:clean": "yarn clean && yarn build", - "build": "stencil build --prod", - "build:dev": "stencil build --debug --dev", + "build": "yarn build:types && rollup -c --bundleConfigAsCjs", + "build:dev": "yarn build:types && NODE_ENV=dev rollup -c --bundleConfigAsCjs", "build:tsc": "tsc --build tsconfig.json --verbose", - "build:watch": "stencil build --watchAll", + "build:watch": "webpack-cli --watch", "build:post-tsc": "echo 'N/A'", "build:pre-tsc": "echo 'N/A'", - "build:release": "yarn version && stencil build", - "clean": "rimraf ./dist && rimraf ./loader", + "size": "size-limit", + "build:release": "yarn version && webpack-cli --mode production", + "clean": "rimraf ./dist", "lint": "yarn lint:eslint && yarn lint:misc --check", "lint:changelog": "../../scripts/validate-changelog.sh @metamask/sdk-install-modal-web", "lint:eslint": "eslint . --cache --ext js,ts", @@ -67,9 +41,8 @@ "prepack": "../../scripts/prepack.sh", "publish:preview": "yarn npm publish --tag preview", "reset": "yarn clean && rimraf ./node_modules/", - "start": "stencil build --dev --watch --serve", - "test": "stencil test --spec --e2e", - "test:watch": "stencil test --spec --e2e --watchAll", + "start": "webpack-dev-server", + "test": "echo \"Running tests for version $npm_package_version...\"", "test:ci": "jest --coverage --passWithNoTests --setupFilesAfterEnv ./jest-preload.js", "preversion": "yarn test", "postversion": "git push --tags && yarn publish . --tag $npm_package_version && git push && echo \"Successfully released version $npm_package_version!\"" @@ -77,12 +50,14 @@ "devDependencies": { "@lavamoat/allow-scripts": "^2.3.1", "@metamask/auto-changelog": "3.1.0", + "@rollup/plugin-commonjs": "^25.0.7", + "@rollup/plugin-node-resolve": "^15.0.2", + "@rollup/plugin-terser": "^0.4.1", + "@rollup/plugin-typescript": "^11.1.1", "@size-limit/preset-big-lib": "^11.0.2", - "@stencil/core": "^4.22.2", - "@types/i18n": "^0.13.12", - "@types/jest": "^29.5.14", - "@types/node": "^22.9.0", "@types/prettier": "^2", + "@types/react": "^18.2.37", + "@types/react-dom": "^18.2.15", "@typescript-eslint/eslint-plugin": "^5.56.0", "@typescript-eslint/parser": "^5.56.0", "eslint": "^8.36.0", @@ -95,14 +70,36 @@ "eslint-plugin-react": "^7.32.2", "i18next": "23.11.5", "jest": "^29.6.4", + "postcss": "^8.4.35", "prettier": "^2.8.8", - "puppeteer": "^23.8.0", + "react": "^18.2.0", + "react-dom": "^18.2.0", "rimraf": "^5.0.0", + "rollup": "^4.26.0", + "rollup-plugin-peer-deps-external": "^2.2.4", + "rollup-plugin-postcss": "^4.0.2", + "rollup-plugin-sizes": "^1.0.6", + "rollup-plugin-typescript2": "^0.36.0", + "rollup-plugin-visualizer": "^5.12.0", "size-limit": "^11.0.2", "typescript": "^5.6.3" }, "peerDependencies": { - "i18next": "23.11.5" + "i18next": "23.11.5", + "react": "^18.2.0", + "react-dom": "^18.2.0", + "react-native": "*" + }, + "peerDependenciesMeta": { + "react": { + "optional": true + }, + "react-dom": { + "optional": true + }, + "react-native": { + "optional": true + } }, "publishConfig": { "access": "public", diff --git a/packages/sdk-install-modal-web/postcss.config.js b/packages/sdk-install-modal-web/postcss.config.js new file mode 100644 index 000000000..9361eff3d --- /dev/null +++ b/packages/sdk-install-modal-web/postcss.config.js @@ -0,0 +1,3 @@ +module.exports = { + plugins: {}, +}; diff --git a/packages/sdk-install-modal-web/src/InstallModal.tsx b/packages/sdk-install-modal-web/src/InstallModal.tsx new file mode 100644 index 000000000..1636d15ed --- /dev/null +++ b/packages/sdk-install-modal-web/src/InstallModal.tsx @@ -0,0 +1,140 @@ +import { i18n } from 'i18next'; +import React, { CSSProperties, useEffect, useRef, useState } from 'react'; +import { WidgetWrapper } from './WidgetWrapper'; +import AdvantagesListItem from './components/AdvantagesListItem'; +import CloseButton from './components/CloseButton'; +import HeartIcon from './components/HeartIcon'; +import InstallIcon from './components/InstallIcon'; +import WalletIcon from './components/LockIcon'; +import Logo from './components/Logo'; +import LockIcon from './components/WalletIcon'; +import styles from './styles'; +import SDKVersion from './components/SDKVersion'; +import encodeQR from '@paulmillr/qr'; + +export interface InstallModalProps { + onClose: () => void; + link: string; + sdkVersion?: string; + preferDesktop: boolean; + metaMaskInstaller: { + startDesktopOnboarding: () => void; + }; + i18nInstance: i18n; +} + +export const InstallModal = (props: InstallModalProps) => { + const [tab, setTab] = useState(props.preferDesktop ? 1 : 2); + const qrCodeContainer = useRef(null); + const { sdkVersion } = props; + + const t = props.i18nInstance.t; + + useEffect(() => { + if (qrCodeContainer.current) { + const svgElement = encodeQR(props.link, "svg", { + ecc: "medium", + scale: 2 + }) + qrCodeContainer.current.innerHTML = svgElement + } + }, [qrCodeContainer]); + + return ( + +
+
+
+
+ + + +
+
+
+ +
+
+
+
+
setTab(1)} + style={ + { + ...styles.tab, + ...(tab === 1 ? styles.tabactive : {}), + ...styles.flexItem, + } as CSSProperties + } + > + {t('DESKTOP')} +
+
setTab(2)} + style={ + { + ...styles.tab, + ...(tab === 2 ? styles.tabactive : {}), + ...styles.flexItem, + } as CSSProperties + } + > + {t('MOBILE')} +
+
+
+
+
+
+
+
+ {t('SCAN_TO_CONNECT')}
+ + {t('META_MASK_MOBILE_APP')} + +
+
+
+
+
+
+ +
+
+ +
+
+ +
+ + +
+
+ +
+ + ); +}; diff --git a/packages/sdk-install-modal-web/src/ModalLoader.tsx b/packages/sdk-install-modal-web/src/ModalLoader.tsx new file mode 100644 index 000000000..b46b5ce04 --- /dev/null +++ b/packages/sdk-install-modal-web/src/ModalLoader.tsx @@ -0,0 +1,151 @@ +import React from 'react'; +import { createRoot } from 'react-dom/client'; + +import { InstallModal, InstallModalProps } from './InstallModal'; +import { PendingModal, PendingModalProps } from './PendingModal'; +import { SelectModal, SelectModalProps } from './SelectModal'; +import encodeQR from '@paulmillr/qr'; + +export interface InstallWidgetProps extends InstallModalProps { + parentElement: Element; +} + +export interface PendingWidgetProps extends PendingModalProps { + parentElement: Element; +} + +export interface SelectWidgetProps extends SelectModalProps { + parentElement: Element; +} + +export class ModalLoader { + private installContainer?: Element; + private pendingContainer?: Element; + private selectContainer?: Element; + private debug = false; + private sdkVersion?: string; + + constructor({debug, sdkVersion}: {debug?: boolean, sdkVersion?: string}) { + this.debug = debug ?? false; + this.sdkVersion = sdkVersion; + } + + renderInstallModal(props: InstallWidgetProps) { + if (this.debug) { + console.debug(`ModalLoader: renderInstallModal`, props); + } + + this.installContainer = props.parentElement; + + const reactRoot = createRoot(props.parentElement); + reactRoot.render( + , + ); + } + + renderSelectModal(props: SelectWidgetProps) { + if (this.debug) { + console.debug(`ModalLoader: renderSelectModal`, props); + } + this.selectContainer = props.parentElement; + + const reactRoot = createRoot(props.parentElement); + reactRoot.render( + , + ); + + setTimeout(() => { + this.updateQRCode(props.link); + }, 100); + } + + renderPendingModal(props: PendingWidgetProps) { + if (this.debug) { + console.debug(`ModalLoader: renderPendingModal`, props); + } + + this.pendingContainer = props.parentElement; + + const reactRoot = createRoot(props.parentElement); + reactRoot.render( + , + ); + } + + updateOTPValue = (otpValue: string) => { + if (this.debug) { + console.debug(`ModalLoader: updateOTPValue`, otpValue); + } + + const tryUpdate = () => { + const otpNode = + document.getElementById('sdk-mm-otp-value'); + + if(this.debug) { + console.debug(`ModalLoader: updateOTPValue: otpNode`, otpNode); + } + + if (otpNode) { + otpNode.textContent = otpValue; + otpNode.style.display = 'block'; + return true; + } else { + return false; + } + } + // Sometime the modal is not properly initialized and the node is not found, we try again after 1s to solve the issue. + setTimeout(() => { + if(this.debug) { + console.debug(`ModalLoader: updateOTPValue: delayed otp update`) + } + tryUpdate(); + }, 800); + }; + + updateQRCode = (link: string) => { + if (this.debug) { + console.debug(`ModalLoader: updateQRCode`, link); + } + // TODO use scoped elem + const qrCodeNode = + document.getElementById('sdk-qrcode-container'); + if (qrCodeNode) { + qrCodeNode.innerHTML = ''; + + const svgElement = encodeQR(link, "svg", { + ecc: "medium", + scale: 2, + }) + qrCodeNode.innerHTML = svgElement + } + }; + + unmount() { + this.pendingContainer?.parentNode?.removeChild(this.pendingContainer); + this.pendingContainer = undefined; + this.installContainer?.parentNode?.removeChild(this.installContainer); + this.installContainer = undefined; + this.selectContainer?.parentNode?.removeChild(this.selectContainer); + this.selectContainer = undefined; + } +} diff --git a/packages/sdk-install-modal-web/src/PendingModal.tsx b/packages/sdk-install-modal-web/src/PendingModal.tsx new file mode 100644 index 000000000..79e75b09f --- /dev/null +++ b/packages/sdk-install-modal-web/src/PendingModal.tsx @@ -0,0 +1,90 @@ +import { i18n } from 'i18next'; +import React from 'react'; +import { WidgetWrapper } from './WidgetWrapper'; +import CloseButton from './components/CloseButton'; +import Logo from './components/Logo'; +import styles from './styles'; +import SDKVersion from './components/SDKVersion'; + +export interface PendingModalProps { + onClose: () => void; + onDisconnect?: () => void; + sdkVersion?: string; + updateOTPValue: (otpValue: string) => void; + displayOTP?: boolean; + i18nInstance: i18n; +} + +export const PendingModal = (props: PendingModalProps) => { + const displayOTP = props.displayOTP ?? true; + const { sdkVersion } = props; + + const t = props.i18nInstance.t; + return ( + +
+
+
+
+ + + +
+
+
+ +
+
+
+
+ {displayOTP + ? t('PENDING_MODAL.OPEN_META_MASK_SELECT_CODE') + : t('PENDING_MODAL.OPEN_META_MASK_CONTINUE')} +
+
+ {displayOTP && ( +
+ * {t('PENDING_MODAL.NUMBER_AFTER_OPEN_NOTICE')} +
+ )} +
+
+ +
+
+ +
+
+ ); +}; diff --git a/packages/sdk-install-modal-web/src/SelectModal.tsx b/packages/sdk-install-modal-web/src/SelectModal.tsx new file mode 100644 index 000000000..aa9531ebe --- /dev/null +++ b/packages/sdk-install-modal-web/src/SelectModal.tsx @@ -0,0 +1,116 @@ +import { i18n } from 'i18next'; +import React, { CSSProperties, useState } from 'react'; +import { WidgetWrapper } from './WidgetWrapper'; +import CloseButton from './components/CloseButton'; +import ConnectIcon from './components/ConnectIcon'; +import Logo from './components/Logo'; +import { MetamaskExtensionImage } from './components/MetamaskExtensionImage'; +import styles from './styles'; +import SDKVersion from './components/SDKVersion'; + +export interface SelectModalProps { + onClose: (shouldTerminate?: boolean) => void; + link: string; + sdkVersion?: string; + connectWithExtension: () => void; + i18nInstance: i18n; +} + +export const SelectModal = (props: SelectModalProps) => { + const [tab, setTab] = useState(2); + + const { sdkVersion } = props; + + const t = props.i18nInstance.t; + + return ( + +
props.onClose(true)}>
+
+
+
+ props.onClose(true)}> + + +
+
+
+ +
+
+
+
+
setTab(1)} + style={ + { + ...styles.tab, + ...(tab === 1 ? styles.tabactive : {}), + ...styles.flexItem, + } as CSSProperties + } + > + {t('DESKTOP')} +
+
setTab(2)} + style={ + { + ...styles.tab, + ...(tab === 2 ? styles.tabactive : {}), + ...styles.flexItem, + } as CSSProperties + } + > + {t('MOBILE')} +
+
+
+
+
+
+
+
+ {t('SCAN_TO_CONNECT')} +
+ + {t('META_MASK_MOBILE_APP')} + +
+
+
+
+
+
+ +
+
+ {t('SELECT_MODAL.CRYPTO_TAKE_CONTROL_TEXT')} +
+ + +
+
+ +
+ + ); +}; diff --git a/packages/sdk-install-modal-web/src/components/widget-wrapper/widget-wrapper.tsx b/packages/sdk-install-modal-web/src/WidgetWrapper.tsx similarity index 60% rename from packages/sdk-install-modal-web/src/components/widget-wrapper/widget-wrapper.tsx rename to packages/sdk-install-modal-web/src/WidgetWrapper.tsx index 409a25005..1527ba33f 100644 --- a/packages/sdk-install-modal-web/src/components/widget-wrapper/widget-wrapper.tsx +++ b/packages/sdk-install-modal-web/src/WidgetWrapper.tsx @@ -1,4 +1,4 @@ -import { h, ChildNode } from '@stencil/core'; +import React from 'react'; import './resetStyles.css'; const widgetWrapperStyle = { @@ -6,13 +6,15 @@ const widgetWrapperStyle = { }; export const WidgetWrapper = ({ + children, className, }: { + children: React.ReactNode; className: string; -}, children: ChildNode) => { +}) => { return ( -
+
{children}
); -}; \ No newline at end of file +}; diff --git a/packages/sdk-install-modal-web/src/components.d.ts b/packages/sdk-install-modal-web/src/components.d.ts deleted file mode 100644 index 29d80bd84..000000000 --- a/packages/sdk-install-modal-web/src/components.d.ts +++ /dev/null @@ -1,161 +0,0 @@ -/* eslint-disable */ -/* tslint:disable */ -/** - * This is an autogenerated file created by the Stencil compiler. - * It contains typing information for all components that exist in this project. - */ -import { HTMLStencilElement, JSXBase } from "@stencil/core/internal"; -import { i18n } from "i18next"; -export { i18n } from "i18next"; -export namespace Components { - interface MmInstallModal { - "i18nInstance": i18n; - /** - * The QR code link - */ - "link": string; - "preferDesktop": boolean; - "sdkVersion"?: string; - } - interface MmPendingModal { - /** - * The QR code link - */ - "displayOTP"?: boolean; - "i18nInstance": i18n; - "otpCode"?: string; - "sdkVersion"?: string; - } - interface MmSelectModal { - "i18nInstance": i18n; - /** - * The QR code link - */ - "link": string; - "sdkVersion"?: string; - } -} -export interface MmInstallModalCustomEvent extends CustomEvent { - detail: T; - target: HTMLMmInstallModalElement; -} -export interface MmPendingModalCustomEvent extends CustomEvent { - detail: T; - target: HTMLMmPendingModalElement; -} -export interface MmSelectModalCustomEvent extends CustomEvent { - detail: T; - target: HTMLMmSelectModalElement; -} -declare global { - interface HTMLMmInstallModalElementEventMap { - "close": any; - "startDesktopOnboarding": any; - } - interface HTMLMmInstallModalElement extends Components.MmInstallModal, HTMLStencilElement { - addEventListener(type: K, listener: (this: HTMLMmInstallModalElement, ev: MmInstallModalCustomEvent) => any, options?: boolean | AddEventListenerOptions): void; - addEventListener(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; - addEventListener(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; - addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; - removeEventListener(type: K, listener: (this: HTMLMmInstallModalElement, ev: MmInstallModalCustomEvent) => any, options?: boolean | EventListenerOptions): void; - removeEventListener(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | EventListenerOptions): void; - removeEventListener(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventListenerOptions): void; - removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void; - } - var HTMLMmInstallModalElement: { - prototype: HTMLMmInstallModalElement; - new (): HTMLMmInstallModalElement; - }; - interface HTMLMmPendingModalElementEventMap { - "close": any; - "disconnect": any; - "updateOTPValue": { otpValue: string }; - } - interface HTMLMmPendingModalElement extends Components.MmPendingModal, HTMLStencilElement { - addEventListener(type: K, listener: (this: HTMLMmPendingModalElement, ev: MmPendingModalCustomEvent) => any, options?: boolean | AddEventListenerOptions): void; - addEventListener(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; - addEventListener(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; - addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; - removeEventListener(type: K, listener: (this: HTMLMmPendingModalElement, ev: MmPendingModalCustomEvent) => any, options?: boolean | EventListenerOptions): void; - removeEventListener(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | EventListenerOptions): void; - removeEventListener(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventListenerOptions): void; - removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void; - } - var HTMLMmPendingModalElement: { - prototype: HTMLMmPendingModalElement; - new (): HTMLMmPendingModalElement; - }; - interface HTMLMmSelectModalElementEventMap { - "close": { shouldTerminate?: boolean }; - "connectWithExtension": any; - } - interface HTMLMmSelectModalElement extends Components.MmSelectModal, HTMLStencilElement { - addEventListener(type: K, listener: (this: HTMLMmSelectModalElement, ev: MmSelectModalCustomEvent) => any, options?: boolean | AddEventListenerOptions): void; - addEventListener(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; - addEventListener(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; - addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; - removeEventListener(type: K, listener: (this: HTMLMmSelectModalElement, ev: MmSelectModalCustomEvent) => any, options?: boolean | EventListenerOptions): void; - removeEventListener(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | EventListenerOptions): void; - removeEventListener(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventListenerOptions): void; - removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void; - } - var HTMLMmSelectModalElement: { - prototype: HTMLMmSelectModalElement; - new (): HTMLMmSelectModalElement; - }; - interface HTMLElementTagNameMap { - "mm-install-modal": HTMLMmInstallModalElement; - "mm-pending-modal": HTMLMmPendingModalElement; - "mm-select-modal": HTMLMmSelectModalElement; - } -} -declare namespace LocalJSX { - interface MmInstallModal { - "i18nInstance"?: i18n; - /** - * The QR code link - */ - "link"?: string; - "onClose"?: (event: MmInstallModalCustomEvent) => void; - "onStartDesktopOnboarding"?: (event: MmInstallModalCustomEvent) => void; - "preferDesktop"?: boolean; - "sdkVersion"?: string; - } - interface MmPendingModal { - /** - * The QR code link - */ - "displayOTP"?: boolean; - "i18nInstance"?: i18n; - "onClose"?: (event: MmPendingModalCustomEvent) => void; - "onDisconnect"?: (event: MmPendingModalCustomEvent) => void; - "onUpdateOTPValue"?: (event: MmPendingModalCustomEvent<{ otpValue: string }>) => void; - "otpCode"?: string; - "sdkVersion"?: string; - } - interface MmSelectModal { - "i18nInstance"?: i18n; - /** - * The QR code link - */ - "link"?: string; - "onClose"?: (event: MmSelectModalCustomEvent<{ shouldTerminate?: boolean }>) => void; - "onConnectWithExtension"?: (event: MmSelectModalCustomEvent) => void; - "sdkVersion"?: string; - } - interface IntrinsicElements { - "mm-install-modal": MmInstallModal; - "mm-pending-modal": MmPendingModal; - "mm-select-modal": MmSelectModal; - } -} -export { LocalJSX as JSX }; -declare module "@stencil/core" { - export namespace JSX { - interface IntrinsicElements { - "mm-install-modal": LocalJSX.MmInstallModal & JSXBase.HTMLAttributes; - "mm-pending-modal": LocalJSX.MmPendingModal & JSXBase.HTMLAttributes; - "mm-select-modal": LocalJSX.MmSelectModal & JSXBase.HTMLAttributes; - } - } -} diff --git a/packages/sdk-install-modal-web/src/components/misc/AdvantagesListItem.tsx b/packages/sdk-install-modal-web/src/components/AdvantagesListItem.tsx similarity index 53% rename from packages/sdk-install-modal-web/src/components/misc/AdvantagesListItem.tsx rename to packages/sdk-install-modal-web/src/components/AdvantagesListItem.tsx index cc6dc983d..e482d8666 100644 --- a/packages/sdk-install-modal-web/src/components/misc/AdvantagesListItem.tsx +++ b/packages/sdk-install-modal-web/src/components/AdvantagesListItem.tsx @@ -1,11 +1,12 @@ -import { h } from '@stencil/core'; +import React from 'react'; +import styles from '../styles'; const AdvantagesListItem = ({ Icon, text }: { Icon: any; text: string }) => ( -
-
+
+
-
+
{text}
diff --git a/packages/sdk-install-modal-web/src/components/misc/CloseButton.tsx b/packages/sdk-install-modal-web/src/components/CloseButton.tsx similarity index 89% rename from packages/sdk-install-modal-web/src/components/misc/CloseButton.tsx rename to packages/sdk-install-modal-web/src/components/CloseButton.tsx index b2c5dbe4f..ecd395eef 100644 --- a/packages/sdk-install-modal-web/src/components/misc/CloseButton.tsx +++ b/packages/sdk-install-modal-web/src/components/CloseButton.tsx @@ -1,5 +1,4 @@ -import { h } from "@stencil/core"; - +import React from 'react'; const CloseButton = () => ( ( > diff --git a/packages/sdk-install-modal-web/src/components/misc/ConnectIcon.tsx b/packages/sdk-install-modal-web/src/components/ConnectIcon.tsx similarity index 97% rename from packages/sdk-install-modal-web/src/components/misc/ConnectIcon.tsx rename to packages/sdk-install-modal-web/src/components/ConnectIcon.tsx index 414c3e412..0c98ac64a 100644 --- a/packages/sdk-install-modal-web/src/components/misc/ConnectIcon.tsx +++ b/packages/sdk-install-modal-web/src/components/ConnectIcon.tsx @@ -1,5 +1,4 @@ -import { h } from "@stencil/core"; - +import React from 'react'; const ConnectIcon = () => ( ( ( ( ); diff --git a/packages/sdk-install-modal-web/src/components/misc/LockIcon.tsx b/packages/sdk-install-modal-web/src/components/LockIcon.tsx similarity index 95% rename from packages/sdk-install-modal-web/src/components/misc/LockIcon.tsx rename to packages/sdk-install-modal-web/src/components/LockIcon.tsx index 9b55be499..7ce947e1c 100644 --- a/packages/sdk-install-modal-web/src/components/misc/LockIcon.tsx +++ b/packages/sdk-install-modal-web/src/components/LockIcon.tsx @@ -1,5 +1,4 @@ -import { h } from "@stencil/core"; - +import React from 'react'; const WalletIcon = () => ( ( ( d="M52.021 1L31.0526 16.4886L34.9517 7.36063L52.021 1Z" fill="#E17726" stroke="#E17726" - stroke-width="0.5" - stroke-linecap="round" - stroke-linejoin="round" + strokeWidth="0.5" + strokeLinecap="round" + strokeLinejoin="round" /> ); diff --git a/packages/sdk-install-modal-web/src/components/misc/MetamaskExtensionImage.tsx b/packages/sdk-install-modal-web/src/components/MetamaskExtensionImage.tsx similarity index 85% rename from packages/sdk-install-modal-web/src/components/misc/MetamaskExtensionImage.tsx rename to packages/sdk-install-modal-web/src/components/MetamaskExtensionImage.tsx index 0c8a7e267..0849633d3 100644 --- a/packages/sdk-install-modal-web/src/components/misc/MetamaskExtensionImage.tsx +++ b/packages/sdk-install-modal-web/src/components/MetamaskExtensionImage.tsx @@ -1,4 +1,4 @@ -import { h } from "@stencil/core"; +import React from 'react'; export const MetamaskExtensionImage = () => ( ( d="M295.952 95.4242L241.395 135.226L251.54 111.77L295.952 95.4242Z" fill="#E17726" stroke="#E17726" - stroke-width="0.94513" - stroke-linecap="round" - stroke-linejoin="round" + strokeWidth="0.94513" + strokeLinecap="round" + strokeLinejoin="round" /> ( y2="266.801" gradientUnits="userSpaceOnUse" > - - + + ( y2="401.574" gradientUnits="userSpaceOnUse" > - - - + + + ( y2="104.53" gradientUnits="userSpaceOnUse" > - - + + ( y2="72.8792" gradientUnits="userSpaceOnUse" > - - + + ( y2="183.406" gradientUnits="userSpaceOnUse" > - - + + ( y2="163.003" gradientUnits="userSpaceOnUse" > - - - + + + ( y2="241.328" gradientUnits="userSpaceOnUse" > - - + + ( y2="182.925" gradientUnits="userSpaceOnUse" > - - + + ( y2="245.537" gradientUnits="userSpaceOnUse" > - - + + ( y2="280.762" gradientUnits="userSpaceOnUse" > - - + + ( y2="100.028" gradientUnits="userSpaceOnUse" > - - + + ( y2="157.571" gradientUnits="userSpaceOnUse" > - - + + ( y2="243.911" gradientUnits="userSpaceOnUse" > - - + + ( y2="38.8076" gradientUnits="userSpaceOnUse" > - - + + ( y2="104.041" gradientUnits="userSpaceOnUse" > - - + + ( y2="302.269" gradientUnits="userSpaceOnUse" > - - + + ( y2="197.95" gradientUnits="userSpaceOnUse" > - - - + + + ( y2="232.788" gradientUnits="userSpaceOnUse" > - - - + + + ( y2="273.774" gradientUnits="userSpaceOnUse" > - - + + diff --git a/packages/sdk-install-modal-web/src/components/misc/SDKVersion.tsx b/packages/sdk-install-modal-web/src/components/SDKVersion.tsx similarity index 60% rename from packages/sdk-install-modal-web/src/components/misc/SDKVersion.tsx rename to packages/sdk-install-modal-web/src/components/SDKVersion.tsx index d573c4f90..dfb32b0d4 100644 --- a/packages/sdk-install-modal-web/src/components/misc/SDKVersion.tsx +++ b/packages/sdk-install-modal-web/src/components/SDKVersion.tsx @@ -1,7 +1,7 @@ -import { h } from "@stencil/core"; +import React from 'react' export default function SDKVersion({version}: {version?: string}) { return ( -
SDK Version {version ? `v${version}`:`unknown`}
+
SDK Version {version ? `v${version}`:`unknown`}
) } diff --git a/packages/sdk-install-modal-web/src/components/misc/WalletIcon.tsx b/packages/sdk-install-modal-web/src/components/WalletIcon.tsx similarity index 96% rename from packages/sdk-install-modal-web/src/components/misc/WalletIcon.tsx rename to packages/sdk-install-modal-web/src/components/WalletIcon.tsx index a380a1f0c..fa15468c0 100644 --- a/packages/sdk-install-modal-web/src/components/misc/WalletIcon.tsx +++ b/packages/sdk-install-modal-web/src/components/WalletIcon.tsx @@ -1,5 +1,4 @@ -import { h } from "@stencil/core"; - +import React from 'react'; const LockIcon = () => ( -
- - - ) - } -} diff --git a/packages/sdk-install-modal-web/src/components/mm-pending-modal/mm-pending-modal.tsx b/packages/sdk-install-modal-web/src/components/mm-pending-modal/mm-pending-modal.tsx deleted file mode 100644 index dca8a6b1b..000000000 --- a/packages/sdk-install-modal-web/src/components/mm-pending-modal/mm-pending-modal.tsx +++ /dev/null @@ -1,121 +0,0 @@ -import { Component, Prop, h, Event, EventEmitter } from '@stencil/core'; -import { WidgetWrapper } from '../widget-wrapper/widget-wrapper'; -import SDKVersion from '../misc/SDKVersion'; -import CloseButton from '../misc/CloseButton'; -import Logo from '../misc/Logo'; -import { i18n } from 'i18next'; - -@Component({ - tag: 'mm-pending-modal', - styleUrl: '../style.css', - shadow: true, -}) -export class PendingModal { - /** - * The QR code link - */ - @Prop() displayOTP?: boolean; - - @Prop() sdkVersion?: string; - - @Prop() i18nInstance: i18n; - - @Prop() otpCode?: string; - - @Event() close: EventEmitter; - - @Event() disconnect: EventEmitter; - - @Event() updateOTPValue: EventEmitter<{ otpValue: string }>; - - onClose() { - this.close.emit(); - } - - onDisconnect() { - this.disconnect.emit(); - } - - onUpdateOTPValueHandler(otpValue: string) { - this.updateOTPValue.emit({ - otpValue, - }) - } - - disconnectedCallback() { - this.onClose(); - } - - render() { - const displayOTP = this.displayOTP ?? true; - const sdkVersion = this.sdkVersion - const t = this.i18nInstance.t; - - return ( - -
- -
- ) - } -} diff --git a/packages/sdk-install-modal-web/src/components/mm-select-modal/mm-select-modal.tsx b/packages/sdk-install-modal-web/src/components/mm-select-modal/mm-select-modal.tsx deleted file mode 100644 index 4bd66d4cb..000000000 --- a/packages/sdk-install-modal-web/src/components/mm-select-modal/mm-select-modal.tsx +++ /dev/null @@ -1,153 +0,0 @@ -import { Component, Prop, h, Event, EventEmitter, State, Watch, Element } from '@stencil/core'; -import { WidgetWrapper } from '../widget-wrapper/widget-wrapper'; -import SDKVersion from '../misc/SDKVersion'; -import CloseButton from '../misc/CloseButton'; -import Logo from '../misc/Logo'; -import { i18n } from 'i18next'; -import ConnectIcon from '../misc/ConnectIcon'; -import { MetamaskExtensionImage } from '../misc/MetamaskExtensionImage'; -import encodeQR from '@paulmillr/qr'; - -@Component({ - tag: 'mm-select-modal', - styleUrl: '../style.css', - shadow: true, -}) -export class PendingModal { - /** - * The QR code link - */ - @Prop() link: string; - - @Prop() sdkVersion?: string; - - @Prop() i18nInstance: i18n; - - @Event() close: EventEmitter<{ shouldTerminate?: boolean }>; - - @Event() connectWithExtension: EventEmitter; - - @State() tab: number = 1; - - @Element() el: HTMLElement; - - onClose(shouldTerminate = false) { - this.close.emit({ shouldTerminate }); - } - - connectWithExtensionHandler() { - this.connectWithExtension.emit(); - } - - setTab(tab: number) { - this.tab = tab; - } - - @Watch('link') - updateLink(newLink: string) { - const svgElement = encodeQR(newLink, "svg", { - ecc: "medium", - scale: 2 - }) - - if (!this.el.shadowRoot) { - return; - } - - const qrcodeDiv = this.el.shadowRoot.querySelector("#sdk-mm-qrcode"); - - if (!qrcodeDiv) { - return; - } - - qrcodeDiv.innerHTML = svgElement - } - - disconnectedCallback() { - this.onClose(); - } - - render() { - const sdkVersion = this.sdkVersion - const t = this.i18nInstance.t; - - return ( - -
this.onClose(true)}>
-