aboutsummaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/taler-util/src/walletTypes.ts32
-rw-r--r--packages/taler-wallet-core/src/db.ts17
-rw-r--r--packages/taler-wallet-core/src/wallet.ts76
3 files changed, 113 insertions, 12 deletions
diff --git a/packages/taler-util/src/walletTypes.ts b/packages/taler-util/src/walletTypes.ts
index ec14630d2..35cb14837 100644
--- a/packages/taler-util/src/walletTypes.ts
+++ b/packages/taler-util/src/walletTypes.ts
@@ -600,8 +600,15 @@ export interface WalletCoreVersion {
bank: string;
}
+export interface KnownBankAccountsInfo {
+ uri: PaytoUri;
+ kyc_completed: boolean;
+ currency: string;
+ alias: string,
+}
+
export interface KnownBankAccounts {
- accounts: { [payto: string]: PaytoUri };
+ accounts: KnownBankAccountsInfo[];
}
export interface ExchangeTos {
@@ -1077,6 +1084,29 @@ export const codecForListKnownBankAccounts =
.property("currency", codecOptional(codecForString()))
.build("ListKnownBankAccountsRequest");
+export interface AddKnownBankAccountsRequest {
+ payto: string;
+ alias: string;
+ currency: string;
+}
+export const codecForAddKnownBankAccounts =
+ (): Codec<AddKnownBankAccountsRequest> =>
+ buildCodecForObject<AddKnownBankAccountsRequest>()
+ .property("payto", (codecForString()))
+ .property("alias", (codecForString()))
+ .property("currency", (codecForString()))
+ .build("AddKnownBankAccountsRequest");
+
+export interface ForgetKnownBankAccountsRequest {
+ payto: string;
+}
+
+export const codecForForgetKnownBankAccounts =
+ (): Codec<ForgetKnownBankAccountsRequest> =>
+ buildCodecForObject<ForgetKnownBankAccountsRequest>()
+ .property("payto", (codecForString()))
+ .build("ForgetKnownBankAccountsRequest");
+
export interface GetExchangeWithdrawalInfo {
exchangeBaseUrl: string;
amount: AmountJson;
diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts
index 589f84e15..c33e1c3fb 100644
--- a/packages/taler-wallet-core/src/db.ts
+++ b/packages/taler-wallet-core/src/db.ts
@@ -2084,8 +2084,25 @@ export const WalletStoresV1 = {
}),
{},
),
+ bankAccounts: describeStore(
+ "bankAccounts",
+ describeContents<BankAccountsRecord>({
+ keyPath: "uri",
+ }),
+ {},
+ ),
};
+/**
+ * User accounts
+ */
+export interface BankAccountsRecord {
+ uri: string;
+ currency: string;
+ kyc_completed: boolean;
+ alias: string;
+}
+
export interface MetaConfigRecord {
key: string;
value: any;
diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts
index 3ee37ec1a..7890259f2 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -93,6 +93,9 @@ import {
TalerErrorDetail,
codecForTransactionByIdRequest,
DenominationInfo,
+ KnownBankAccountsInfo,
+ codecForAddKnownBankAccounts,
+ codecForForgetKnownBankAccounts,
} from "@gnu-taler/taler-util";
import { TalerCryptoInterface } from "./crypto/cryptoImplementation.js";
import {
@@ -670,27 +673,68 @@ async function listKnownBankAccounts(
ws: InternalWalletState,
currency?: string,
): Promise<KnownBankAccounts> {
- const accounts: { [account: string]: PaytoUri } = {};
+ const accounts: KnownBankAccountsInfo[] = [];
await ws.db
- .mktx((x) => [x.withdrawalGroups])
+ .mktx((x) => [x.bankAccounts])
.runReadOnly(async (tx) => {
- const withdrawalGroups = await tx.withdrawalGroups.iter().toArray();
- for (const r of withdrawalGroups) {
- const amount = r.rawWithdrawalAmount;
- if (currency && currency !== amount.currency) {
+ const knownAccounts = await tx.bankAccounts.iter().toArray();
+ for (const r of knownAccounts) {
+ if (currency && currency !== r.currency) {
continue;
}
- if (r.senderWire) {
- const payto = parsePaytoUri(r.senderWire);
- if (payto) {
- accounts[r.senderWire] = payto;
- }
+ const payto = parsePaytoUri(r.uri);
+ if (payto) {
+ accounts.push({
+ uri: payto,
+ alias: r.alias,
+ kyc_completed: r.kyc_completed,
+ currency: r.currency,
+ });
}
}
});
return { accounts };
}
+/**
+ */
+async function addKnownBankAccounts(
+ ws: InternalWalletState,
+ payto: string,
+ alias: string,
+ currency: string,
+): Promise<void> {
+ await ws.db
+ .mktx((x) => [x.bankAccounts])
+ .runReadWrite(async (tx) => {
+ tx.bankAccounts.put({
+ uri: payto,
+ alias: alias,
+ currency: currency,
+ kyc_completed: false,
+ });
+ });
+ return;
+}
+
+/**
+ */
+async function forgetKnownBankAccounts(
+ ws: InternalWalletState,
+ payto: string,
+): Promise<void> {
+ await ws.db
+ .mktx((x) => [x.bankAccounts])
+ .runReadWrite(async (tx) => {
+ const account = await tx.bankAccounts.get(payto);
+ if (!account) {
+ throw Error(`account not found: ${payto}`);
+ }
+ tx.bankAccounts.delete(account.uri);
+ });
+ return;
+}
+
async function getExchanges(
ws: InternalWalletState,
): Promise<ExchangesListResponse> {
@@ -1140,6 +1184,16 @@ async function dispatchRequestInternal(
const req = codecForListKnownBankAccounts().decode(payload);
return await listKnownBankAccounts(ws, req.currency);
}
+ case "addKnownBankAccounts": {
+ const req = codecForAddKnownBankAccounts().decode(payload);
+ await addKnownBankAccounts(ws, req.payto, req.alias, req.currency);
+ return {};
+ }
+ case "forgetKnownBankAccounts": {
+ const req = codecForForgetKnownBankAccounts().decode(payload);
+ await forgetKnownBankAccounts(ws, req.payto);
+ return {};
+ }
case "getWithdrawalDetailsForUri": {
const req = codecForGetWithdrawalDetailsForUri().decode(payload);
return await getWithdrawalDetailsForUri(ws, req.talerWithdrawUri);