From cea0ac02b64c2a575a5788552e813d315e3f3096 Mon Sep 17 00:00:00 2001
From: Sebastian <sebasjm@gmail.com>
Date: Thu, 13 Jan 2022 01:33:24 -0300
Subject: import db from the wallet web extension

---
 .../src/popup/DeveloperPage.tsx                    | 27 +++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

(limited to 'packages/taler-wallet-webextension/src/popup/DeveloperPage.tsx')

diff --git a/packages/taler-wallet-webextension/src/popup/DeveloperPage.tsx b/packages/taler-wallet-webextension/src/popup/DeveloperPage.tsx
index 840398a44..ea87ba01f 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(
-- 
cgit v1.2.3

