From 1c3346cd534143f4dd56a625b963a1a3acfa83d1 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 29 May 2017 16:27:53 +0200 Subject: less ad-hoc messaging, fix some lint warnings --- src/wallet.ts | 73 ++++++++++++----------------------------------------------- 1 file changed, 14 insertions(+), 59 deletions(-) (limited to 'src/wallet.ts') diff --git a/src/wallet.ts b/src/wallet.ts index 743042b97..5564162b9 100644 --- a/src/wallet.ts +++ b/src/wallet.ts @@ -50,9 +50,11 @@ import { Amounts, Auditor, AuditorRecord, + CheckPayResult, CoinPaySig, CoinRecord, CoinStatus, + ConfirmPayResult, Contract, CreateReserveResponse, CurrencyRecord, @@ -63,6 +65,7 @@ import { ExchangeRecord, ExchangeWireFeesRecord, Notifier, + OfferRecord, PayCoinInfo, PaybackConfirmation, PreCoinRecord, @@ -271,48 +274,6 @@ export class ConfirmReserveRequest { } -/** - * Offer record, stored in the wallet's database. - */ -@Checkable.Class() -export class OfferRecord { - /** - * The contract that was offered by the merchant. - */ - @Checkable.Value(Contract) - contract: Contract; - - /** - * Signature by the merchant over the contract details. - */ - @Checkable.String - merchant_sig: string; - - /** - * Hash of the contract terms. - */ - @Checkable.String - H_contract: string; - - /** - * Time when the offer was made. - */ - @Checkable.Number - offer_time: number; - - /** - * Serial ID when the offer is stored in the wallet DB. - */ - @Checkable.Optional(Checkable.Number) - id?: number; - - /** - * Verify that a value matches the schema of this class and convert it into a - * member. - */ - static checked: (obj: any) => OfferRecord; -} - /** * Activity history record. */ @@ -981,14 +942,14 @@ export class Wallet { * Add a contract to the wallet and sign coins, * but do not send them yet. */ - async confirmPay(offer: OfferRecord): Promise { + async confirmPay(offer: OfferRecord): Promise { console.log("executing confirmPay"); const transaction = await this.q().get(Stores.transactions, offer.H_contract); if (transaction) { // Already payed ... - return {}; + return "paid"; } const res = await this.getCoinsForPayment({ @@ -1007,29 +968,25 @@ export class Wallet { if (!res) { console.log("not confirming payment, insufficient coins"); - return { - error: "coins-insufficient", - }; + return "insufficient-balance"; } const {exchangeUrl, cds} = res; const ds = await this.cryptoApi.signDeposit(offer, cds); - await this.recordConfirmPay(offer, - ds, - exchangeUrl); - return {}; + await this.recordConfirmPay(offer, ds, exchangeUrl); + return "paid"; } /** - * Add a contract to the wallet and sign coins, - * but do not send them yet. + * Check if payment for an offer is possible, or if the offer has already + * been payed for. */ - async checkPay(offer: OfferRecord): Promise { + async checkPay(offer: OfferRecord): Promise { // First check if we already payed for it. const transaction = await this.q().get(Stores.transactions, offer.H_contract); if (transaction) { - return {isPayed: true}; + return "insufficient-balance"; } // If not already payed, check if we could pay for it. @@ -1046,11 +1003,9 @@ export class Wallet { if (!res) { console.log("not confirming payment, insufficient coins"); - return { - error: "coins-insufficient", - }; + return "insufficient-balance"; } - return {isPayed: false}; + return "payment-possible"; } -- cgit v1.2.3