aboutsummaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-06-13 14:32:27 +0200
committerFlorian Dold <florian@dold.me>2024-06-13 14:32:27 +0200
commited9d4e4216be4fd69d7c0613cb6ee4605a6de3ce (patch)
tree579b072d4b9f884730986610ce15d9aa3354bbb2 /packages
parentee75c6d7436acf96268c773d14f43e2d9a15b790 (diff)
downloadwallet-core-ed9d4e4216be4fd69d7c0613cb6ee4605a6de3ce.tar.xz
wallet-core: implement getDepositWireTypesForCurrency
Diffstat (limited to 'packages')
-rw-r--r--packages/taler-util/src/wallet-types.ts27
-rw-r--r--packages/taler-wallet-core/src/wallet-api-types.ts15
-rw-r--r--packages/taler-wallet-core/src/wallet.ts42
3 files changed, 83 insertions, 1 deletions
diff --git a/packages/taler-util/src/wallet-types.ts b/packages/taler-util/src/wallet-types.ts
index d23780145..8fa5b1e69 100644
--- a/packages/taler-util/src/wallet-types.ts
+++ b/packages/taler-util/src/wallet-types.ts
@@ -3372,3 +3372,30 @@ export const codecForHintNetworkAvailabilityRequest =
buildCodecForObject<HintNetworkAvailabilityRequest>()
.property("isNetworkAvailable", codecForBoolean())
.build("HintNetworkAvailabilityRequest");
+
+export interface GetDepositWireTypesForCurrencyRequest {
+ currency: string;
+ /**
+ * Optional scope info to further restrict the result.
+ * Currency must match the currency field.
+ */
+ scopeInfo?: ScopeInfo;
+}
+
+export const codecForGetDepositWireTypesForCurrencyRequest =
+ (): Codec<GetDepositWireTypesForCurrencyRequest> =>
+ buildCodecForObject<GetDepositWireTypesForCurrencyRequest>()
+ .property("currency", codecForString())
+ .property("scopeInfo", codecOptional(codecForScopeInfo()))
+ .build("GetDepositWireTypesForCurrencyRequest");
+
+/**
+ * Response with wire types that are supported for a deposit.
+ *
+ * In the future, we might surface more information here, such as debit restrictions
+ * by the exchange, which then can be shown by UIs to the user before they
+ * enter their payment information.
+ */
+export interface GetDepositWireTypesForCurrencyResponse {
+ wireTypes: string[];
+}
diff --git a/packages/taler-wallet-core/src/wallet-api-types.ts b/packages/taler-wallet-core/src/wallet-api-types.ts
index 398feddac..c54ec1360 100644
--- a/packages/taler-wallet-core/src/wallet-api-types.ts
+++ b/packages/taler-wallet-core/src/wallet-api-types.ts
@@ -71,6 +71,8 @@ import {
GetContractTermsDetailsRequest,
GetCurrencySpecificationRequest,
GetCurrencySpecificationResponse,
+ GetDepositWireTypesForCurrencyRequest,
+ GetDepositWireTypesForCurrencyResponse,
GetExchangeEntryByUrlRequest,
GetExchangeEntryByUrlResponse,
GetExchangeResourcesRequest,
@@ -266,7 +268,7 @@ export enum WalletApiOperation {
Shutdown = "shutdown",
HintNetworkAvailability = "hintNetworkAvailability",
CanonicalizeBaseUrl = "canonicalizeBaseUrl",
- GetDepositWireTypesForCurency = "getDepositWireTypesForCurrency",
+ GetDepositWireTypesForCurrency = "getDepositWireTypesForCurrency",
TestingWaitTransactionsFinal = "testingWaitTransactionsFinal",
TestingWaitRefreshesFinal = "testingWaitRefreshesFinal",
TestingWaitTransactionState = "testingWaitTransactionState",
@@ -730,6 +732,16 @@ export type GetExchangeTosOp = {
};
/**
+ * Get wire types that can be used for a deposit operation
+ * with the provided currency.
+ */
+export type GetDepositWireTypesForCurrencyOp = {
+ op: WalletApiOperation.GetDepositWireTypesForCurrency;
+ request: GetDepositWireTypesForCurrencyRequest;
+ response: GetDepositWireTypesForCurrencyResponse;
+};
+
+/**
* Get the current terms of a service of an exchange.
*/
export type GetExchangeDetailedInfoOp = {
@@ -1369,6 +1381,7 @@ export type WalletOperations = {
[WalletApiOperation.TestingGetReserveHistory]: TestingGetReserveHistoryOp;
[WalletApiOperation.TestingResetAllRetries]: TestingResetAllRetriesOp;
[WalletApiOperation.HintNetworkAvailability]: HintNetworkAvailabilityOp;
+ [WalletApiOperation.GetDepositWireTypesForCurrency]: GetDepositWireTypesForCurrencyOp;
};
export type WalletCoreRequestType<
diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts
index 7a69fcb21..2a84d912d 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -103,6 +103,7 @@ import {
codecForGetBalanceDetailRequest,
codecForGetContractTermsDetails,
codecForGetCurrencyInfoRequest,
+ codecForGetDepositWireTypesForCurrencyRequest,
codecForGetExchangeEntryByUrlRequest,
codecForGetExchangeResourcesRequest,
codecForGetExchangeTosRequest,
@@ -215,6 +216,7 @@ import {
getExchangeDetailedInfo,
getExchangeResources,
getExchangeTos,
+ getExchangeWireDetailsInTx,
listExchanges,
lookupExchangeByUri,
} from "./exchanges.js";
@@ -1316,6 +1318,46 @@ async function dispatchRequestInternal(
const dbDump = await exportDb(wex.ws.idb);
return dbDump;
}
+ case WalletApiOperation.GetDepositWireTypesForCurrency: {
+ const req =
+ codecForGetDepositWireTypesForCurrencyRequest().decode(payload);
+ const wtSet: Set<string> = new Set();
+ await wex.db.runReadOnlyTx(
+ { storeNames: ["exchanges", "exchangeDetails"] },
+ async (tx) => {
+ const exchanges = await tx.exchanges.getAll();
+ for (const exchange of exchanges) {
+ const det = await getExchangeWireDetailsInTx(tx, exchange.baseUrl);
+ if (!det) {
+ continue;
+ }
+ if (det.currency !== req.currency) {
+ continue;
+ }
+ for (const acc of det.wireInfo.accounts) {
+ let usable = true;
+ for (const dr of acc.debit_restrictions) {
+ if (dr.type === "deny") {
+ usable = false;
+ break;
+ }
+ }
+ if (!usable) {
+ break;
+ }
+ const parsedPayto = parsePaytoUri(acc.payto_uri);
+ if (!parsedPayto) {
+ continue;
+ }
+ wtSet.add(parsedPayto.targetType);
+ }
+ }
+ },
+ );
+ return {
+ wireTypes: [...wtSet],
+ };
+ }
case WalletApiOperation.ListGlobalCurrencyExchanges: {
const resp: ListGlobalCurrencyExchangesResponse = {
exchanges: [],