aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/db.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2023-05-05 19:03:44 +0200
committerFlorian Dold <florian@dold.me>2023-05-07 21:51:02 +0200
commit7f0edb6a783d9a50f94f65c815c1280baecaac89 (patch)
treeb4f3bc24fece1f651e8c2f69fc0fcf52e1d6f330 /packages/taler-wallet-core/src/db.ts
parenta0bf83fbb5db026389cc7d203adcff050d5a1b28 (diff)
downloadwallet-core-7f0edb6a783d9a50f94f65c815c1280baecaac89.tar.xz
wallet-core: refund DD37 refactoring
Diffstat (limited to 'packages/taler-wallet-core/src/db.ts')
-rw-r--r--packages/taler-wallet-core/src/db.ts189
1 files changed, 125 insertions, 64 deletions
diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts
index d1258f2f9..92781d2ed 100644
--- a/packages/taler-wallet-core/src/db.ts
+++ b/packages/taler-wallet-core/src/db.ts
@@ -118,7 +118,7 @@ export const CURRENT_DB_CONFIG_KEY = "currentMainDbName";
* backwards-compatible way or object stores and indices
* are added.
*/
-export const WALLET_DB_MINOR_VERSION = 6;
+export const WALLET_DB_MINOR_VERSION = 7;
/**
* Ranges for operation status fields.
@@ -208,7 +208,7 @@ export enum WithdrawalGroupStatus {
* talk to the exchange. Money might have been
* wired or not.
*/
- AbortedExchange = 60
+ AbortedExchange = 60,
}
/**
@@ -1012,63 +1012,6 @@ export interface RefreshSessionRecord {
norevealIndex?: number;
}
-export enum RefundState {
- Failed = "failed",
- Applied = "applied",
- Pending = "pending",
-}
-
-/**
- * State of one refund from the merchant, maintained by the wallet.
- */
-export type WalletRefundItem =
- | WalletRefundFailedItem
- | WalletRefundPendingItem
- | WalletRefundAppliedItem;
-
-export interface WalletRefundItemCommon {
- // Execution time as claimed by the merchant
- executionTime: TalerProtocolTimestamp;
-
- /**
- * Time when the wallet became aware of the refund.
- */
- obtainedTime: TalerProtocolTimestamp;
-
- refundAmount: AmountString;
-
- refundFee: AmountString;
-
- /**
- * Upper bound on the refresh cost incurred by
- * applying this refund.
- *
- * Might be lower in practice when two refunds on the same
- * coin are refreshed in the same refresh operation.
- */
- totalRefreshCostBound: AmountString;
-
- coinPub: string;
-
- rtransactionId: number;
-}
-
-/**
- * Failed refund, either because the merchant did
- * something wrong or it expired.
- */
-export interface WalletRefundFailedItem extends WalletRefundItemCommon {
- type: RefundState.Failed;
-}
-
-export interface WalletRefundPendingItem extends WalletRefundItemCommon {
- type: RefundState.Pending;
-}
-
-export interface WalletRefundAppliedItem extends WalletRefundItemCommon {
- type: RefundState.Applied;
-}
-
export enum RefundReason {
/**
* Normal refund given by the merchant.
@@ -1161,6 +1104,8 @@ export enum PurchaseStatus {
*/
QueryingAutoRefund = 15,
+ PendingAcceptRefund = 16,
+
/**
* Proposal downloaded, but the user needs to accept/reject it.
*/
@@ -1169,12 +1114,12 @@ export enum PurchaseStatus {
/**
* The user has rejected the proposal.
*/
- ProposalRefused = 50,
+ AbortedProposalRefused = 50,
/**
* Downloading or processing the proposal has failed permanently.
*/
- ProposalDownloadFailed = 51,
+ FailedClaim = 51,
/**
* Downloaded proposal was detected as a re-purchase.
@@ -1184,12 +1129,12 @@ export enum PurchaseStatus {
/**
* The payment has been aborted.
*/
- PaymentAbortFinished = 53,
+ AbortedIncompletePayment = 53,
/**
* Payment was successful.
*/
- Paid = 54,
+ Done = 54,
}
/**
@@ -1303,7 +1248,7 @@ export interface PurchaseRecord {
*
* FIXME: Put this into a separate object store?
*/
- refunds: { [refundKey: string]: WalletRefundItem };
+ // refunds: { [refundKey: string]: WalletRefundItem };
/**
* When was the last refund made?
@@ -2152,6 +2097,97 @@ export interface CurrencySettingsRecord {
// Later, we might add stuff related to how the currency is rendered.
}
+export enum RefundGroupStatus {
+ Pending = 10,
+ Done = 50,
+ Failed = 51,
+ Aborted = 52,
+}
+
+/**
+ * Metadata about a group of refunds with the merchant.
+ */
+export interface RefundGroupRecord {
+ status: RefundGroupStatus;
+
+ /**
+ * Timestamp when the refund group was created.
+ */
+ timestampCreated: TalerProtocolTimestamp;
+
+ proposalId: string;
+
+ refundGroupId: string;
+
+ refreshGroupId?: string;
+
+ amountRaw: AmountString;
+
+ /**
+ * Estimated effective amount, based on
+ * refund fees and refresh costs.
+ */
+ amountEffective: AmountString;
+}
+
+export enum RefundItemStatus {
+ /**
+ * Intermittent error that the merchant is
+ * reporting from the exchange.
+ *
+ * We'll try again!
+ */
+ Pending = 10,
+ /**
+ * Refund was obtained successfully.
+ */
+ Done = 50,
+ /**
+ * Permanent error reported by the exchange
+ * for the refund.
+ */
+ Failed = 51,
+}
+
+/**
+ * Refund for a single coin in a payment with a merchant.
+ */
+export interface RefundItemRecord {
+ /**
+ * Auto-increment DB record ID.
+ */
+ id?: number;
+
+ status: RefundItemStatus;
+
+ refundGroupId: string;
+
+ // Execution time as claimed by the merchant
+ executionTime: TalerProtocolTimestamp;
+
+ /**
+ * Time when the wallet became aware of the refund.
+ */
+ obtainedTime: TalerProtocolTimestamp;
+
+ refundAmount: AmountString;
+
+ //refundFee: AmountString;
+
+ /**
+ * Upper bound on the refresh cost incurred by
+ * applying this refund.
+ *
+ * Might be lower in practice when two refunds on the same
+ * coin are refreshed in the same refresh operation.
+ */
+ //totalRefreshCostBound: AmountString;
+
+ coinPub: string;
+
+ rtxid: number;
+}
+
/**
* Schema definition for the IndexedDB
* wallet database.
@@ -2494,6 +2530,31 @@ export const WalletStoresV1 = {
}),
{},
),
+ refundGroups: describeStore(
+ "refundGroups",
+ describeContents<RefundGroupRecord>({
+ keyPath: "refundGroupId",
+ versionAdded: 7,
+ }),
+ {
+ byProposalId: describeIndex("byProposalId", "proposalId"),
+ },
+ ),
+ refundItems: describeStore(
+ "refundItems",
+ describeContents<RefundItemRecord>({
+ keyPath: "id",
+ versionAdded: 7,
+ autoIncrement: true,
+ }),
+ {
+ byCoinPubAndRtxid: describeIndex("byCoinPubAndRtxid", [
+ "coinPub",
+ "rtxid",
+ ]),
+ byRefundGroupId: describeIndex("byRefundGroupId", ["refundGroupId"]),
+ },
+ ),
fixups: describeStore(
"fixups",
describeContents<FixupRecord>({