aboutsummaryrefslogtreecommitdiff
path: root/lib/wallet
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2016-11-13 10:17:39 +0100
committerFlorian Dold <florian.dold@gmail.com>2016-11-13 10:17:39 +0100
commiteb84d5747aac0de781d64fb9cdbf2da13006d85e (patch)
tree387d7711e177d151a185e2a9a870c39cc03926ce /lib/wallet
parentb2128609ac8159a14224deba399144b3400c8c20 (diff)
downloadwallet-core-eb84d5747aac0de781d64fb9cdbf2da13006d85e.tar.xz
fix small react issues
Diffstat (limited to 'lib/wallet')
-rw-r--r--lib/wallet/db.ts4
-rw-r--r--lib/wallet/query.ts16
-rw-r--r--lib/wallet/renderHtml.tsx10
-rw-r--r--lib/wallet/wallet.ts37
-rw-r--r--lib/wallet/wxMessaging.ts11
5 files changed, 71 insertions, 7 deletions
diff --git a/lib/wallet/db.ts b/lib/wallet/db.ts
index d4ae1cd48..9cffc164c 100644
--- a/lib/wallet/db.ts
+++ b/lib/wallet/db.ts
@@ -26,7 +26,7 @@ import {IExchangeInfo} from "./types";
*/
const DB_NAME = "taler";
-const DB_VERSION = 10;
+const DB_VERSION = 11;
import {Stores} from "./wallet";
import {Store, Index} from "./query";
@@ -114,4 +114,4 @@ export function exportDb(db: IDBDatabase): Promise<any> {
export function deleteDb() {
indexedDB.deleteDatabase(DB_NAME);
-} \ No newline at end of file
+}
diff --git a/lib/wallet/query.ts b/lib/wallet/query.ts
index c172bbeb7..08e270ea6 100644
--- a/lib/wallet/query.ts
+++ b/lib/wallet/query.ts
@@ -423,6 +423,22 @@ export class QueryRoot implements PromiseLike<void> {
}
+ putWithResult<T>(store: Store<T>, val: T): Promise<IDBValidKey> {
+ const {resolve, promise} = openPromise();
+ let doPutWithResult = (tx: IDBTransaction) => {
+ let req = tx.objectStore(store.name).put(val);
+ req.onsuccess = () => {
+ resolve(req.result);
+ }
+ this.scheduleFinish();
+ };
+ this.addWork(doPutWithResult, store.name, true);
+ return Promise.resolve()
+ .then(() => this.finish())
+ .then(() => promise);
+ }
+
+
mutate<T>(store: Store<T>, key: any, f: (v: T) => T): QueryRoot {
let doPut = (tx: IDBTransaction) => {
let reqGet = tx.objectStore(store.name).get(key);
diff --git a/lib/wallet/renderHtml.tsx b/lib/wallet/renderHtml.tsx
index 6afe32b74..940d5c425 100644
--- a/lib/wallet/renderHtml.tsx
+++ b/lib/wallet/renderHtml.tsx
@@ -34,15 +34,15 @@ export function renderContract(contract: Contract): JSX.Element {
return (
<div>
- <p>{
- i18n.parts`${merchantName}
- wants to enter a contract over ${amount}
- with you.`}
+ <p>
+ The merchant {merchantName}
+ wants to enter a contract over {amount}{" "}
+ with you.
</p>
<p>{i18n`You are about to purchase:`}</p>
<ul>
{contract.products.map(
- (p: any) => (<li>{`${p.description}: ${prettyAmount(p.price)}`}</li>))
+ (p: any, i: number) => (<li key={i}>{`${p.description}: ${prettyAmount(p.price)}`}</li>))
}
</ul>
</div>
diff --git a/lib/wallet/wallet.ts b/lib/wallet/wallet.ts
index 47d42132d..9fb6e5a27 100644
--- a/lib/wallet/wallet.ts
+++ b/lib/wallet/wallet.ts
@@ -142,6 +142,15 @@ export class Offer {
@Checkable.String
H_contract: string;
+ @Checkable.Number
+ offer_time: number;
+
+ /**
+ * Serial ID when the offer is stored in the wallet DB.
+ */
+ @Checkable.Optional(Checkable.Number)
+ id?: number;
+
static checked: (obj: any) => Offer;
}
@@ -297,6 +306,15 @@ export namespace Stores {
timestampIndex = new Index<number,HistoryRecord>(this, "timestamp", "timestamp");
}
+ class OffersStore extends Store<Offer> {
+ constructor() {
+ super("offers", {
+ keyPath: "id",
+ autoIncrement: true
+ });
+ }
+ }
+
class TransactionsStore extends Store<Transaction> {
constructor() {
super("transactions", {keyPath: "contractHash"});
@@ -314,6 +332,7 @@ export namespace Stores {
export let coins: CoinsStore = new CoinsStore();
export let refresh: Store<RefreshSession> = new Store<RefreshSession>("refresh", {keyPath: "meltCoinPub"});
export let history: HistoryStore = new HistoryStore();
+ export let offers: OffersStore = new OffersStore();
export let precoins: Store<PreCoin> = new Store<PreCoin>("precoins", {keyPath: "coinPub"});
}
@@ -585,6 +604,18 @@ export class Wallet {
}
+ async saveOffer(offer: Offer): Promise<number> {
+ console.log(`saving offer in wallet.ts`);
+ let id = await this.q().putWithResult(Stores.offers, offer);
+ this.notifier.notify();
+ console.log(`saved offer with id ${id}`);
+ if (typeof id !== "number") {
+ throw Error("db schema wrong");
+ }
+ return id;
+ }
+
+
/**
* Add a contract to the wallet and sign coins,
* but do not send them yet.
@@ -1525,6 +1556,12 @@ export class Wallet {
return {history};
}
+
+ async getOffer(offerId: number): Promise<any> {
+ let offer = await this.q() .get(Stores.offers, offerId);
+ return offer;
+ }
+
async getExchanges(): Promise<IExchangeInfo[]> {
return this.q()
.iter<IExchangeInfo>(Stores.exchanges)
diff --git a/lib/wallet/wxMessaging.ts b/lib/wallet/wxMessaging.ts
index 1c3876772..07f16f24f 100644
--- a/lib/wallet/wxMessaging.ts
+++ b/lib/wallet/wxMessaging.ts
@@ -168,6 +168,14 @@ function makeHandlers(db: IDBDatabase,
}
return wallet.putHistory(detail.historyEntry);
},
+ ["save-offer"]: function (detail: any) {
+ let offer = detail.offer;
+ if (!offer) {
+ return Promise.resolve({ error: "offer missing" });
+ }
+ console.log("handling safe-offer");
+ return wallet.saveOffer(offer);
+ },
["reserve-creation-info"]: function (detail, sender) {
if (!detail.baseUrl || typeof detail.baseUrl !== "string") {
return Promise.resolve({ error: "bad url" });
@@ -183,6 +191,9 @@ function makeHandlers(db: IDBDatabase,
// TODO: limit history length
return wallet.getHistory();
},
+ ["get-offer"]: function (detail, sender) {
+ return wallet.getOffer(detail.offerId);
+ },
["get-exchanges"]: function (detail, sender) {
return wallet.getExchanges();
},