aboutsummaryrefslogtreecommitdiff
path: root/src/wallet.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/wallet.ts')
-rw-r--r--src/wallet.ts47
1 files changed, 45 insertions, 2 deletions
diff --git a/src/wallet.ts b/src/wallet.ts
index e90a6e3db..825763173 100644
--- a/src/wallet.ts
+++ b/src/wallet.ts
@@ -107,9 +107,15 @@ import {
DownloadedWithdrawInfo,
WithdrawDetails,
AcceptWithdrawalResponse,
+ PurchaseDetails,
} from "./walletTypes";
import { openPromise } from "./promiseUtils";
-import { parsePayUri, parseWithdrawUri, parseTipUri, parseRefundUri } from "./taleruri";
+import {
+ parsePayUri,
+ parseWithdrawUri,
+ parseTipUri,
+ parseRefundUri,
+} from "./taleruri";
interface SpeculativePayData {
payCoinInfo: PayCoinInfo;
@@ -3462,7 +3468,10 @@ export class Wallet {
timestamp: new Date().getTime(),
tipId: res.tipId,
pickupUrl: res.tipPickupUrl,
- totalFees: Amounts.add(withdrawDetails.overhead, withdrawDetails.withdrawFee).amount,
+ totalFees: Amounts.add(
+ withdrawDetails.overhead,
+ withdrawDetails.withdrawFee,
+ ).amount,
};
await this.q().put(Stores.tips, tipRecord);
}
@@ -3585,6 +3594,40 @@ export class Wallet {
};
}
+ async getPurchaseDetails(hc: string): Promise<PurchaseDetails> {
+ const purchase = await this.q().get(Stores.purchases, hc);
+ if (!purchase) {
+ throw Error("unknown purchase");
+ }
+ const refundsDoneAmounts = Object.values(purchase.refundsDone).map(x =>
+ Amounts.parseOrThrow(x.refund_amount),
+ );
+ const refundsPendingAmounts = Object.values(purchase.refundsPending).map(
+ x => Amounts.parseOrThrow(x.refund_amount),
+ );
+ const totalRefundAmount = Amounts.sum([
+ ...refundsDoneAmounts,
+ ...refundsPendingAmounts,
+ ]).amount;
+ const refundsDoneFees = Object.values(purchase.refundsDone).map(x =>
+ Amounts.parseOrThrow(x.refund_amount),
+ );
+ const refundsPendingFees = Object.values(purchase.refundsPending).map(
+ x => Amounts.parseOrThrow(x.refund_amount),
+ );
+ const totalRefundFees = Amounts.sum([
+ ...refundsDoneFees,
+ ...refundsPendingFees,
+ ]).amount;
+ const totalFees = totalRefundFees;
+ return {
+ contractTerms: purchase.contractTerms,
+ hasRefund: purchase.timestamp_refund !== 0,
+ totalRefundAmount: totalRefundAmount,
+ totalRefundAndRefreshFees: totalFees,
+ };
+ }
+
/**
* Reset the retry timeouts for ongoing operations.
*/