From fdbe5c12e99804ea52757fdb0876ad95c2f75701 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 23 Jan 2023 10:07:08 -0300 Subject: tune up backend dependecies --- packages/merchant-backend-ui/.storybook/.babelrc | 25 ------- packages/merchant-backend-ui/.storybook/main.js | 82 -------------------- packages/merchant-backend-ui/.storybook/preview.js | 73 ------------------ packages/merchant-backend-ui/package.json | 73 +++--------------- packages/merchant-backend-ui/rollup.config.js | 2 - .../merchant-backend-ui/src/components/Footer.tsx | 27 ++++--- packages/merchant-backend-ui/src/components/QR.tsx | 49 +++++++----- packages/merchant-backend-ui/src/hooks/backend.ts | 8 +- .../merchant-backend-ui/src/pages/DepletedTip.tsx | 40 +++++----- .../tests/__mocks__/browserMocks.ts | 42 ----------- .../tests/__mocks__/fileMocks.ts | 24 ------ .../tests/__mocks__/fileTransformer.js | 31 -------- .../tests/__mocks__/setupTests.ts | 28 ------- .../tests/funcitons/regex.test.ts | 87 ---------------------- packages/merchant-backend-ui/tests/util.ts | 62 --------------- packages/merchant-backend-ui/tsconfig.back.json | 23 ------ 16 files changed, 81 insertions(+), 595 deletions(-) delete mode 100644 packages/merchant-backend-ui/.storybook/.babelrc delete mode 100644 packages/merchant-backend-ui/.storybook/main.js delete mode 100644 packages/merchant-backend-ui/.storybook/preview.js delete mode 100644 packages/merchant-backend-ui/tests/__mocks__/browserMocks.ts delete mode 100644 packages/merchant-backend-ui/tests/__mocks__/fileMocks.ts delete mode 100644 packages/merchant-backend-ui/tests/__mocks__/fileTransformer.js delete mode 100644 packages/merchant-backend-ui/tests/__mocks__/setupTests.ts delete mode 100644 packages/merchant-backend-ui/tests/funcitons/regex.test.ts delete mode 100644 packages/merchant-backend-ui/tests/util.ts delete mode 100644 packages/merchant-backend-ui/tsconfig.back.json diff --git a/packages/merchant-backend-ui/.storybook/.babelrc b/packages/merchant-backend-ui/.storybook/.babelrc deleted file mode 100644 index 610b6f339..000000000 --- a/packages/merchant-backend-ui/.storybook/.babelrc +++ /dev/null @@ -1,25 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2021 Taler Systems S.A. - - GNU Taler is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - GNU Taler; see the file COPYING. If not, see - */ - - /** - * - * @author Sebastian Javier Marchano (sebasjm) - */ -{ - "presets": [ - "preact-cli/babel" - ] -} \ No newline at end of file diff --git a/packages/merchant-backend-ui/.storybook/main.js b/packages/merchant-backend-ui/.storybook/main.js deleted file mode 100644 index 5497a6510..000000000 --- a/packages/merchant-backend-ui/.storybook/main.js +++ /dev/null @@ -1,82 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2021 Taler Systems S.A. - - GNU Taler is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - GNU Taler; see the file COPYING. If not, see - */ - -/** -* -* @author Sebastian Javier Marchano (sebasjm) -*/ - - -module.exports = { - "stories": [ - "../src/**/*.stories.mdx", - "../src/**/*.stories.@(js|jsx|ts|tsx)" - ], - "addons": [ - "@storybook/preset-scss", - "@storybook/addon-a11y", - "@storybook/addon-essentials" //docs, control, actions, viewpot, toolbar, background - ], - // sb does not yet support new jsx transform by default - // https://github.com/storybookjs/storybook/issues/12881 - // https://github.com/storybookjs/storybook/issues/12952 - babel: async (options) => ({ - ...options, - presets: [ - ...options.presets, - [ - '@babel/preset-react', { - runtime: 'automatic', - }, - 'preset-react-jsx-transform' - ], - "@linaria", - ], - }), - webpackFinal: (config) => { - // should be removed after storybook 6.3 - // https://github.com/storybookjs/storybook/issues/12853#issuecomment-821576113 - config.resolve.alias = { - react: "preact/compat", - "react-dom": "preact/compat", - }; - - // we need to add @linaria loader AFTER the babel-loader - // https://github.com/callstack/linaria/blob/master/docs/BUNDLERS_INTEGRATION.md#webpack - config.module.rules[0] = { - ...(config.module.rules[0]), - loader: undefined, // Disable the predefined babel-loader on the rule - use: [ - { - ...(config.module.rules[0].use[0]), - loader: 'babel-loader', - }, - { - loader: '@linaria/webpack-loader', - options: { - sourceMap: true, //always true since this is dev - babelOptions: { - presets: config.module.rules[0].use[0].options.presets, - } - // Pass the current babel options to linaria's babel instance - } - } - ] - }; - - return config; - }, -} \ No newline at end of file diff --git a/packages/merchant-backend-ui/.storybook/preview.js b/packages/merchant-backend-ui/.storybook/preview.js deleted file mode 100644 index a9cc4c39a..000000000 --- a/packages/merchant-backend-ui/.storybook/preview.js +++ /dev/null @@ -1,73 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2021 Taler Systems S.A. - - GNU Taler is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - GNU Taler; see the file COPYING. If not, see - */ - -import { ConfigContextProvider } from '../src/context/config' -import { InstanceContextProvider } from '../src/context/instance' -import { TranslationProvider } from '../src/context/translation' -import { BackendContextProvider } from '../src/context/backend' -import { h } from 'preact'; - -const mockConfig = { - backendURL: 'http://demo.taler.net', - currency: 'TESTKUDOS' -} - -const mockInstance = { - id: 'instance-id', - token: 'instance-token', - admin: false, -} - -const mockBackend = { - url: 'http://merchant.url', - token: 'default-token', - triedToLog: false, -} - -export const parameters = { - controls: { expanded: true }, - // actions: { argTypesRegex: "^on.*" }, -} - -export const globalTypes = { - locale: { - name: 'Locale', - description: 'Internationalization locale', - defaultValue: 'en', - toolbar: { - icon: 'globe', - items: [ - { value: 'en', right: 'πŸ‡ΊπŸ‡Έ', title: 'English' }, - { value: 'es', right: 'πŸ‡ͺπŸ‡Έ', title: 'Spanish' }, - ], - }, - }, -}; - -export const decorators = [ - (Story, { globals }) => - - , - (Story) => - - , - (Story) => - - , - (Story) => - - , -]; diff --git a/packages/merchant-backend-ui/package.json b/packages/merchant-backend-ui/package.json index c6ef3a413..b4a886f7b 100644 --- a/packages/merchant-backend-ui/package.json +++ b/packages/merchant-backend-ui/package.json @@ -1,21 +1,18 @@ { "private": true, - "name": "merchant-backend", - "version": "0.0.4", - "license": "MIT", + "name": "@gnu-taler/merchant-backend", + "version": "0.0.5", + "license": "AGPL-3.0-or-later", "scripts": { + "compile": "rollup -c", "build": "rollup -c", "dev": "rollup -c -w", "render-examples": "ts-node -O '{\"module\": \"commonjs\"}' -T render-examples.ts dist/pages dist/examples", "lint-check": "eslint '{src,tests}/**/*.{js,jsx,ts,tsx}'", "lint-fix": "eslint --fix '{src,tests}/**/*.{js,jsx,ts,tsx}'", - "test": "jest ./tests", - "dev-test": "jest ./tests --watch", "typedoc": "typedoc src", - "clean": "rimraf build storybook-static docs single dist", - "serve-dist": "sirv --port ${PORT:=8080} --cors --single dist", - "build-storybook": "build-storybook", - "storybook": "start-storybook -p 6006" + "clean": "rimraf build docs single dist", + "serve-dist": "sirv --port ${PORT:=8080} --cors --single dist" }, "engines": { "node": ">=12", @@ -46,15 +43,14 @@ "date-fns": "^2.21.1", "history": "4.10.1", "jed": "^1.1.1", - "preact": "^10.5.13", - "preact-router": "^3.2.1", + "preact": "10.11.3", + "preact-router": "3.2.1", "qrcode-generator": "^1.4.4", "swr": "^0.5.5", "yup": "^0.32.9" }, "devDependencies": { "@babel/core": "7.18.9", - "@babel/plugin-transform-react-jsx-source": "7.18.6", "@creativebulma/bulma-tooltip": "^1.2.0", "@gnu-taler/pogen": "^0.0.5", "@linaria/babel-preset": "3.0.0-beta.22", @@ -70,75 +66,26 @@ "@rollup/plugin-image": "^2.1.1", "@rollup/plugin-json": "^4.1.0", "@rollup/plugin-replace": "^3.0.0", - "@rollup/plugin-typescript": "^8.2.5", - "@storybook/addon-a11y": "^6.2.9", - "@storybook/addon-actions": "^6.2.9", - "@storybook/addon-essentials": "^6.2.9", - "@storybook/addon-links": "^6.2.9", - "@storybook/preact": "^6.2.9", - "@storybook/preset-scss": "^1.0.3", - "@testing-library/preact": "^2.0.1", - "@testing-library/preact-hooks": "^1.1.0", - "@types/enzyme": "^3.10.8", + "@rollup/plugin-typescript": "11", "@types/history": "^4.7.8", - "@types/jest": "^26.0.23", "@types/mocha": "^8.2.2", "@types/mustache": "^4.1.2", "@typescript-eslint/eslint-plugin": "^4.22.0", "@typescript-eslint/parser": "^4.22.0", "babel-loader": "^8.2.2", "base64-inline-loader": "^1.1.1", - "bulma": "^0.9.2", - "bulma-checkbox": "^1.1.1", - "bulma-radio": "^1.1.1", - "bulma-responsive-tables": "^1.2.3", - "bulma-switch-control": "^1.1.1", - "bulma-timeline": "^3.0.4", - "bulma-upload-control": "^1.2.0", - "dotenv": "^8.2.0", - "enzyme": "^3.11.0", - "enzyme-adapter-preact-pure": "^3.1.0", "eslint": "^7.25.0", "eslint-config-preact": "^1.1.4", "eslint-plugin-header": "^3.1.1", - "html-webpack-inline-chunk-plugin": "^1.1.1", - "html-webpack-inline-source-plugin": "0.0.10", - "html-webpack-skip-assets-plugin": "^1.0.1", - "inline-chunk-html-plugin": "^1.1.1", - "jest": "^26.6.3", - "jest-preset-preact": "^4.0.2", "mustache": "^4.2.0", "po2json": "^0.4.5", - "preact-cli": "^3.0.5", - "preact-render-to-json": "^3.6.6", "preact-render-to-string": "^5.1.19", "rimraf": "^3.0.2", "rollup": "^2.56.3", "rollup-plugin-bundle-html": "^0.2.2", "rollup-plugin-css-only": "^3.1.0", - "sass": "^1.32.13", - "sass-loader": "10.1.1", "script-ext-html-webpack-plugin": "^2.1.5", "sirv-cli": "^1.0.11", - "tslib": "^2.3.1", - "typedoc": "^0.20.36", - "typescript": "^4.2.4" - }, - "jest": { - "preset": "jest-preset-preact", - "transformIgnorePatterns": [ - "node_modules/.pnpm/(?!(@gnu-taler\\+taler-util))", - "\\.pnp\\.[^\\/]+$" - ], - "setupFiles": [ - "/tests/__mocks__/browserMocks.ts", - "/tests/__mocks__/setupTests.ts" - ], - "moduleNameMapper": { - "\\.(css|less)$": "identity-obj-proxy" - }, - "transform": { - "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|po)$": "/tests/__mocks__/fileTransformer.js" - } + "typescript": "4.8.4" } } diff --git a/packages/merchant-backend-ui/rollup.config.js b/packages/merchant-backend-ui/rollup.config.js index f5227ba74..7707c13a0 100644 --- a/packages/merchant-backend-ui/rollup.config.js +++ b/packages/merchant-backend-ui/rollup.config.js @@ -26,8 +26,6 @@ import css from 'rollup-plugin-css-only'; import html from '@rollup/plugin-html'; import commonjs from "@rollup/plugin-commonjs"; - - const template = async ({ files, }) => { diff --git a/packages/merchant-backend-ui/src/components/Footer.tsx b/packages/merchant-backend-ui/src/components/Footer.tsx index 5f2957800..278e4a543 100644 --- a/packages/merchant-backend-ui/src/components/Footer.tsx +++ b/packages/merchant-backend-ui/src/components/Footer.tsx @@ -15,18 +15,21 @@ */ /** -* -* @author Sebastian Javier Marchano (sebasjm) -*/ -import { h, VNode } from 'preact'; -import { FooterBar } from '../styled'; + * + * @author Sebastian Javier Marchano (sebasjm) + */ +import { h, VNode } from "preact"; +import { FooterBar } from "../styled/index.js"; export function Footer(): VNode { - return -

- Learn more about GNU Taler on our website. -

Copyright © 2014—2021 Taler Systems SA

-

-
+ return ( + +

+ + Learn more about GNU Taler on our website. + +

Copyright © 2014—2021 Taler Systems SA

+

+
+ ); } - diff --git a/packages/merchant-backend-ui/src/components/QR.tsx b/packages/merchant-backend-ui/src/components/QR.tsx index 29c9920bf..425a94961 100644 --- a/packages/merchant-backend-ui/src/components/QR.tsx +++ b/packages/merchant-backend-ui/src/components/QR.tsx @@ -14,28 +14,41 @@ GNU Taler; see the file COPYING. If not, see */ - import { h, VNode } from "preact"; - import { useEffect, useRef } from "preact/hooks"; - import qrcode from "qrcode-generator"; - -export function createSVG(text:string):string { - const qr = qrcode(0, 'L'); +import { h, VNode } from "preact"; +import { useEffect, useRef } from "preact/hooks"; +import qrcode from "qrcode-generator"; + +export function createSVG(text: string): string { + const qr = qrcode(0, "L"); qr.addData(text); qr.make(); return qr.createSvgTag({ scalable: true, - margin: 0 + margin: 0, }); } - export function QR({ text }: { text: string; }):VNode { - const divRef = useRef(null); - useEffect(() => { - divRef.current.innerHTML = createSVG(text) - }); - - return
-
-
; - } - \ No newline at end of file +export function QR({ text }: { text: string }): VNode { + const divRef = useRef(null); + useEffect(() => { + if (divRef.current) { + divRef.current.innerHTML = createSVG(text); + } + }); + + return ( +
+
+
+ ); +} diff --git a/packages/merchant-backend-ui/src/hooks/backend.ts b/packages/merchant-backend-ui/src/hooks/backend.ts index 96b8f7139..044344d5d 100644 --- a/packages/merchant-backend-ui/src/hooks/backend.ts +++ b/packages/merchant-backend-ui/src/hooks/backend.ts @@ -209,7 +209,7 @@ export async function request(url: string, options: RequestOptions = {}): Pro url, responseType: 'json', headers, - cancelToken: !removeAxiosCancelToken? source.token : undefined, + cancelToken: !removeAxiosCancelToken ? source.token : undefined, method: options.method || 'get', data: options.data, params: options.params, @@ -217,8 +217,10 @@ export async function request(url: string, options: RequestOptions = {}): Pro }) return buildRequestOk(res, url, !!options.token) } catch (e) { - const error = buildRequestFailed(e, url, !!options.token) - throw error + if (axios.isAxiosError(e)) { + throw buildRequestFailed(e, url, !!options.token) + } + throw e } } diff --git a/packages/merchant-backend-ui/src/pages/DepletedTip.tsx b/packages/merchant-backend-ui/src/pages/DepletedTip.tsx index 756b08d6a..61fc52cdf 100644 --- a/packages/merchant-backend-ui/src/pages/DepletedTip.tsx +++ b/packages/merchant-backend-ui/src/pages/DepletedTip.tsx @@ -15,30 +15,30 @@ */ /** -* -* @author Sebastian Javier Marchano (sebasjm) -*/ -import { Fragment, h, render, VNode } from 'preact'; -import { render as renderToString } from 'preact-render-to-string'; -import { Footer } from '../components/Footer'; + * + * @author Sebastian Javier Marchano (sebasjm) + */ +import { Fragment, h, render, VNode } from "preact"; +import { render as renderToString } from "preact-render-to-string"; +import { Footer } from "../components/Footer"; import "../css/pure-min.css"; import "../css/style.css"; -import { Page } from '../styled'; +import { Page } from "../styled"; function Head(): VNode { - return Status of your tip + return Status of your tip; } export function DepletedTip(): VNode { - return -
-

Tip already collected

-
- You have already collected this tip. -
-
-