diff options
author | Florian Dold <florian.dold@gmail.com> | 2019-08-31 13:27:12 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2019-08-31 13:27:12 +0200 |
commit | c35b3be7957a90bd1e861c0502736aa1eb7acfbf (patch) | |
tree | 0d3277f26ac07131cf94f0600e055b191e88239f /src/wallet.ts | |
parent | c3f47e8f5866838b8c58ad8762d636a2b3ec2217 (diff) | |
download | wallet-core-c35b3be7957a90bd1e861c0502736aa1eb7acfbf.tar.xz |
refund view
Diffstat (limited to 'src/wallet.ts')
-rw-r--r-- | src/wallet.ts | 47 |
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. */ |