From e05ba843a061c8050648ce922f36ed3d8e1cf24a Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 24 Nov 2022 23:16:01 -0300 Subject: fix 7465 --- .../src/NavigationBar.tsx | 45 ++++- .../src/components/AmountField.stories.tsx | 1 - .../src/components/TransactionItem.tsx | 4 +- .../src/cta/InvoicePay/state.ts | 1 + .../src/cta/Payment/index.ts | 17 +- .../src/cta/Payment/state.ts | 8 + .../src/cta/Payment/stories.tsx | 8 + .../src/cta/Payment/views.tsx | 25 ++- .../src/popup/Application.tsx | 4 + .../src/wallet/AddBackupProvider/state.ts | 6 +- .../src/wallet/Application.tsx | 12 +- .../src/wallet/Backup.stories.tsx | 2 + .../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 +++++++++++++++++++++ .../src/wallet/ProviderDetail.stories.tsx | 2 + .../src/wallet/ProviderDetailPage.tsx | 81 +++++--- .../src/wallet/index.stories.tsx | 2 + 20 files changed, 592 insertions(+), 41 deletions(-) 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') diff --git a/packages/taler-wallet-webextension/src/NavigationBar.tsx b/packages/taler-wallet-webextension/src/NavigationBar.tsx index ff2404800..b900fab9d 100644 --- a/packages/taler-wallet-webextension/src/NavigationBar.tsx +++ b/packages/taler-wallet-webextension/src/NavigationBar.tsx @@ -24,7 +24,7 @@ /** * Imports. */ -import { h, VNode } from "preact"; +import { Fragment, h, VNode } from "preact"; import { NavigationHeader, NavigationHeaderHolder, @@ -33,6 +33,11 @@ import { import { useTranslationContext } from "./context/translation.js"; import settingsIcon from "./svg/settings_black_24dp.svg"; import qrIcon from "./svg/qr_code_24px.svg"; +import warningIcon from "./svg/warning_24px.svg"; +import { useAsyncAsHook } from "./hooks/useAsyncAsHook.js"; +import { wxApi } from "./wxApi.js"; +import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; +import { JustInDevMode } from "./components/JustInDevMode.js"; /** * List of pages used by the wallet @@ -102,6 +107,7 @@ export const Pages = { backupProviderAdd: "/backup/provider/add", qr: "/qr", + notifications: "/notifications", settings: "/settings", settingsExchangeAdd: pageDefinition<{ currency?: string }>( "/settings/exchange/add/:currency?", @@ -127,7 +133,21 @@ export const Pages = { ), }; -export function PopupNavBar({ path = "" }: { path?: string }): VNode { +export function PopupNavBar({ + path = "", +}: { + path?: string; +}): // api: typeof wxApi, +VNode { + const api = wxApi; //FIXME: as parameter + const hook = useAsyncAsHook(async () => { + return await api.wallet.call( + WalletApiOperation.GetUserAttentionUnreadCount, + {}, + ); + }); + const attentionCount = !hook || hook.hasError ? 0 : hook.response.total; + const { i18n } = useTranslationContext(); return ( @@ -141,6 +161,17 @@ export function PopupNavBar({ path = "" }: { path?: string }): VNode { Backup
+ {attentionCount > 0 ? ( + + + + ) : ( + + )} Backup - - Dev + + Notifications + + + Dev + + +
diff --git a/packages/taler-wallet-webextension/src/components/AmountField.stories.tsx b/packages/taler-wallet-webextension/src/components/AmountField.stories.tsx index 3183364a8..ff9a71992 100644 --- a/packages/taler-wallet-webextension/src/components/AmountField.stories.tsx +++ b/packages/taler-wallet-webextension/src/components/AmountField.stories.tsx @@ -50,7 +50,6 @@ function RenderAmount(): VNode { Amount} - currency="USD" highestDenom={2000000} lowestDenom={0.01} handler={handler} diff --git a/packages/taler-wallet-webextension/src/components/TransactionItem.tsx b/packages/taler-wallet-webextension/src/components/TransactionItem.tsx index f8b23081d..c2c4b52e3 100644 --- a/packages/taler-wallet-webextension/src/components/TransactionItem.tsx +++ b/packages/taler-wallet-webextension/src/components/TransactionItem.tsx @@ -27,6 +27,7 @@ import { h, VNode } from "preact"; import { useTranslationContext } from "../context/translation.js"; import { Avatar } from "../mui/Avatar.js"; import { Pages } from "../NavigationBar.js"; +import { assertUnreachable } from "../utils/index.js"; import { Column, ExtraLargeText, @@ -175,8 +176,7 @@ export function TransactionItem(props: { tx: Transaction }): VNode { /> ); default: { - const pe: never = tx; - throw Error(`unsupported transaction type ${pe}`); + assertUnreachable(tx); } } } diff --git a/packages/taler-wallet-webextension/src/cta/InvoicePay/state.ts b/packages/taler-wallet-webextension/src/cta/InvoicePay/state.ts index 1846794fc..c7fb48958 100644 --- a/packages/taler-wallet-webextension/src/cta/InvoicePay/state.ts +++ b/packages/taler-wallet-webextension/src/cta/InvoicePay/state.ts @@ -89,6 +89,7 @@ export function useComponentState( const insufficientBalance: PreparePayResult = { status: PreparePayResultType.InsufficientBalance, + talerUri: "taler://pay", proposalId: "fakeID", contractTerms: {} as any, amountRaw: hook.response.p2p.amount, diff --git a/packages/taler-wallet-webextension/src/cta/Payment/index.ts b/packages/taler-wallet-webextension/src/cta/Payment/index.ts index f0270b96c..80822b381 100644 --- a/packages/taler-wallet-webextension/src/cta/Payment/index.ts +++ b/packages/taler-wallet-webextension/src/cta/Payment/index.ts @@ -18,6 +18,7 @@ import { AmountJson, PreparePayResult, PreparePayResultAlreadyConfirmed, + PreparePayResultInsufficientBalance, PreparePayResultPaymentPossible, } from "@gnu-taler/taler-util"; import { Loading } from "../../components/Loading.js"; @@ -26,7 +27,7 @@ import { ButtonHandler } from "../../mui/handlers.js"; import { compose, StateViewMap } from "../../utils/index.js"; import { wxApi } from "../../wxApi.js"; import { useComponentState } from "./state.js"; -import { BaseView, LoadingUriView } from "./views.js"; +import { BaseView, LoadingUriView, LostView } from "./views.js"; export interface Props { talerPayUri?: string; @@ -40,6 +41,7 @@ export type State = | State.LoadingUriError | State.Ready | State.NoEnoughBalance + | State.Lost | State.NoBalanceForCurrency | State.Confirmed; @@ -62,12 +64,15 @@ export namespace State { } export interface NoBalanceForCurrency extends BaseInfo { status: "no-balance-for-currency"; - payStatus: PreparePayResult; + payStatus: + | PreparePayResultInsufficientBalance + | PreparePayResultPaymentPossible + | PreparePayResultAlreadyConfirmed; balance: undefined; } export interface NoEnoughBalance extends BaseInfo { status: "no-enough-balance"; - payStatus: PreparePayResult; + payStatus: PreparePayResultInsufficientBalance; balance: AmountJson; } export interface Ready extends BaseInfo { @@ -77,6 +82,11 @@ export namespace State { balance: AmountJson; } + export interface Lost { + status: "lost"; + error: undefined; + } + export interface Confirmed extends BaseInfo { status: "confirmed"; payStatus: PreparePayResultAlreadyConfirmed; @@ -89,6 +99,7 @@ const viewMapping: StateViewMap = { "loading-uri": LoadingUriView, "no-balance-for-currency": BaseView, "no-enough-balance": BaseView, + lost: LostView, confirmed: BaseView, ready: BaseView, }; diff --git a/packages/taler-wallet-webextension/src/cta/Payment/state.ts b/packages/taler-wallet-webextension/src/cta/Payment/state.ts index 49d022320..b90b1e495 100644 --- a/packages/taler-wallet-webextension/src/cta/Payment/state.ts +++ b/packages/taler-wallet-webextension/src/cta/Payment/state.ts @@ -82,6 +82,14 @@ export function useComponentState( }; } const { payStatus } = hook.response; + + if (payStatus.status === PreparePayResultType.Lost) { + return { + status: "lost", + error: undefined, + }; + } + const amount = Amounts.parseOrThrow(payStatus.amountRaw); const foundBalance = hook.response.balance.balances.find( diff --git a/packages/taler-wallet-webextension/src/cta/Payment/stories.tsx b/packages/taler-wallet-webextension/src/cta/Payment/stories.tsx index 7d5a7694e..fd437d5d2 100644 --- a/packages/taler-wallet-webextension/src/cta/Payment/stories.tsx +++ b/packages/taler-wallet-webextension/src/cta/Payment/stories.tsx @@ -44,6 +44,7 @@ export const NoBalance = createExample(BaseView, { uri: "", payStatus: { status: PreparePayResultType.InsufficientBalance, + talerUri: "taler://pay/..", noncePriv: "", proposalId: "96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0", contractTerms: { @@ -73,6 +74,7 @@ export const NoEnoughBalance = createExample(BaseView, { uri: "", payStatus: { status: PreparePayResultType.InsufficientBalance, + talerUri: "taler://pay/..", noncePriv: "", proposalId: "96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0", contractTerms: { @@ -102,6 +104,7 @@ export const EnoughBalanceButRestricted = createExample(BaseView, { uri: "", payStatus: { status: PreparePayResultType.InsufficientBalance, + talerUri: "taler://pay/..", noncePriv: "", proposalId: "96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0", contractTerms: { @@ -136,6 +139,7 @@ export const PaymentPossible = createExample(BaseView, { uri: "taler://pay/merchant-backend.taler/2021.242-01G2X4275RBWG/?c=66BE594PDZR24744J6EQK52XM0", payStatus: { status: PreparePayResultType.PaymentPossible, + talerUri: "taler://pay/..", amountEffective: "USD:10", amountRaw: "USD:10", noncePriv: "", @@ -176,6 +180,7 @@ export const PaymentPossibleWithFee = createExample(BaseView, { uri: "taler://pay/merchant-backend.taler/2021.242-01G2X4275RBWG/?c=66BE594PDZR24744J6EQK52XM0", payStatus: { status: PreparePayResultType.PaymentPossible, + talerUri: "taler://pay/..", amountEffective: "USD:10.20", amountRaw: "USD:10", noncePriv: "", @@ -213,6 +218,7 @@ export const TicketWithAProductList = createExample(BaseView, { uri: "taler://pay/merchant-backend.taler/2021.242-01G2X4275RBWG/?c=66BE594PDZR24744J6EQK52XM0", payStatus: { status: PreparePayResultType.PaymentPossible, + talerUri: "taler://pay/..", amountEffective: "USD:10.20", amountRaw: "USD:10", noncePriv: "", @@ -269,6 +275,7 @@ export const TicketWithShipping = createExample(BaseView, { uri: "taler://pay/merchant-backend.taler/2021.242-01G2X4275RBWG/?c=66BE594PDZR24744J6EQK52XM0", payStatus: { status: PreparePayResultType.PaymentPossible, + talerUri: "taler://pay/..", amountEffective: "USD:10.20", amountRaw: "USD:10", noncePriv: "", @@ -315,6 +322,7 @@ export const AlreadyConfirmedByOther = createExample(BaseView, { uri: "taler://pay/merchant-backend.taler/2021.242-01G2X4275RBWG/?c=66BE594PDZR24744J6EQK52XM0", payStatus: { status: PreparePayResultType.AlreadyConfirmed, + talerUri: "taler://pay/..", amountEffective: "USD:10", amountRaw: "USD:10", contractTerms: { diff --git a/packages/taler-wallet-webextension/src/cta/Payment/views.tsx b/packages/taler-wallet-webextension/src/cta/Payment/views.tsx index d9b6eaa02..6b502a87f 100644 --- a/packages/taler-wallet-webextension/src/cta/Payment/views.tsx +++ b/packages/taler-wallet-webextension/src/cta/Payment/views.tsx @@ -26,6 +26,7 @@ import { import { Fragment, h, VNode } from "preact"; import { useState } from "preact/hooks"; import { Amount } from "../../components/Amount.js"; +import { ErrorMessage } from "../../components/ErrorMessage.js"; import { LoadingError } from "../../components/LoadingError.js"; import { LogoHeader } from "../../components/LogoHeader.js"; import { Part } from "../../components/Part.js"; @@ -43,6 +44,7 @@ import { Time } from "../../components/Time.js"; import { useTranslationContext } from "../../context/translation.js"; import { Button } from "../../mui/Button.js"; import { ButtonHandler } from "../../mui/handlers.js"; +import { assertUnreachable } from "../../utils/index.js"; import { MerchantDetails, PurchaseDetails } from "../../wallet/Transaction.js"; import { State } from "./index.js"; @@ -63,8 +65,24 @@ type SupportedStates = | State.NoBalanceForCurrency | State.NoEnoughBalance; +export function LostView(state: State.Lost): VNode { + const { i18n } = useTranslationContext(); + + return ( + Could not load pay status} + description={ + + The proposal was lost, another should be downloaded + + } + /> + ); +} + export function BaseView(state: SupportedStates): VNode { const { i18n } = useTranslationContext(); + const contractTerms: ContractTerms = state.payStatus.contractTerms; const price = { @@ -399,8 +417,9 @@ export function ButtonsSection({ ); } + if (payStatus.status === PreparePayResultType.Lost) { + return ; + } - const error: never = payStatus; - - return ; + assertUnreachable(payStatus); } diff --git a/packages/taler-wallet-webextension/src/popup/Application.tsx b/packages/taler-wallet-webextension/src/popup/Application.tsx index 457f26cfd..8186c6790 100644 --- a/packages/taler-wallet-webextension/src/popup/Application.tsx +++ b/packages/taler-wallet-webextension/src/popup/Application.tsx @@ -150,6 +150,10 @@ export function Application(): VNode { component={RedirectToWalletPage} /> + diff --git a/packages/taler-wallet-webextension/src/wallet/AddBackupProvider/state.ts b/packages/taler-wallet-webextension/src/wallet/AddBackupProvider/state.ts index 0b3c17902..504ee4678 100644 --- a/packages/taler-wallet-webextension/src/wallet/AddBackupProvider/state.ts +++ b/packages/taler-wallet-webextension/src/wallet/AddBackupProvider/state.ts @@ -171,7 +171,11 @@ export function useComponentState( switch (resp.status) { case "payment-required": - return onPaymentRequired(resp.talerUri); + if (resp.talerUri) { + return onPaymentRequired(resp.talerUri); + } else { + return onComplete(url); + } case "error": return setOperationError(resp.error); case "ok": diff --git a/packages/taler-wallet-webextension/src/wallet/Application.tsx b/packages/taler-wallet-webextension/src/wallet/Application.tsx index 6b265c1ba..6362f1924 100644 --- a/packages/taler-wallet-webextension/src/wallet/Application.tsx +++ b/packages/taler-wallet-webextension/src/wallet/Application.tsx @@ -66,6 +66,7 @@ import { TransferPickupPage } from "../cta/TransferPickup/index.js"; import { InvoicePayPage } from "../cta/InvoicePay/index.js"; import { RecoveryPage } from "../cta/Recovery/index.js"; import { AddBackupProviderPage } from "./AddBackupProvider/index.js"; +import { NotificationsPage } from "./Notifications/index.js"; export function Application(): VNode { const [globalNotification, setGlobalNotification] = useState< @@ -206,6 +207,7 @@ export function Application(): VNode { /> + {/** * BACKUP @@ -218,6 +220,12 @@ export function Application(): VNode { + redirectTo(`${Pages.ctaPay}?talerPayUri=${uri}`) + } + onWithdraw={(amount: string) => + redirectTo(Pages.receiveCash({ amount })) + } onBack={() => redirectTo(Pages.backup)} /> - redirectTo(Pages.ctaWithdrawManual({ amount })) + redirectTo(Pages.receiveCash({ amount })) } cancel={() => redirectTo(Pages.balance)} onSuccess={(tid: string) => @@ -321,7 +329,7 @@ export function Application(): VNode { path={Pages.ctaInvoicePay} component={InvoicePayPage} goToWalletManualWithdraw={(amount?: string) => - redirectTo(Pages.ctaWithdrawManual({ amount })) + redirectTo(Pages.receiveCash({ amount })) } onClose={() => redirectTo(Pages.balance)} onSuccess={(tid: string) => diff --git a/packages/taler-wallet-webextension/src/wallet/Backup.stories.tsx b/packages/taler-wallet-webextension/src/wallet/Backup.stories.tsx index b12f5e5f6..2e19d3944 100644 --- a/packages/taler-wallet-webextension/src/wallet/Backup.stories.tsx +++ b/packages/taler-wallet-webextension/src/wallet/Backup.stories.tsx @@ -89,6 +89,7 @@ export const LotOfProviders = createExample(TestedComponent, { paymentProposalIds: [], paymentStatus: { type: ProviderPaymentType.Pending, + talerUri: "taler://", }, terms: { annualFee: "KUDOS:0.1", @@ -103,6 +104,7 @@ export const LotOfProviders = createExample(TestedComponent, { paymentProposalIds: [], paymentStatus: { type: ProviderPaymentType.InsufficientBalance, + amount: "KUDOS:10", }, terms: { annualFee: "KUDOS:0.1", 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} +
+ )} +
+ + +
+ + + + + +
+ ); +} diff --git a/packages/taler-wallet-webextension/src/wallet/ProviderDetail.stories.tsx b/packages/taler-wallet-webextension/src/wallet/ProviderDetail.stories.tsx index d55a25e78..854c14ac1 100644 --- a/packages/taler-wallet-webextension/src/wallet/ProviderDetail.stories.tsx +++ b/packages/taler-wallet-webextension/src/wallet/ProviderDetail.stories.tsx @@ -174,6 +174,7 @@ export const InactiveInsufficientBalance = createExample(TestedComponent, { paymentProposalIds: [], paymentStatus: { type: ProviderPaymentType.InsufficientBalance, + amount: "EUR:123", }, terms: { annualFee: "EUR:0.1", @@ -191,6 +192,7 @@ export const InactivePending = createExample(TestedComponent, { paymentProposalIds: [], paymentStatus: { type: ProviderPaymentType.Pending, + talerUri: "taler://pay/sad", }, terms: { annualFee: "EUR:0.1", diff --git a/packages/taler-wallet-webextension/src/wallet/ProviderDetailPage.tsx b/packages/taler-wallet-webextension/src/wallet/ProviderDetailPage.tsx index d9dd1d746..6dde30b39 100644 --- a/packages/taler-wallet-webextension/src/wallet/ProviderDetailPage.tsx +++ b/packages/taler-wallet-webextension/src/wallet/ProviderDetailPage.tsx @@ -36,9 +36,16 @@ import { wxApi } from "../wxApi.js"; interface Props { pid: string; onBack: () => Promise; + onPayProvider: (uri: string) => Promise; + onWithdraw: (amount: string) => Promise; } -export function ProviderDetailPage({ pid: providerURL, onBack }: Props): VNode { +export function ProviderDetailPage({ + pid: providerURL, + onBack, + onPayProvider, + onWithdraw, +}: Props): VNode { const { i18n } = useTranslationContext(); async function getProviderInfo(): Promise { //create a first list of backup info by currency @@ -71,11 +78,30 @@ export function ProviderDetailPage({ pid: providerURL, onBack }: Props): VNode { /> ); } + const info = state.response; + if (info === null) { + return ( + +
+

+ + There is not known provider with url "{providerURL}". + +

+
+
+ +
+
+
+ ); + } return ( wxApi.wallet .call(WalletApiOperation.RunBackupCycle, { @@ -83,6 +109,16 @@ export function ProviderDetailPage({ pid: providerURL, onBack }: Props): VNode { }) .then() } + onPayProvider={async () => { + if (info.paymentStatus.type !== ProviderPaymentType.Pending) return; + if (!info.paymentStatus.talerUri) return; + onPayProvider(info.paymentStatus.talerUri); + }} + onWithdraw={async () => { + if (info.paymentStatus.type !== ProviderPaymentType.InsufficientBalance) + return; + onWithdraw(info.paymentStatus.amount); + }} onDelete={() => wxApi.wallet .call(WalletApiOperation.RemoveBackupProvider, { @@ -99,42 +135,25 @@ export function ProviderDetailPage({ pid: providerURL, onBack }: Props): VNode { } export interface ViewProps { - url: string; - info: ProviderInfo | null; + info: ProviderInfo; onDelete: () => Promise; onSync: () => Promise; onBack: () => Promise; onExtend: () => Promise; + onPayProvider: () => Promise; + onWithdraw: () => Promise; } export function ProviderView({ info, - url, onDelete, + onPayProvider, + onWithdraw, onSync, onBack, onExtend, }: ViewProps): VNode { const { i18n } = useTranslationContext(); - if (info === null) { - return ( - -
-

- - There is not known provider with url "{url}". - -

-
-
- -
-
-
- ); - } const lb = info.lastSuccessfulBackupTimestamp ? AbsoluteTime.fromTimestamp(info.lastSuccessfulBackupTimestamp) : undefined; @@ -230,6 +249,18 @@ export function ProviderView({ + {info.paymentStatus.type === ProviderPaymentType.Pending && + info.paymentStatus.talerUri ? ( + + ) : undefined} + {info.paymentStatus.type === + ProviderPaymentType.InsufficientBalance ? ( + + ) : undefined}
diff --git a/packages/taler-wallet-webextension/src/wallet/index.stories.tsx b/packages/taler-wallet-webextension/src/wallet/index.stories.tsx index ef1295846..20de1a3c3 100644 --- a/packages/taler-wallet-webextension/src/wallet/index.stories.tsx +++ b/packages/taler-wallet-webextension/src/wallet/index.stories.tsx @@ -36,6 +36,7 @@ import * as a17 from "./QrReader.stories.js"; import * as a18 from "./DestinationSelection.stories.js"; import * as a19 from "./ExchangeSelection/stories.js"; import * as a20 from "./ManageAccount/stories.js"; +import * as a21 from "./Notifications/stories.js"; export default [ a1, @@ -55,4 +56,5 @@ export default [ a18, a19, a20, + a21, ]; -- cgit v1.2.3