import db from the wallet web extension
This commit is contained in:
parent
4b289cde5d
commit
cea0ac02b6
@ -1088,3 +1088,11 @@ export const codecForWithdrawFakebankRequest = (): Codec<WithdrawFakebankRequest
|
|||||||
.property("bank", codecForString())
|
.property("bank", codecForString())
|
||||||
.property("exchange", codecForString())
|
.property("exchange", codecForString())
|
||||||
.build("WithdrawFakebankRequest");
|
.build("WithdrawFakebankRequest");
|
||||||
|
|
||||||
|
export interface ImportDb {
|
||||||
|
dump: any;
|
||||||
|
}
|
||||||
|
export const codecForImportDbRequest = (): Codec<ImportDb> =>
|
||||||
|
buildCodecForObject<ImportDb>()
|
||||||
|
.property("dump", codecForAny())
|
||||||
|
.build("ImportDbRequest")
|
||||||
|
@ -45,6 +45,7 @@ import {
|
|||||||
PaytoUri,
|
PaytoUri,
|
||||||
codecForGetFeeForDeposit,
|
codecForGetFeeForDeposit,
|
||||||
codecForListKnownBankAccounts,
|
codecForListKnownBankAccounts,
|
||||||
|
codecForImportDbRequest,
|
||||||
} from "@gnu-taler/taler-util";
|
} from "@gnu-taler/taler-util";
|
||||||
import {
|
import {
|
||||||
addBackupProvider,
|
addBackupProvider,
|
||||||
@ -130,6 +131,7 @@ import {
|
|||||||
AuditorTrustRecord,
|
AuditorTrustRecord,
|
||||||
CoinSourceType,
|
CoinSourceType,
|
||||||
exportDb,
|
exportDb,
|
||||||
|
importDb,
|
||||||
ReserveRecordStatus,
|
ReserveRecordStatus,
|
||||||
WalletStoresV1,
|
WalletStoresV1,
|
||||||
} from "./db.js";
|
} from "./db.js";
|
||||||
@ -997,6 +999,11 @@ async function dispatchRequestInternal(
|
|||||||
const dbDump = await exportDb(ws.db.idbHandle());
|
const dbDump = await exportDb(ws.db.idbHandle());
|
||||||
return dbDump;
|
return dbDump;
|
||||||
}
|
}
|
||||||
|
case "importDb": {
|
||||||
|
const req = codecForImportDbRequest().decode(payload);
|
||||||
|
await importDb(ws.db.idbHandle(), req.dump);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
throw OperationFailedError.fromCode(
|
throw OperationFailedError.fromCode(
|
||||||
TalerErrorCode.WALLET_CORE_API_OPERATION_UNKNOWN,
|
TalerErrorCode.WALLET_CORE_API_OPERATION_UNKNOWN,
|
||||||
|
@ -18,7 +18,7 @@ import { NotificationType } from "@gnu-taler/taler-util";
|
|||||||
import { PendingTaskInfo } from "@gnu-taler/taler-wallet-core";
|
import { PendingTaskInfo } from "@gnu-taler/taler-wallet-core";
|
||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
import { Fragment, h, VNode } from "preact";
|
import { Fragment, h, VNode } from "preact";
|
||||||
import { useState } from "preact/hooks";
|
import { useRef, useState } from "preact/hooks";
|
||||||
import { Diagnostics } from "../components/Diagnostics";
|
import { Diagnostics } from "../components/Diagnostics";
|
||||||
import { NotifyUpdateFadeOut } from "../components/styled";
|
import { NotifyUpdateFadeOut } from "../components/styled";
|
||||||
import { Time } from "../components/Time";
|
import { Time } from "../components/Time";
|
||||||
@ -83,11 +83,34 @@ export function View({
|
|||||||
content,
|
content,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
const fileRef = useRef<HTMLInputElement>(null);
|
||||||
|
async function onImportDatabase(str: string): Promise<void> {
|
||||||
|
return wxApi.importDB(JSON.parse(str));
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<p>Debug tools:</p>
|
<p>Debug tools:</p>
|
||||||
<button onClick={confirmReset}>reset</button>
|
<button onClick={confirmReset}>reset</button>
|
||||||
<br />
|
<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>
|
<button onClick={onExportDatabase}>export database</button>
|
||||||
{downloadedDatabase && (
|
{downloadedDatabase && (
|
||||||
<div>
|
<div>
|
||||||
@ -152,6 +175,8 @@ export function reload(): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function runIntegrationTest() {}
|
||||||
|
|
||||||
export async function confirmReset(): Promise<void> {
|
export async function confirmReset(): Promise<void> {
|
||||||
if (
|
if (
|
||||||
confirm(
|
confirm(
|
||||||
|
@ -110,7 +110,6 @@ export function View({
|
|||||||
setAmount(num);
|
setAmount(num);
|
||||||
setFee(undefined);
|
setFee(undefined);
|
||||||
}
|
}
|
||||||
const feeHasBeenCalculated = fee !== undefined;
|
|
||||||
const currency = balance.currency;
|
const currency = balance.currency;
|
||||||
const amountStr: AmountString = `${currency}:${amount}`;
|
const amountStr: AmountString = `${currency}:${amount}`;
|
||||||
const feeSum =
|
const feeSum =
|
||||||
@ -151,7 +150,7 @@ export function View({
|
|||||||
: !parsedAmount
|
: !parsedAmount
|
||||||
? "Invalid amount"
|
? "Invalid amount"
|
||||||
: Amounts.cmp(balance, parsedAmount) === -1
|
: Amounts.cmp(balance, parsedAmount) === -1
|
||||||
? `To much, your current balance is ${Amounts.stringifyValue(balance)}`
|
? `Too much, your current balance is ${Amounts.stringifyValue(balance)}`
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
const totalToDeposit = parsedAmount
|
const totalToDeposit = parsedAmount
|
||||||
@ -159,7 +158,7 @@ export function View({
|
|||||||
: Amounts.getZero(currency);
|
: Amounts.getZero(currency);
|
||||||
|
|
||||||
const unableToDeposit =
|
const unableToDeposit =
|
||||||
Amounts.isZero(totalToDeposit) && feeHasBeenCalculated;
|
Amounts.isZero(totalToDeposit) || fee === undefined || error !== undefined;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
@ -224,12 +223,13 @@ export function View({
|
|||||||
</section>
|
</section>
|
||||||
<footer>
|
<footer>
|
||||||
<div />
|
<div />
|
||||||
<ButtonPrimary
|
{unableToDeposit ? (
|
||||||
disabled={unableToDeposit}
|
<ButtonPrimary disabled>Deposit</ButtonPrimary>
|
||||||
onClick={() => onSend(accountURI, amountStr)}
|
) : (
|
||||||
>
|
<ButtonPrimary onClick={() => onSend(accountURI, amountStr)}>
|
||||||
Deposit {Amounts.stringifyValue(totalToDeposit)} {currency}
|
Deposit {Amounts.stringifyValue(totalToDeposit)} {currency}
|
||||||
</ButtonPrimary>
|
</ButtonPrimary>
|
||||||
|
)}
|
||||||
</footer>
|
</footer>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
);
|
);
|
||||||
|
@ -376,6 +376,10 @@ export function exportDB(): Promise<any> {
|
|||||||
return callBackend("exportDb", {});
|
return callBackend("exportDb", {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function importDB(dump: any): Promise<void> {
|
||||||
|
return callBackend("importDb", { dump })
|
||||||
|
}
|
||||||
|
|
||||||
export function onUpdateNotification(messageTypes: Array<NotificationType>, doCallback: () => void): () => void {
|
export function onUpdateNotification(messageTypes: Array<NotificationType>, doCallback: () => void): () => void {
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
const port = chrome.runtime.connect({ name: "notifications" });
|
const port = chrome.runtime.connect({ name: "notifications" });
|
||||||
|
Loading…
Reference in New Issue
Block a user