From e05ba843a061c8050648ce922f36ed3d8e1cf24a Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 24 Nov 2022 23:16:01 -0300 Subject: fix 7465 --- .../src/wallet/Notifications/index.ts | 61 ++++++ .../src/wallet/Notifications/state.ts | 48 +++++ .../src/wallet/Notifications/stories.tsx | 58 ++++++ .../src/wallet/Notifications/test.ts | 28 +++ .../src/wallet/Notifications/views.tsx | 220 +++++++++++++++++++++ 5 files changed, 415 insertions(+) create mode 100644 packages/taler-wallet-webextension/src/wallet/Notifications/index.ts create mode 100644 packages/taler-wallet-webextension/src/wallet/Notifications/state.ts create mode 100644 packages/taler-wallet-webextension/src/wallet/Notifications/stories.tsx create mode 100644 packages/taler-wallet-webextension/src/wallet/Notifications/test.ts create mode 100644 packages/taler-wallet-webextension/src/wallet/Notifications/views.tsx (limited to 'packages/taler-wallet-webextension/src/wallet/Notifications') diff --git a/packages/taler-wallet-webextension/src/wallet/Notifications/index.ts b/packages/taler-wallet-webextension/src/wallet/Notifications/index.ts new file mode 100644 index 000000000..253a0e629 --- /dev/null +++ b/packages/taler-wallet-webextension/src/wallet/Notifications/index.ts @@ -0,0 +1,61 @@ +/* + This file is part of GNU Taler + (C) 2022 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 { UserAttentionUnreadList } from "@gnu-taler/taler-util"; +import { Loading } from "../../components/Loading.js"; +import { HookError } from "../../hooks/useAsyncAsHook.js"; +import { compose, StateViewMap } from "../../utils/index.js"; +import { wxApi } from "../../wxApi.js"; +import { useComponentState } from "./state.js"; +import { LoadingUriView, ReadyView } from "./views.js"; + +export interface Props {} + +export type State = State.Loading | State.LoadingUriError | State.Ready; + +export namespace State { + export interface Loading { + status: "loading"; + error: undefined; + } + + export interface LoadingUriError { + status: "loading-error"; + error: HookError; + } + + export interface BaseInfo { + error: undefined; + } + + export interface Ready extends BaseInfo { + status: "ready"; + error: undefined; + list: UserAttentionUnreadList; + } +} + +const viewMapping: StateViewMap = { + loading: Loading, + "loading-error": LoadingUriView, + ready: ReadyView, +}; + +export const NotificationsPage = compose( + "NotificationsPage", + (p: Props) => useComponentState(p, wxApi), + viewMapping, +); diff --git a/packages/taler-wallet-webextension/src/wallet/Notifications/state.ts b/packages/taler-wallet-webextension/src/wallet/Notifications/state.ts new file mode 100644 index 000000000..093722cf0 --- /dev/null +++ b/packages/taler-wallet-webextension/src/wallet/Notifications/state.ts @@ -0,0 +1,48 @@ +/* + This file is part of GNU Taler + (C) 2022 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 { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; +import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js"; +import { wxApi } from "../../wxApi.js"; +import { Props, State } from "./index.js"; + +export function useComponentState({}: Props, api: typeof wxApi): State { + const hook = useAsyncAsHook(async () => { + return await api.wallet.call( + WalletApiOperation.GetUserAttentionRequests, + {}, + ); + }); + + if (!hook) { + return { + status: "loading", + error: undefined, + }; + } + if (hook.hasError) { + return { + status: "loading-error", + error: hook, + }; + } + + return { + status: "ready", + error: undefined, + list: hook.response.pending, + }; +} diff --git a/packages/taler-wallet-webextension/src/wallet/Notifications/stories.tsx b/packages/taler-wallet-webextension/src/wallet/Notifications/stories.tsx new file mode 100644 index 000000000..e4c7105e9 --- /dev/null +++ b/packages/taler-wallet-webextension/src/wallet/Notifications/stories.tsx @@ -0,0 +1,58 @@ +/* + This file is part of GNU Taler + (C) 2022 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) + */ + +import { AbsoluteTime, AttentionType } from "@gnu-taler/taler-util"; +import { createExample } from "../../test-utils.js"; +import { ReadyView } from "./views.js"; + +export default { + title: "wallet/notifications", +}; + +export const Ready = createExample(ReadyView, { + list: [ + { + when: AbsoluteTime.now(), + read: false, + info: { + type: AttentionType.KycWithdrawal, + transactionId: "123", + }, + }, + { + when: AbsoluteTime.now(), + read: false, + info: { + type: AttentionType.MerchantRefund, + transactionId: "123", + }, + }, + { + when: AbsoluteTime.now(), + read: false, + info: { + type: AttentionType.BackupUnpaid, + provider_base_url: "http://sync.taler.net", + talerUri: "taler://payment/asdasdasd", + }, + }, + ], +}); diff --git a/packages/taler-wallet-webextension/src/wallet/Notifications/test.ts b/packages/taler-wallet-webextension/src/wallet/Notifications/test.ts new file mode 100644 index 000000000..eae4d4ca2 --- /dev/null +++ b/packages/taler-wallet-webextension/src/wallet/Notifications/test.ts @@ -0,0 +1,28 @@ +/* + This file is part of GNU Taler + (C) 2022 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) + */ + +import { expect } from "chai"; + +describe("test description", () => { + it("should assert", () => { + expect([]).deep.equals([]); + }); +}); diff --git a/packages/taler-wallet-webextension/src/wallet/Notifications/views.tsx b/packages/taler-wallet-webextension/src/wallet/Notifications/views.tsx new file mode 100644 index 000000000..9146d8837 --- /dev/null +++ b/packages/taler-wallet-webextension/src/wallet/Notifications/views.tsx @@ -0,0 +1,220 @@ +/* + This file is part of GNU Taler + (C) 2022 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 { + AbsoluteTime, + AttentionInfo, + AttentionType, +} from "@gnu-taler/taler-util"; +import { Fragment, h, VNode } from "preact"; +import { LoadingError } from "../../components/LoadingError.js"; +import { + Column, + DateSeparator, + HistoryRow, + LargeText, + SmallLightText, +} from "../../components/styled/index.js"; +import { Time } from "../../components/Time.js"; +import { useTranslationContext } from "../../context/translation.js"; +import { Avatar } from "../../mui/Avatar.js"; +import { Button } from "../../mui/Button.js"; +import { Grid } from "../../mui/Grid.js"; +import { Pages } from "../../NavigationBar.js"; +import { assertUnreachable } from "../../utils/index.js"; +import { State } from "./index.js"; + +export function LoadingUriView({ error }: State.LoadingUriError): VNode { + const { i18n } = useTranslationContext(); + + return ( + Could not load notifications} + error={error} + /> + ); +} + +const term = 1000 * 60 * 60 * 24; +function normalizeToDay(x: number): number { + return Math.round(x / term) * term; +} + +export function ReadyView({ list }: State.Ready): VNode { + const { i18n } = useTranslationContext(); + if (list.length < 1) { + return ( +
+ No notification left +
+ ); + } + + const byDate = list.reduce((rv, x) => { + const theDate = x.when.t_ms === "never" ? 0 : normalizeToDay(x.when.t_ms); + if (theDate) { + (rv[theDate] = rv[theDate] || []).push(x); + } + + return rv; + }, {} as { [x: string]: typeof list }); + const datesWithNotifications = Object.keys(byDate); + + return ( +
+ {datesWithNotifications.map((d, i) => { + return ( + + + + {byDate[d].map((n, i) => ( + + ))} + + ); + })} +
+ ); +} + +function NotificationItem({ + info, + isRead, + timestamp, +}: { + info: AttentionInfo; + timestamp: AbsoluteTime; + isRead: boolean; +}): VNode { + switch (info.type) { + case AttentionType.KycWithdrawal: + return ( + + ); + case AttentionType.MerchantRefund: + return ( + + ); + case AttentionType.BackupUnpaid: + return ( + + ); + case AttentionType.AuditorDenominationsExpires: + return
not implemented
; + case AttentionType.AuditorKeyExpires: + return
not implemented
; + case AttentionType.AuditorTosChanged: + return
not implemented
; + case AttentionType.ExchangeDenominationsExpired: + return
not implemented
; + // case AttentionType.ExchangeDenominationsExpiresSoon: + // return
not implemented
; + case AttentionType.ExchangeKeyExpired: + return
not implemented
; + // case AttentionType.ExchangeKeyExpiresSoon: + // return
not implemented
; + case AttentionType.ExchangeTosChanged: + return
not implemented
; + case AttentionType.BackupExpiresSoon: + return
not implemented
; + case AttentionType.PushPaymentReceived: + return
not implemented
; + case AttentionType.PullPaymentPaid: + return
not implemented
; + default: + assertUnreachable(info); + } +} + +function NotificationLayout(props: { + title: string; + href: string; + subtitle?: string; + timestamp: AbsoluteTime; + iconPath: string; + isRead: boolean; +}): VNode { + const { i18n } = useTranslationContext(); + return ( + + + {props.iconPath} + + + +
{props.title}
+ {props.subtitle && ( +
+ {props.subtitle} +
+ )} +
+ + +
+ + + + + +
+ ); +} -- cgit v1.2.3