From 4fd1e07449c97619dbf1e0e17baa47168644dba9 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 19 Oct 2016 20:16:01 +0200 Subject: fix db issue --- lib/wallet/query.ts | 9 +++++---- lib/wallet/wallet.ts | 9 +++++---- pages/confirm-contract.tsx | 35 ++++++++++++++++++++++++++--------- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/lib/wallet/query.ts b/lib/wallet/query.ts index 3571c32c7..c369e4b67 100644 --- a/lib/wallet/query.ts +++ b/lib/wallet/query.ts @@ -51,6 +51,7 @@ export class Index { constructor(s: Store, indexName: string, keyPath: string | string[]) { this.storeName = s.name; this.indexName = indexName; + this.keyPath = keyPath; } } @@ -60,7 +61,7 @@ export class Index { */ export interface QueryStream { indexJoin(index: Index, - keyFn: (obj: T) => I): QueryStream<[T, S]>; + keyFn: (obj: T) => I): QueryStream>; keyJoin(store: Store, keyFn: (obj: T) => I): QueryStream>; filter(f: (T: any) => boolean): QueryStream; @@ -106,7 +107,7 @@ abstract class QueryStreamBase implements QueryStream { } indexJoin(index: Index, - keyFn: (obj: T) => I): QueryStream<[T, S]> { + keyFn: (obj: T) => I): QueryStream> { this.root.addStoreAccess(index.storeName, false); return new QueryStreamIndexJoin(this, index.storeName, index.indexName, keyFn); } @@ -212,7 +213,7 @@ class QueryStreamFlatMap extends QueryStreamBase { } -class QueryStreamIndexJoin extends QueryStreamBase<[T, S]> { +class QueryStreamIndexJoin extends QueryStreamBase> { s: QueryStreamBase; storeName: string; key: any; @@ -239,7 +240,7 @@ class QueryStreamIndexJoin extends QueryStreamBase<[T, S]> { req.onsuccess = () => { let cursor = req.result; if (cursor) { - f(false, [value, cursor.value], tx); + f(false, {left: value, right: cursor.value}, tx); cursor.continue(); } else { f(true, undefined, tx); diff --git a/lib/wallet/wallet.ts b/lib/wallet/wallet.ts index 380243b44..851b7b048 100644 --- a/lib/wallet/wallet.ts +++ b/lib/wallet/wallet.ts @@ -320,7 +320,7 @@ export namespace Stores { super("coins", {keyPath: "coinPub"}); } - exchangeBaseUrlIndex = new Index(this, "exchangeBaseUrl", "exchageBaseUrl"); + exchangeBaseUrlIndex = new Index(this, "exchangeBaseUrl", "exchangeBaseUrl"); } class HistoryStore extends Store { @@ -461,10 +461,10 @@ export class Wallet { let x: number; - function storeExchangeCoin(mc: any, url: string) { - let exchange: IExchangeInfo = mc[0]; + function storeExchangeCoin(mc: JoinResult, url: string) { + let exchange: IExchangeInfo = mc.left; console.log("got coin for exchange", url); - let coin: Coin = mc[1]; + let coin: Coin = mc.right; if (coin.suspended) { console.log("skipping suspended coin", coin.denomPub, @@ -517,6 +517,7 @@ export class Wallet { console.log("not suitable exchanges found"); } + console.log("exchange coins:"); console.dir(m); // We try to find the first exchange where we have diff --git a/pages/confirm-contract.tsx b/pages/confirm-contract.tsx index a30046c2d..5867051ac 100644 --- a/pages/confirm-contract.tsx +++ b/pages/confirm-contract.tsx @@ -24,26 +24,37 @@ /// import {substituteFulfillmentUrl} from "../lib/wallet/helpers"; -import {Contract, AmountJson} from "../lib/wallet/types"; +import {Contract, AmountJson, IExchangeInfo} from "../lib/wallet/types"; import {renderContract, prettyAmount} from "../lib/wallet/renderHtml"; "use strict"; +import {getExchanges} from "../lib/wallet/wxApi"; interface DetailState { collapsed: boolean; + exchanges: null|IExchangeInfo[]; } interface DetailProps { - contract: Contract; + contract: Contract + collapsed: boolean } class Details extends preact.Component { - constructor() { - super(); + constructor(props: DetailProps) { + super(props); this.state = { - collapsed: true + collapsed: props.collapsed, + exchanges: null }; + + this.update(); + } + + async update() { + let exchanges = await getExchanges(); + this.setState({exchanges} as any); } render(props: DetailProps, state: DetailState) { @@ -51,7 +62,7 @@ class Details extends preact.Component { return (
@@ -60,7 +71,7 @@ class Details extends preact.Component { return (
@@ -69,6 +80,12 @@ class Details extends preact.Component { {props.contract.exchanges.map( e =>
  • {`${e.url}: ${e.master_pub}`}
  • )} + Exchanges in the wallet: +
      + {(state.exchanges || []).map( + (e: IExchangeInfo) => +
    • {`${e.baseUrl}: ${e.masterPublicKey}`}
    • )} +
    ); } @@ -143,7 +160,7 @@ class ContractPrompt extends preact.Component {(state.error ?

    {state.error}

    :

    )} -

    +
    ); } -- cgit v1.2.3