add bank account record

This commit is contained in:
Sebastian 2022-09-23 15:17:29 -03:00
parent 22e87bb18f
commit fbf0502672
No known key found for this signature in database
GPG Key ID: BE4FF68352439FC1
3 changed files with 113 additions and 12 deletions

View File

@ -600,8 +600,15 @@ export interface WalletCoreVersion {
bank: string; bank: string;
} }
export interface KnownBankAccountsInfo {
uri: PaytoUri;
kyc_completed: boolean;
currency: string;
alias: string,
}
export interface KnownBankAccounts { export interface KnownBankAccounts {
accounts: { [payto: string]: PaytoUri }; accounts: KnownBankAccountsInfo[];
} }
export interface ExchangeTos { export interface ExchangeTos {
@ -1077,6 +1084,29 @@ export const codecForListKnownBankAccounts =
.property("currency", codecOptional(codecForString())) .property("currency", codecOptional(codecForString()))
.build("ListKnownBankAccountsRequest"); .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 { export interface GetExchangeWithdrawalInfo {
exchangeBaseUrl: string; exchangeBaseUrl: string;
amount: AmountJson; amount: AmountJson;

View File

@ -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 { export interface MetaConfigRecord {
key: string; key: string;
value: any; value: any;

View File

@ -93,6 +93,9 @@ import {
TalerErrorDetail, TalerErrorDetail,
codecForTransactionByIdRequest, codecForTransactionByIdRequest,
DenominationInfo, DenominationInfo,
KnownBankAccountsInfo,
codecForAddKnownBankAccounts,
codecForForgetKnownBankAccounts,
} from "@gnu-taler/taler-util"; } from "@gnu-taler/taler-util";
import { TalerCryptoInterface } from "./crypto/cryptoImplementation.js"; import { TalerCryptoInterface } from "./crypto/cryptoImplementation.js";
import { import {
@ -670,27 +673,68 @@ async function listKnownBankAccounts(
ws: InternalWalletState, ws: InternalWalletState,
currency?: string, currency?: string,
): Promise<KnownBankAccounts> { ): Promise<KnownBankAccounts> {
const accounts: { [account: string]: PaytoUri } = {}; const accounts: KnownBankAccountsInfo[] = [];
await ws.db await ws.db
.mktx((x) => [x.withdrawalGroups]) .mktx((x) => [x.bankAccounts])
.runReadOnly(async (tx) => { .runReadOnly(async (tx) => {
const withdrawalGroups = await tx.withdrawalGroups.iter().toArray(); const knownAccounts = await tx.bankAccounts.iter().toArray();
for (const r of withdrawalGroups) { for (const r of knownAccounts) {
const amount = r.rawWithdrawalAmount; if (currency && currency !== r.currency) {
if (currency && currency !== amount.currency) {
continue; continue;
} }
if (r.senderWire) { const payto = parsePaytoUri(r.uri);
const payto = parsePaytoUri(r.senderWire); if (payto) {
if (payto) { accounts.push({
accounts[r.senderWire] = payto; uri: payto,
} alias: r.alias,
kyc_completed: r.kyc_completed,
currency: r.currency,
});
} }
} }
}); });
return { accounts }; 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( async function getExchanges(
ws: InternalWalletState, ws: InternalWalletState,
): Promise<ExchangesListResponse> { ): Promise<ExchangesListResponse> {
@ -1140,6 +1184,16 @@ async function dispatchRequestInternal(
const req = codecForListKnownBankAccounts().decode(payload); const req = codecForListKnownBankAccounts().decode(payload);
return await listKnownBankAccounts(ws, req.currency); 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": { case "getWithdrawalDetailsForUri": {
const req = codecForGetWithdrawalDetailsForUri().decode(payload); const req = codecForGetWithdrawalDetailsForUri().decode(payload);
return await getWithdrawalDetailsForUri(ws, req.talerWithdrawUri); return await getWithdrawalDetailsForUri(ws, req.talerWithdrawUri);