From d0a4f9f934cea5bbb3da90ea13ccf91d9fb1c933 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 27 Apr 2016 06:03:04 +0200 Subject: UI fixes --- lib/wallet/wallet.ts | 22 ++++++++++++++++++++++ lib/wallet/wxMessaging.ts | 18 ++++++++++++++++++ 2 files changed, 40 insertions(+) (limited to 'lib/wallet') diff --git a/lib/wallet/wallet.ts b/lib/wallet/wallet.ts index dde7a8248..3c9f3ffed 100644 --- a/lib/wallet/wallet.ts +++ b/lib/wallet/wallet.ts @@ -521,6 +521,28 @@ export class Wallet { } + /** + * Add a contract to the wallet and sign coins, + * but do not send them yet. + */ + checkPay(offer: Offer): Promise { + console.log("executing checkPay"); + return Promise.resolve().then(() => { + return this.getPossibleExchangeCoins(offer.contract.amount, + offer.contract.max_fee, + offer.contract.exchanges) + }).then((mcs) => { + if (Object.keys(mcs).length == 0) { + console.log("not confirming payment, insufficient coins"); + return { + error: "coins-insufficient", + }; + } + return {}; + }); + } + + /** * Retrieve all necessary information for looking up the contract * with the given hash. diff --git a/lib/wallet/wxMessaging.ts b/lib/wallet/wxMessaging.ts index 64b16de8d..164342f4e 100644 --- a/lib/wallet/wxMessaging.ts +++ b/lib/wallet/wxMessaging.ts @@ -99,6 +99,24 @@ function makeHandlers(db: IDBDatabase, return wallet.confirmPay(offer); }, + ["check-pay"]: function(detail, sender) { + let offer; + try { + offer = Offer.checked(detail.offer); + } catch (e) { + if (e instanceof Checkable.SchemaError) { + console.error("schema error:", e.message); + return Promise.resolve({ + error: "invalid contract", + hint: e.message, + detail: detail + }); + } else { + throw e; + } + } + return wallet.checkPay(offer); + }, ["execute-payment"]: function(detail, sender) { return wallet.executePayment(detail.H_contract); }, -- cgit v1.2.3