fix db issue

This commit is contained in:
Florian Dold 2016-10-19 20:16:01 +02:00
parent b0b737f72e
commit 4fd1e07449
3 changed files with 36 additions and 17 deletions

View File

@ -51,6 +51,7 @@ export class Index<S extends IDBValidKey,T> {
constructor(s: Store<T>, indexName: string, keyPath: string | string[]) { constructor(s: Store<T>, indexName: string, keyPath: string | string[]) {
this.storeName = s.name; this.storeName = s.name;
this.indexName = indexName; this.indexName = indexName;
this.keyPath = keyPath;
} }
} }
@ -60,7 +61,7 @@ export class Index<S extends IDBValidKey,T> {
*/ */
export interface QueryStream<T> { export interface QueryStream<T> {
indexJoin<S,I extends IDBValidKey>(index: Index<I,S>, indexJoin<S,I extends IDBValidKey>(index: Index<I,S>,
keyFn: (obj: T) => I): QueryStream<[T, S]>; keyFn: (obj: T) => I): QueryStream<JoinResult<T, S>>;
keyJoin<S,I extends IDBValidKey>(store: Store<S>, keyJoin<S,I extends IDBValidKey>(store: Store<S>,
keyFn: (obj: T) => I): QueryStream<JoinResult<T,S>>; keyFn: (obj: T) => I): QueryStream<JoinResult<T,S>>;
filter(f: (T: any) => boolean): QueryStream<T>; filter(f: (T: any) => boolean): QueryStream<T>;
@ -106,7 +107,7 @@ abstract class QueryStreamBase<T> implements QueryStream<T> {
} }
indexJoin<S,I extends IDBValidKey>(index: Index<I,S>, indexJoin<S,I extends IDBValidKey>(index: Index<I,S>,
keyFn: (obj: T) => I): QueryStream<[T, S]> { keyFn: (obj: T) => I): QueryStream<JoinResult<T, S>> {
this.root.addStoreAccess(index.storeName, false); this.root.addStoreAccess(index.storeName, false);
return new QueryStreamIndexJoin(this, index.storeName, index.indexName, keyFn); return new QueryStreamIndexJoin(this, index.storeName, index.indexName, keyFn);
} }
@ -212,7 +213,7 @@ class QueryStreamFlatMap<T> extends QueryStreamBase<T> {
} }
class QueryStreamIndexJoin<T, S> extends QueryStreamBase<[T, S]> { class QueryStreamIndexJoin<T, S> extends QueryStreamBase<JoinResult<T, S>> {
s: QueryStreamBase<T>; s: QueryStreamBase<T>;
storeName: string; storeName: string;
key: any; key: any;
@ -239,7 +240,7 @@ class QueryStreamIndexJoin<T, S> extends QueryStreamBase<[T, S]> {
req.onsuccess = () => { req.onsuccess = () => {
let cursor = req.result; let cursor = req.result;
if (cursor) { if (cursor) {
f(false, [value, cursor.value], tx); f(false, {left: value, right: cursor.value}, tx);
cursor.continue(); cursor.continue();
} else { } else {
f(true, undefined, tx); f(true, undefined, tx);

View File

@ -320,7 +320,7 @@ export namespace Stores {
super("coins", {keyPath: "coinPub"}); super("coins", {keyPath: "coinPub"});
} }
exchangeBaseUrlIndex = new Index<string,Coin>(this, "exchangeBaseUrl", "exchageBaseUrl"); exchangeBaseUrlIndex = new Index<string,Coin>(this, "exchangeBaseUrl", "exchangeBaseUrl");
} }
class HistoryStore extends Store<HistoryRecord> { class HistoryStore extends Store<HistoryRecord> {
@ -461,10 +461,10 @@ export class Wallet {
let x: number; let x: number;
function storeExchangeCoin(mc: any, url: string) { function storeExchangeCoin(mc: JoinResult<IExchangeInfo, Coin>, url: string) {
let exchange: IExchangeInfo = mc[0]; let exchange: IExchangeInfo = mc.left;
console.log("got coin for exchange", url); console.log("got coin for exchange", url);
let coin: Coin = mc[1]; let coin: Coin = mc.right;
if (coin.suspended) { if (coin.suspended) {
console.log("skipping suspended coin", console.log("skipping suspended coin",
coin.denomPub, coin.denomPub,
@ -517,6 +517,7 @@ export class Wallet {
console.log("not suitable exchanges found"); console.log("not suitable exchanges found");
} }
console.log("exchange coins:");
console.dir(m); console.dir(m);
// We try to find the first exchange where we have // We try to find the first exchange where we have

View File

@ -24,26 +24,37 @@
/// <reference path="../lib/decl/preact.d.ts" /> /// <reference path="../lib/decl/preact.d.ts" />
import {substituteFulfillmentUrl} from "../lib/wallet/helpers"; 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"; import {renderContract, prettyAmount} from "../lib/wallet/renderHtml";
"use strict"; "use strict";
import {getExchanges} from "../lib/wallet/wxApi";
interface DetailState { interface DetailState {
collapsed: boolean; collapsed: boolean;
exchanges: null|IExchangeInfo[];
} }
interface DetailProps { interface DetailProps {
contract: Contract; contract: Contract
collapsed: boolean
} }
class Details extends preact.Component<DetailProps, DetailState> { class Details extends preact.Component<DetailProps, DetailState> {
constructor() { constructor(props: DetailProps) {
super(); super(props);
this.state = { 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) { render(props: DetailProps, state: DetailState) {
@ -51,7 +62,7 @@ class Details extends preact.Component<DetailProps, DetailState> {
return ( return (
<div> <div>
<button className="linky" <button className="linky"
onClick={() => { this.setState({collapsed: false})}}> onClick={() => { this.setState({collapsed: false} as any)}}>
show more details show more details
</button> </button>
</div> </div>
@ -60,7 +71,7 @@ class Details extends preact.Component<DetailProps, DetailState> {
return ( return (
<div> <div>
<button className="linky" <button className="linky"
onClick={() => this.setState({collapsed: true})}> onClick={() => this.setState({collapsed: true} as any)}>
show less details show less details
</button> </button>
<div> <div>
@ -69,6 +80,12 @@ class Details extends preact.Component<DetailProps, DetailState> {
{props.contract.exchanges.map( {props.contract.exchanges.map(
e => <li>{`${e.url}: ${e.master_pub}`}</li>)} e => <li>{`${e.url}: ${e.master_pub}`}</li>)}
</ul> </ul>
Exchanges in the wallet:
<ul>
{(state.exchanges || []).map(
(e: IExchangeInfo) =>
<li>{`${e.baseUrl}: ${e.masterPublicKey}`}</li>)}
</ul>
</div> </div>
</div>); </div>);
} }
@ -143,7 +160,7 @@ class ContractPrompt extends preact.Component<ContractPromptProps, ContractPromp
this.state.error = `Error: ${resp.error}`; this.state.error = `Error: ${resp.error}`;
break; break;
} }
preact.rerender(); this.setState({} as any);
return; return;
} }
let c = d.offer.contract; let c = d.offer.contract;
@ -165,7 +182,7 @@ class ContractPrompt extends preact.Component<ContractPromptProps, ContractPromp
Confirm payment Confirm payment
</button> </button>
{(state.error ? <p className="errorbox">{state.error}</p> : <p />)} {(state.error ? <p className="errorbox">{state.error}</p> : <p />)}
<Details contract={c} /> <Details contract={c} collapsed={!state.error}/>
</div> </div>
); );
} }