aboutsummaryrefslogtreecommitdiff
path: root/src/wallet.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-03-24 16:59:23 +0100
committerFlorian Dold <florian.dold@gmail.com>2017-03-24 16:59:23 +0100
commitdf87dc0242caab05cb27623edf000625d1a7f039 (patch)
treefc2c0103166e3b24112b1cf9805242c56ec04264 /src/wallet.ts
parent76ef6796888ddba2f29a3c634a36e5db72710345 (diff)
downloadwallet-core-df87dc0242caab05cb27623edf000625d1a7f039.tar.xz
add currencies and currency defaults to DB
Diffstat (limited to 'src/wallet.ts')
-rw-r--r--src/wallet.ts68
1 files changed, 67 insertions, 1 deletions
diff --git a/src/wallet.ts b/src/wallet.ts
index 030e60303..a2d9e2ad9 100644
--- a/src/wallet.ts
+++ b/src/wallet.ts
@@ -202,6 +202,38 @@ export interface NonceRecord {
pub: string;
}
+export interface AuditorRecord {
+ baseUrl: string;
+ auditorPub: string;
+ expirationStamp: number;
+}
+
+export interface CurrencyRecord {
+ name: string;
+ fractionalDigits: number;
+ auditors: AuditorRecord[];
+}
+
+export interface ConfigRecord {
+ key: string;
+ value: any;
+}
+
+
+const builtinCurrencies: CurrencyRecord[] = [
+ {
+ name: "KUDOS",
+ fractionalDigits: 2,
+ auditors: [
+ {
+ baseUrl: "https://auditor.demo.taler.net",
+ expirationStamp: (new Date(2027, 1)).getTime(),
+ auditorPub: "XN9KMN5G2KGPCAN0E89MM5HE8FV4WBWA9KDTMTDR817MWBCYA7H0",
+ },
+ ]
+ },
+];
+
function setTimeout(f: any, t: number) {
return chrome.extension.getBackgroundPage().setTimeout(f, t);
@@ -354,7 +386,7 @@ export namespace Stores {
class DenominationsStore extends Store<DenominationRecord> {
constructor() {
- // case needed because of bug in type annotations
+ // cast needed because of bug in type annotations
super("denominations",
{keyPath: ["exchangeBaseUrl", "denomPub"] as any as IDBKeyPath});
}
@@ -363,6 +395,18 @@ export namespace Stores {
denomPubIndex = new Index<string, DenominationRecord>(this, "denomPub", "denomPub");
}
+ class CurrenciesStore extends Store<CurrencyRecord> {
+ constructor() {
+ super("currencies", {keyPath: "name"});
+ }
+ }
+
+ class ConfigStore extends Store<ConfigRecord> {
+ constructor() {
+ super("config", {keyPath: "key"});
+ }
+ }
+
export const exchanges: ExchangeStore = new ExchangeStore();
export const nonces: NonceStore = new NonceStore();
export const transactions: TransactionsStore = new TransactionsStore();
@@ -373,6 +417,8 @@ export namespace Stores {
export const offers: OffersStore = new OffersStore();
export const precoins: Store<PreCoinRecord> = new Store<PreCoinRecord>("precoins", {keyPath: "coinPub"});
export const denominations: DenominationsStore = new DenominationsStore();
+ export const currencies: CurrenciesStore = new CurrenciesStore();
+ export const config: ConfigStore = new ConfigStore();
}
@@ -405,9 +451,29 @@ export class Wallet {
this.notifier = notifier;
this.cryptoApi = new CryptoApi();
+ this.fillDefaults();
this.resumePendingFromDb();
}
+ private async fillDefaults() {
+ let onTrue = (r: QueryRoot) => {
+ console.log("defaults already applied");
+ };
+ let onFalse = (r: QueryRoot) => {
+ console.log("applying defaults");
+ r.put(Stores.config, {key: "currencyDefaultsApplied", value: true})
+ .putAll(Stores.currencies, builtinCurrencies)
+ .finish();
+ };
+ await (
+ this.q()
+ .iter(Stores.config)
+ .filter(x => x.key == "currencyDefaultsApplied")
+ .first()
+ .cond((x) => x && x.value, onTrue, onFalse)
+ );
+ }
+
private startOperation(operationId: string) {
this.runningOperations.add(operationId);