gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-wallet-webex] branch master updated (e8bec33 -> ace1


From: gnunet
Subject: [GNUnet-SVN] [taler-wallet-webex] branch master updated (e8bec33 -> ace1a1b)
Date: Thu, 13 Apr 2017 15:05:43 +0200

This is an automated email from the git hooks/post-receive script.

dold pushed a change to branch master
in repository wallet-webex.

    from e8bec33  add auditor editing
     new 0ef5140  add exchanges to currency info
     new ace1a1b  download/import db from dump page

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/pages/add-auditor.tsx |  2 +-
 src/pages/show-db.html    |  3 +++
 src/pages/show-db.ts      | 39 ++++++++++++++++++++++++++++++++++++++-
 src/types.ts              | 10 ++++++++++
 src/wallet.ts             | 18 +++++++++++++++---
 src/wxBackend.ts          | 27 +++++++++++++++++++++++++++
 6 files changed, 94 insertions(+), 5 deletions(-)

diff --git a/src/pages/add-auditor.tsx b/src/pages/add-auditor.tsx
index 2eb98c4..3ec21f5 100644
--- a/src/pages/add-auditor.tsx
+++ b/src/pages/add-auditor.tsx
@@ -55,7 +55,7 @@ class ConfirmAuditor extends 
ImplicitStateComponent<ConfirmAuditorProps> {
     }
 
     if (!currency) {
-      currency = { name: this.props.currency, auditors: [], fractionalDigits: 
2 };
+      currency = { name: this.props.currency, auditors: [], fractionalDigits: 
2, exchanges: [] };
     }
 
     let newAuditor = { auditorPub: this.props.auditorPub, baseUrl: 
this.props.url, expirationStamp: this.props.expirationStamp };
diff --git a/src/pages/show-db.html b/src/pages/show-db.html
index af8ca6e..1cf11e4 100644
--- a/src/pages/show-db.html
+++ b/src/pages/show-db.html
@@ -10,6 +10,9 @@
   </head>
   <body>
     <h1>DB Dump</h1>
+    <input type="file" id="fileInput" style="display:none">
+    <button id="import">Import Dump</button>
+    <button id="download">Download Dump</button>
     <pre id="dump"></pre>
   </body>
 </html>
diff --git a/src/pages/show-db.ts b/src/pages/show-db.ts
index 71e7438..9552536 100644
--- a/src/pages/show-db.ts
+++ b/src/pages/show-db.ts
@@ -28,7 +28,7 @@ function replacer(match: string, pIndent: string, pKey: 
string, pVal: string,
   var str = '<span class=json-string>';
   var r = pIndent || '';
   if (pKey) {
-    r = r + key + pKey.replace(/[": ]/g, '') + '</span>: ';
+    r = r + key + '"' + pKey.replace(/[": ]/g, '') + '":</span> ';
   }
   if (pVal) {
     r = r + (pVal[0] == '"' ? str : val) + pVal + '</span>';
@@ -53,5 +53,42 @@ document.addEventListener("DOMContentLoaded", () => {
       throw Error();
     }
     el.innerHTML = prettyPrint(resp);
+
+    document.getElementById("download")!.addEventListener("click", (evt) => {
+      console.log("creating download");
+      let element = document.createElement("a");
+      element.setAttribute("href", "data:text/plain;charset=utf-8," + 
encodeURIComponent(JSON.stringify(resp)));
+      element.setAttribute("download", "wallet-dump.txt");
+      element.style.display = "none";
+      document.body.appendChild(element);
+      element.click();
+    });
+
+  });
+
+
+  let fileInput = document.getElementById("fileInput")! as HTMLInputElement;
+  fileInput.onchange = (evt) => {
+    if (!fileInput.files || fileInput.files.length != 1) {
+      alert("please select exactly one file to import");
+      return;
+    }
+    const file = fileInput.files[0];
+    const fr = new FileReader();
+    fr.onload = (e: any) => {
+      console.log("got file");
+      let dump = JSON.parse(e.target.result);
+      console.log("parsed contents", dump);
+      chrome.runtime.sendMessage({ type: 'import-db', detail: { dump } }, 
(resp) => {
+        alert("loaded");
+      });
+    };
+    console.log("reading file", file);
+    fr.readAsText(file);
+  };
+
+  document.getElementById("import")!.addEventListener("click", (evt) => {
+    fileInput.click();
+    evt.preventDefault();
   });
 });
diff --git a/src/types.ts b/src/types.ts
index 6ac8763..5b2fa28 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -82,10 +82,20 @@ export interface AuditorRecord {
   expirationStamp: number;
 }
 
+export interface ExchangeForCurrencyRecord {
+  /**
+   * Priority for automatic selection when withdrawing.
+   */
+  priority: number;
+  pinnedPub: string;
+  baseUrl: string;
+}
+
 export interface CurrencyRecord {
   name: string;
   fractionalDigits: number;
   auditors: AuditorRecord[];
+  exchanges: ExchangeForCurrencyRecord[];
 }
 
 
diff --git a/src/wallet.ts b/src/wallet.ts
index 506cde1..916d8e1 100644
--- a/src/wallet.ts
+++ b/src/wallet.ts
@@ -221,7 +221,8 @@ const builtinCurrencies: CurrencyRecord[] = [
         expirationStamp: (new Date(2027, 1)).getTime(),
         auditorPub: "XN9KMN5G2KGPCAN0E89MM5HE8FV4WBWA9KDTMTDR817MWBCYA7H0",
       },
-    ]
+    ],
+    exchanges: [],
   },
 ];
 
@@ -525,7 +526,8 @@ export class Wallet {
     this.q()
         .iter(Stores.coins)
         .reduce((c: CoinRecord) => {
-          if (c.dirty && !c.transactionPending) {
+          if (c.dirty && !c.transactionPending && !(c.currentAmount.value == 0 
&& c.currentAmount.fraction == 0)) {
+            console.log("resuming pending refresh for coin", c);
             this.refresh(c.coinPub);
           }
         });
@@ -1440,6 +1442,10 @@ export class Wallet {
       throw Error("coin not found");
     }
 
+    if (coin.currentAmount.value == 0 && coin.currentAmount.fraction == 0) {
+      return undefined;
+    }
+
     let exchange = await this.updateExchangeFromUrl(coin.exchangeBaseUrl);
 
     if (!exchange) {
@@ -1466,10 +1472,11 @@ export class Wallet {
     let newCoinDenoms = getWithdrawDenomList(availableAmount,
                                              availableDenoms);
 
+    console.log("refreshing coin", coin);
     console.log("refreshing into", newCoinDenoms);
 
     if (newCoinDenoms.length == 0) {
-      console.log("not refreshing, value too small");
+      console.log(`not refreshing, available amount 
${amountToPretty(availableAmount)} too small`);
       return undefined;
     }
 
@@ -1492,6 +1499,8 @@ export class Wallet {
       return c;
     }
 
+    // Store refresh session and subtract refreshed amount from
+    // coin in the same transaction.
     await this.q()
               .put(Stores.refresh, refreshSession)
               .mutate(Stores.coins, coin.coinPub, mutateCoin)
@@ -1505,12 +1514,15 @@ export class Wallet {
     let refreshSession: RefreshSessionRecord|undefined;
     let oldSession = await this.q().get(Stores.refresh, oldCoinPub);
     if (oldSession) {
+      console.log("got old session for", oldCoinPub);
+      console.log(oldSession);
       refreshSession = oldSession;
     } else {
       refreshSession = await this.createRefreshSession(oldCoinPub);
     }
     if (!refreshSession) {
       // refreshing not necessary
+      console.log("not refreshing", oldCoinPub);
       return;
     }
     this.continueRefreshSession(refreshSession);
diff --git a/src/wxBackend.ts b/src/wxBackend.ts
index 7c31431..7b1a2b3 100644
--- a/src/wxBackend.ts
+++ b/src/wxBackend.ts
@@ -60,6 +60,9 @@ function makeHandlers(db: IDBDatabase,
     ["dump-db"]: function (detail, sender) {
       return exportDb(db);
     },
+    ["import-db"]: function (detail, sender) {
+      return importDb(db, detail.dump);
+    },
     ["get-tab-cookie"]: function (detail, sender) {
       if (!sender || !sender.tab || !sender.tab.id) {
         return Promise.resolve();
@@ -634,6 +637,30 @@ function exportDb(db: IDBDatabase): Promise<any> {
   });
 }
 
+
+function importDb(db: IDBDatabase, dump: any): Promise<void> {
+  console.log("importing db", dump);
+  return new Promise((resolve, reject) => {
+    let tx = db.transaction(Array.from(db.objectStoreNames), "readwrite");
+    for (let storeName in dump.stores) {
+      let objects = [];
+      for (let key in dump.stores[storeName]) {
+        objects.push(dump.stores[storeName][key]);
+      }
+      console.log(`importing ${objects.length} records into ${storeName}`); 
+      let store = tx.objectStore(storeName);
+      let clearReq = store.clear();
+      for (let obj of objects) {
+        store.put(obj);
+      }
+    }
+    tx.addEventListener("complete", () => {
+      resolve();
+    });
+  });
+}
+
+
 function deleteDb() {
   indexedDB.deleteDatabase(DB_NAME);
 }

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]