gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] 04/04: import db from the wallet web extension


From: gnunet
Subject: [taler-wallet-core] 04/04: import db from the wallet web extension
Date: Thu, 13 Jan 2022 05:34:30 +0100

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

sebasjm pushed a commit to branch master
in repository wallet-core.

commit cea0ac02b64c2a575a5788552e813d315e3f3096
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Thu Jan 13 01:33:24 2022 -0300

    import db from the wallet web extension
---
 packages/taler-util/src/walletTypes.ts             |  8 +++++++
 packages/taler-wallet-core/src/wallet.ts           |  7 ++++++
 .../src/popup/DeveloperPage.tsx                    | 27 +++++++++++++++++++++-
 .../src/wallet/DepositPage.tsx                     | 18 +++++++--------
 packages/taler-wallet-webextension/src/wxApi.ts    |  4 ++++
 5 files changed, 54 insertions(+), 10 deletions(-)

diff --git a/packages/taler-util/src/walletTypes.ts 
b/packages/taler-util/src/walletTypes.ts
index 4158dde9..4a871e74 100644
--- a/packages/taler-util/src/walletTypes.ts
+++ b/packages/taler-util/src/walletTypes.ts
@@ -1088,3 +1088,11 @@ export const codecForWithdrawFakebankRequest = (): 
Codec<WithdrawFakebankRequest
     .property("bank", codecForString())
     .property("exchange", codecForString())
     .build("WithdrawFakebankRequest");
+
+export interface ImportDb {
+  dump: any;
+}
+export const codecForImportDbRequest = (): Codec<ImportDb> =>
+  buildCodecForObject<ImportDb>()
+    .property("dump", codecForAny())
+    .build("ImportDbRequest")
diff --git a/packages/taler-wallet-core/src/wallet.ts 
b/packages/taler-wallet-core/src/wallet.ts
index 2f94d5e8..3d83ec21 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -45,6 +45,7 @@ import {
   PaytoUri,
   codecForGetFeeForDeposit,
   codecForListKnownBankAccounts,
+  codecForImportDbRequest,
 } from "@gnu-taler/taler-util";
 import {
   addBackupProvider,
@@ -130,6 +131,7 @@ import {
   AuditorTrustRecord,
   CoinSourceType,
   exportDb,
+  importDb,
   ReserveRecordStatus,
   WalletStoresV1,
 } from "./db.js";
@@ -997,6 +999,11 @@ async function dispatchRequestInternal(
       const dbDump = await exportDb(ws.db.idbHandle());
       return dbDump;
     }
+    case "importDb": {
+      const req = codecForImportDbRequest().decode(payload);
+      await importDb(ws.db.idbHandle(), req.dump);
+      return [];
+    }
   }
   throw OperationFailedError.fromCode(
     TalerErrorCode.WALLET_CORE_API_OPERATION_UNKNOWN,
diff --git a/packages/taler-wallet-webextension/src/popup/DeveloperPage.tsx 
b/packages/taler-wallet-webextension/src/popup/DeveloperPage.tsx
index 840398a4..ea87ba01 100644
--- a/packages/taler-wallet-webextension/src/popup/DeveloperPage.tsx
+++ b/packages/taler-wallet-webextension/src/popup/DeveloperPage.tsx
@@ -18,7 +18,7 @@ import { NotificationType } from "@gnu-taler/taler-util";
 import { PendingTaskInfo } from "@gnu-taler/taler-wallet-core";
 import { format } from "date-fns";
 import { Fragment, h, VNode } from "preact";
-import { useState } from "preact/hooks";
+import { useRef, useState } from "preact/hooks";
 import { Diagnostics } from "../components/Diagnostics";
 import { NotifyUpdateFadeOut } from "../components/styled";
 import { Time } from "../components/Time";
@@ -83,11 +83,34 @@ export function View({
       content,
     });
   }
+  const fileRef = useRef<HTMLInputElement>(null);
+  async function onImportDatabase(str: string): Promise<void> {
+    return wxApi.importDB(JSON.parse(str));
+  }
   return (
     <div>
       <p>Debug tools:</p>
       <button onClick={confirmReset}>reset</button>
       <br />
+      <button onClick={() => fileRef?.current?.click()}>import 
database</button>
+      <input
+        ref={fileRef}
+        style={{ display: "none" }}
+        type="file"
+        onChange={async (e) => {
+          const f: FileList | null = e.currentTarget.files;
+          if (!f || f.length != 1) {
+            return Promise.reject();
+          }
+          const buf = await f[0].arrayBuffer();
+          const str = new Uint8Array(buf).reduce(
+            (data, byte) => data + String.fromCharCode(byte),
+            "",
+          );
+          return onImportDatabase(str);
+        }}
+      />
+      <br />
       <button onClick={onExportDatabase}>export database</button>
       {downloadedDatabase && (
         <div>
@@ -152,6 +175,8 @@ export function reload(): void {
   }
 }
 
+function runIntegrationTest() {}
+
 export async function confirmReset(): Promise<void> {
   if (
     confirm(
diff --git a/packages/taler-wallet-webextension/src/wallet/DepositPage.tsx 
b/packages/taler-wallet-webextension/src/wallet/DepositPage.tsx
index 9e15daa9..abe830e8 100644
--- a/packages/taler-wallet-webextension/src/wallet/DepositPage.tsx
+++ b/packages/taler-wallet-webextension/src/wallet/DepositPage.tsx
@@ -110,7 +110,6 @@ export function View({
     setAmount(num);
     setFee(undefined);
   }
-  const feeHasBeenCalculated = fee !== undefined;
   const currency = balance.currency;
   const amountStr: AmountString = `${currency}:${amount}`;
   const feeSum =
@@ -151,7 +150,7 @@ export function View({
     : !parsedAmount
     ? "Invalid amount"
     : Amounts.cmp(balance, parsedAmount) === -1
-    ? `To much, your current balance is ${Amounts.stringifyValue(balance)}`
+    ? `Too much, your current balance is ${Amounts.stringifyValue(balance)}`
     : undefined;
 
   const totalToDeposit = parsedAmount
@@ -159,7 +158,7 @@ export function View({
     : Amounts.getZero(currency);
 
   const unableToDeposit =
-    Amounts.isZero(totalToDeposit) && feeHasBeenCalculated;
+    Amounts.isZero(totalToDeposit) || fee === undefined || error !== undefined;
 
   return (
     <Fragment>
@@ -224,12 +223,13 @@ export function View({
       </section>
       <footer>
         <div />
-        <ButtonPrimary
-          disabled={unableToDeposit}
-          onClick={() => onSend(accountURI, amountStr)}
-        >
-          Deposit {Amounts.stringifyValue(totalToDeposit)} {currency}
-        </ButtonPrimary>
+        {unableToDeposit ? (
+          <ButtonPrimary disabled>Deposit</ButtonPrimary>
+        ) : (
+          <ButtonPrimary onClick={() => onSend(accountURI, amountStr)}>
+            Deposit {Amounts.stringifyValue(totalToDeposit)} {currency}
+          </ButtonPrimary>
+        )}
       </footer>
     </Fragment>
   );
diff --git a/packages/taler-wallet-webextension/src/wxApi.ts 
b/packages/taler-wallet-webextension/src/wxApi.ts
index dc96efc7..d02a017a 100644
--- a/packages/taler-wallet-webextension/src/wxApi.ts
+++ b/packages/taler-wallet-webextension/src/wxApi.ts
@@ -376,6 +376,10 @@ export function exportDB(): Promise<any> {
   return callBackend("exportDb", {});
 }
 
+export function importDB(dump: any): Promise<void> {
+  return callBackend("importDb", { dump })
+}
+
 export function onUpdateNotification(messageTypes: Array<NotificationType>, 
doCallback: () => void): () => void {
   // eslint-disable-next-line no-undef
   const port = chrome.runtime.connect({ name: "notifications" });

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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