diff options
Diffstat (limited to 'packages/taler-wallet-webextension/src/wallet/History.stories.tsx')
-rw-r--r-- | packages/taler-wallet-webextension/src/wallet/History.stories.tsx | 672 |
1 files changed, 548 insertions, 124 deletions
diff --git a/packages/taler-wallet-webextension/src/wallet/History.stories.tsx b/packages/taler-wallet-webextension/src/wallet/History.stories.tsx index 0ac4be9a6..482b8d698 100644 --- a/packages/taler-wallet-webextension/src/wallet/History.stories.tsx +++ b/packages/taler-wallet-webextension/src/wallet/History.stories.tsx @@ -1,6 +1,6 @@ /* This file is part of GNU Taler - (C) 2021 Taler Systems S.A. + (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 @@ -15,184 +15,608 @@ */ /** -* -* @author Sebastian Javier Marchano (sebasjm) -*/ + * + * @author Sebastian Javier Marchano (sebasjm) + */ import { + AmountString, PaymentStatus, - TransactionCommon, TransactionDeposit, TransactionPayment, - TransactionRefresh, TransactionRefund, TransactionTip, TransactionType, + RefreshReason, + ScopeType, + TalerProtocolTimestamp, + TransactionCommon, + TransactionDeposit, + TransactionMajorState, + TransactionPayment, + TransactionPeerPullCredit, + TransactionPeerPullDebit, + TransactionPeerPushCredit, + TransactionPeerPushDebit, + TransactionRefresh, + TransactionRefund, + TransactionType, TransactionWithdrawal, - WithdrawalType -} from '@gnu-taler/taler-util'; -import { HistoryView as TestedComponent } from './History'; -import { createExample } from '../test-utils'; - + WithdrawalType, +} from "@gnu-taler/taler-util"; +import { HistoryView as TestedComponent } from "./History.js"; +import * as tests from "@gnu-taler/web-util/testing"; export default { - title: 'wallet/history/list', + title: "history", component: TestedComponent, }; -let count = 0 -const commonTransaction = () => ({ - amountRaw: 'USD:10', - amountEffective: 'USD:9', - pending: false, - timestamp: { - t_ms: new Date().getTime() - (count++ * 1000 * 60 * 60 * 7) - }, - transactionId: '12', -} as TransactionCommon) +let count = 0; +const commonTransaction = (): TransactionCommon => + ({ + amountRaw: "USD:10", + amountEffective: "USD:9", + txState: { + major: TransactionMajorState.Done, + }, + timestamp: TalerProtocolTimestamp.fromSeconds( + new Date().getTime() / 1000 - count++ * 60 * 60 * 7, + ), + transactionId: String(count), + }) as TransactionCommon; const exampleData = { withdraw: { ...commonTransaction(), type: TransactionType.Withdrawal, - exchangeBaseUrl: 'http://exchange.demo.taler.net', + exchangeBaseUrl: "http://exchange.demo.taler.net", withdrawalDetails: { + reservePub: "A05AJGMFNSK4Q62NXR2FKNDB1J4EXTYQTE7VA4M9GZQ4TR06YBNG", confirmed: false, - exchangePaytoUris: ['payto://x-taler-bank/bank/account'], + exchangePaytoUris: ["payto://x-taler-bank/bank/account"], type: WithdrawalType.ManualTransfer, - } + reserveIsReady: false, + }, } as TransactionWithdrawal, payment: { ...commonTransaction(), - amountEffective: 'USD:11', + amountEffective: "USD:11" as AmountString, type: TransactionType.Payment, + posConfirmation: undefined, info: { - contractTermsHash: 'ASDZXCASD', + contractTermsHash: "ASDZXCASD", merchant: { - name: 'Blog', + name: "Blog", }, - orderId: '2021.167-03NPY6MCYMVGT', + orderId: "2021.167-03NPY6MCYMVGT", products: [], - summary: 'the summary', - fulfillmentMessage: '', + summary: "the summary", + fulfillmentMessage: "", }, - proposalId: '1EMJJH8EP1NX3XF7733NCYS2DBEJW4Q2KA5KEB37MCQJQ8Q5HMC0', + refunds: [], + refundPending: undefined, + totalRefundEffective: "USD:0" as AmountString, + totalRefundRaw: "USD:0" as AmountString, + proposalId: "1EMJJH8EP1NX3XF7733NCYS2DBEJW4Q2KA5KEB37MCQJQ8Q5HMC0", status: PaymentStatus.Accepted, + refundQueryActive: false, } as TransactionPayment, deposit: { ...commonTransaction(), type: TransactionType.Deposit, - depositGroupId: '#groupId', - targetPaytoUri: 'payto://x-taler-bank/bank/account', + depositGroupId: "#groupId", + targetPaytoUri: "payto://x-taler-bank/bank/account", } as TransactionDeposit, refresh: { ...commonTransaction(), type: TransactionType.Refresh, - exchangeBaseUrl: 'http://exchange.taler', + refreshInputAmount: "USD:1" as AmountString, + refreshOutputAmount: "USD:0.5" as AmountString, + exchangeBaseUrl: "http://exchange.taler", + refreshReason: RefreshReason.PayMerchant, } as TransactionRefresh, - tip: { - ...commonTransaction(), - type: TransactionType.Tip, - merchantBaseUrl: 'http://ads.merchant.taler.net/', - } as TransactionTip, refund: { ...commonTransaction(), type: TransactionType.Refund, - refundedTransactionId: 'payment:1EMJJH8EP1NX3XF7733NCYS2DBEJW4Q2KA5KEB37MCQJQ8Q5HMC0', - info: { - contractTermsHash: 'ASDZXCASD', + refundedTransactionId: + "payment:1EMJJH8EP1NX3XF7733NCYS2DBEJW4Q2KA5KEB37MCQJQ8Q5HMC0", + paymentInfo: { merchant: { - name: 'the merchant', + name: "the merchant", }, - orderId: '2021.167-03NPY6MCYMVGT', - products: [], - summary: 'the summary', - fulfillmentMessage: '', + summary: "the summary", }, + refundPending: undefined, } as TransactionRefund, -} - -export const Empty = createExample(TestedComponent, { - list: [], - balances: [{ - available: 'TESTKUDOS:10', - pendingIncoming: 'TESTKUDOS:0', - pendingOutgoing: 'TESTKUDOS:0', - hasPendingTransactions: false, - requiresUserInput: false, - }] -}); + push_credit: { + ...commonTransaction(), + type: TransactionType.PeerPushCredit, + info: { + summary: "take this cash", + }, + exchangeBaseUrl: "https://exchange.taler.net", + } as TransactionPeerPushCredit, + push_debit: { + ...commonTransaction(), + type: TransactionType.PeerPushDebit, + talerUri: + "taler://pay-push/exchange.taler.ar/HS585JK0QCXHJ8Z8QWZA3EBAY5WY7XNC1RR2MHJXSH2Z4WP0YPJ0", + info: { + summary: "take this cash", + }, + exchangeBaseUrl: "https://exchange.taler.net", + } as TransactionPeerPushDebit, + pull_credit: { + ...commonTransaction(), + type: TransactionType.PeerPullCredit, + talerUri: + "taler://pay-push/exchange.taler.ar/HS585JK0QCXHJ8Z8QWZA3EBAY5WY7XNC1RR2MHJXSH2Z4WP0YPJ0", + info: { + summary: "pay me", + }, + exchangeBaseUrl: "https://exchange.taler.net", + } as TransactionPeerPullCredit, + pull_debit: { + ...commonTransaction(), + type: TransactionType.PeerPullDebit, + info: { + summary: "pay me", + }, + exchangeBaseUrl: "https://exchange.taler.net", + } as TransactionPeerPullDebit, +}; +export const SomeBalanceWithNoTransactions = tests.createExample( + TestedComponent, + { + transactionsByDate: { + "11/11/11": [], + }, + balances: [ + { + available: "TESTKUDOS:10" as AmountString, + flags: [], + pendingIncoming: "TESTKUDOS:0" as AmountString, + pendingOutgoing: "TESTKUDOS:0" as AmountString, + hasPendingTransactions: false, + requiresUserInput: false, + scopeInfo: { + currency: "Ásd", + type: ScopeType.Auditor, + url: "", + }, + }, + ], + balanceIndex: 0, + }, +); -export const One = createExample(TestedComponent, { - list: [exampleData.withdraw], - balances: [{ - available: 'USD:10', - pendingIncoming: 'USD:0', - pendingOutgoing: 'USD:0', - hasPendingTransactions: false, - requiresUserInput: false, - }] +export const OneSimpleTransaction = tests.createExample(TestedComponent, { + transactionsByDate: { + "11/11/11": [exampleData.withdraw], + }, + balances: [ + { + flags: [], + available: "USD:10" as AmountString, + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, + hasPendingTransactions: false, + requiresUserInput: false, + scopeInfo: { + currency: "Ásd", + type: ScopeType.Auditor, + url: "", + }, + }, + ], + balanceIndex: 0, }); -export const OnePending = createExample(TestedComponent, { - list: [{ - ...exampleData.withdraw, - pending: true - }], - balances: [{ - available: 'USD:10', - pendingIncoming: 'USD:0', - pendingOutgoing: 'USD:0', - hasPendingTransactions: false, - requiresUserInput: false, - }] +export const TwoTransactionsAndZeroBalance = tests.createExample( + TestedComponent, + { + transactionsByDate: { + "11/11/11": [exampleData.withdraw, exampleData.deposit], + }, + balances: [ + { + flags: [], + available: "USD:0" as AmountString, + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, + hasPendingTransactions: false, + requiresUserInput: false, + scopeInfo: { + currency: "Ásd", + type: ScopeType.Auditor, + url: "", + }, + }, + ], + balanceIndex: 0, + }, +); + +export const OneTransactionPending = tests.createExample(TestedComponent, { + transactionsByDate: { + "11/11/11": [ + { + ...exampleData.withdraw, + txState: { + major: TransactionMajorState.Pending, + }, + }, + ], + }, + balances: [ + { + flags: [], + available: "USD:10" as AmountString, + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, + hasPendingTransactions: false, + requiresUserInput: false, + scopeInfo: { + currency: "Ásd", + type: ScopeType.Auditor, + url: "", + }, + }, + ], + balanceIndex: 0, }); -export const Several = createExample(TestedComponent, { - list: [ - exampleData.withdraw, - exampleData.payment, - exampleData.withdraw, - exampleData.payment, +export const SomeTransactions = tests.createExample(TestedComponent, { + transactionsByDate: { + "11/11/11": [ + exampleData.withdraw, + exampleData.payment, + exampleData.withdraw, + exampleData.payment, + { + ...exampleData.payment, + info: { + ...exampleData.payment.info, + summary: + "this is a long summary that may be cropped because its too long", + }, + }, + exampleData.refund, + exampleData.deposit, + ], + }, + balances: [ { - ...exampleData.payment, - info: { - ...exampleData.payment.info, - summary: 'this is a long summary that may be cropped because its too long', + flags: [], + available: "USD:10" as AmountString, + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, + hasPendingTransactions: false, + requiresUserInput: false, + scopeInfo: { + currency: "Ásd", + type: ScopeType.Auditor, + url: "", }, }, - exampleData.refund, - exampleData.tip, - exampleData.deposit, ], - balances: [{ - available: 'TESTKUDOS:10', - pendingIncoming: 'TESTKUDOS:0', - pendingOutgoing: 'TESTKUDOS:0', - hasPendingTransactions: false, - requiresUserInput: false, - }] + balanceIndex: 0, }); -export const SeveralWithTwoCurrencies = createExample(TestedComponent, { - list: [ - exampleData.withdraw, - exampleData.payment, - exampleData.withdraw, - exampleData.payment, - exampleData.refresh, - exampleData.refund, - exampleData.tip, - exampleData.deposit, +export const SomeTransactionsInDifferentStates = tests.createExample( + TestedComponent, + { + transactionsByDate: { + "11/11/11": [ + exampleData.withdraw, + { + ...exampleData.withdraw, + exchangeBaseUrl: "https://aborted/withdrawal", + txState: { + major: TransactionMajorState.Aborted, + }, + }, + { + ...exampleData.withdraw, + exchangeBaseUrl: "https://pending/withdrawal", + txState: { + major: TransactionMajorState.Pending, + }, + }, + { + ...exampleData.withdraw, + exchangeBaseUrl: "https://failed/withdrawal", + txState: { + major: TransactionMajorState.Failed, + }, + }, + { + ...exampleData.payment, + info: { + ...exampleData.payment.info, + summary: "normal payment", + }, + }, + { + ...exampleData.payment, + info: { + ...exampleData.payment.info, + summary: "aborting in progress", + }, + txState: { + major: TransactionMajorState.Aborting, + }, + }, + { + ...exampleData.payment, + info: { + ...exampleData.payment.info, + summary: "aborted payment", + }, + txState: { + major: TransactionMajorState.Aborted, + }, + }, + { + ...exampleData.payment, + info: { + ...exampleData.payment.info, + summary: "pending payment", + }, + txState: { + major: TransactionMajorState.Pending, + }, + }, + { + ...exampleData.payment, + info: { + ...exampleData.payment.info, + summary: "failed payment", + }, + txState: { + major: TransactionMajorState.Failed, + }, + }, + exampleData.refund, + exampleData.deposit, + ], + }, + balances: [ + { + flags: [], + available: "USD:10" as AmountString, + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, + hasPendingTransactions: false, + requiresUserInput: false, + scopeInfo: { + currency: "Ásd", + type: ScopeType.Auditor, + url: "", + }, + }, + ], + balanceIndex: 0, + }, +); + +export const SomeTransactionsWithTwoCurrencies = tests.createExample( + TestedComponent, + { + transactionsByDate: { + "11/11/11": [ + exampleData.withdraw, + exampleData.payment, + exampleData.withdraw, + exampleData.payment, + exampleData.refresh, + exampleData.refund, + exampleData.deposit, + ], + }, + balances: [ + { + flags: [], + available: "USD:0" as AmountString, + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, + hasPendingTransactions: false, + requiresUserInput: false, + scopeInfo: { + currency: "Ásd", + type: ScopeType.Auditor, + url: "", + }, + }, + { + flags: [], + available: "TESTKUDOS:10" as AmountString, + pendingIncoming: "TESTKUDOS:0" as AmountString, + pendingOutgoing: "TESTKUDOS:0" as AmountString, + hasPendingTransactions: false, + requiresUserInput: false, + scopeInfo: { + currency: "Ásd", + type: ScopeType.Auditor, + url: "", + }, + }, + ], + balanceIndex: 0, + }, +); + +export const FiveOfficialCurrencies = tests.createExample(TestedComponent, { + transactionsByDate: { + "11/11/11": [exampleData.withdraw], + }, + balances: [ + { + flags: [], + available: "USD:1000" as AmountString, + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, + hasPendingTransactions: false, + requiresUserInput: false, + scopeInfo: { + currency: "Ásd", + type: ScopeType.Auditor, + url: "", + }, + }, + { + flags: [], + available: "EUR:881" as AmountString, + pendingIncoming: "TESTKUDOS:0" as AmountString, + pendingOutgoing: "TESTKUDOS:0" as AmountString, + hasPendingTransactions: false, + requiresUserInput: false, + scopeInfo: { + currency: "Ásd", + type: ScopeType.Auditor, + url: "", + }, + }, + { + flags: [], + available: "COL:4043000.5" as AmountString, + pendingIncoming: "TESTKUDOS:0" as AmountString, + pendingOutgoing: "TESTKUDOS:0" as AmountString, + hasPendingTransactions: false, + requiresUserInput: false, + scopeInfo: { + currency: "Ásd", + type: ScopeType.Auditor, + url: "", + }, + }, + { + flags: [], + available: "JPY:11564450.6" as AmountString, + pendingIncoming: "TESTKUDOS:0" as AmountString, + pendingOutgoing: "TESTKUDOS:0" as AmountString, + hasPendingTransactions: false, + requiresUserInput: false, + scopeInfo: { + currency: "Ásd", + type: ScopeType.Auditor, + url: "", + }, + }, + { + flags: [], + available: "GBP:736" as AmountString, + pendingIncoming: "TESTKUDOS:0" as AmountString, + pendingOutgoing: "TESTKUDOS:0" as AmountString, + hasPendingTransactions: false, + requiresUserInput: false, + scopeInfo: { + currency: "Ásd", + type: ScopeType.Auditor, + url: "", + }, + }, ], - balances: [{ - available: 'TESTKUDOS:10', - pendingIncoming: 'TESTKUDOS:0', - pendingOutgoing: 'TESTKUDOS:0', - hasPendingTransactions: false, - requiresUserInput: false, - }, { - available: 'USD:10', - pendingIncoming: 'USD:0', - pendingOutgoing: 'USD:0', - hasPendingTransactions: false, - requiresUserInput: false, - }] + balanceIndex: 0, }); +export const FiveOfficialCurrenciesWithHighValue = tests.createExample( + TestedComponent, + { + transactionsByDate: { + "11/11/11": [exampleData.withdraw], + }, + balances: [ + { + flags: [], + available: "USD:881001321230000" as AmountString, + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, + hasPendingTransactions: false, + requiresUserInput: false, + scopeInfo: { + currency: "Ásd", + type: ScopeType.Auditor, + url: "", + }, + }, + { + flags: [], + available: "EUR:10" as AmountString, + pendingIncoming: "TESTKUDOS:0" as AmountString, + pendingOutgoing: "TESTKUDOS:0" as AmountString, + hasPendingTransactions: false, + requiresUserInput: false, + scopeInfo: { + currency: "Ásd", + type: ScopeType.Auditor, + url: "", + }, + }, + { + flags: [], + available: "COL:443000123123000.5123123" as AmountString, + pendingIncoming: "TESTKUDOS:0" as AmountString, + pendingOutgoing: "TESTKUDOS:0" as AmountString, + hasPendingTransactions: false, + scopeInfo: { + currency: "Ásd", + type: ScopeType.Auditor, + url: "", + }, + requiresUserInput: false, + }, + { + flags: [], + available: "JPY:1564450000000.6123123" as AmountString, + pendingIncoming: "TESTKUDOS:0" as AmountString, + pendingOutgoing: "TESTKUDOS:0" as AmountString, + hasPendingTransactions: false, + requiresUserInput: false, + scopeInfo: { + currency: "Ásd", + type: ScopeType.Auditor, + url: "", + }, + }, + { + flags: [], + available: "GBP:736001231231200.23123" as AmountString, + pendingIncoming: "TESTKUDOS:0" as AmountString, + pendingOutgoing: "TESTKUDOS:0" as AmountString, + hasPendingTransactions: false, + requiresUserInput: false, + scopeInfo: { + currency: "Ásd", + type: ScopeType.Auditor, + url: "", + }, + }, + ], + balanceIndex: 0, + }, +); + +export const PeerToPeer = tests.createExample(TestedComponent, { + transactionsByDate: { + "11/11/11": [ + exampleData.pull_credit, + exampleData.pull_debit, + exampleData.push_credit, + exampleData.push_debit, + ], + }, + balances: [ + { + flags: [], + available: "USD:10" as AmountString, + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, + hasPendingTransactions: false, + requiresUserInput: false, + scopeInfo: { + currency: "Ásd", + type: ScopeType.Auditor, + url: "", + }, + }, + ], + balanceIndex: 0, +}); |