gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] 02/04: wallet effective config


From: gnunet
Subject: [taler-wallet-core] 02/04: wallet effective config
Date: Mon, 24 Apr 2023 18:13:29 +0200

This is an automated email from the git hooks/post-receive script.

sebasjm pushed a commit to branch master
in repository wallet-core.

commit 205d7364ed74d90068ae2a1cc402e77ac2f0bbad
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Mon Apr 24 12:53:20 2023 -0300

    wallet effective config
---
 packages/taler-wallet-core/src/bank-api-client.ts  | 35 ++++++++++---
 packages/taler-wallet-core/src/host-impl.node.ts   |  1 +
 packages/taler-wallet-core/src/host-impl.qtart.ts  |  5 +-
 packages/taler-wallet-core/src/wallet-api-types.ts |  1 +
 packages/taler-wallet-core/src/wallet.ts           | 60 +++++++++++-----------
 5 files changed, 64 insertions(+), 38 deletions(-)

diff --git a/packages/taler-wallet-core/src/bank-api-client.ts 
b/packages/taler-wallet-core/src/bank-api-client.ts
index 94ca2271b..677581e22 100644
--- a/packages/taler-wallet-core/src/bank-api-client.ts
+++ b/packages/taler-wallet-core/src/bank-api-client.ts
@@ -257,6 +257,8 @@ export interface BankAccessApiClientArgs {
   baseUrl: string;
   username: string;
   password: string;
+  enableThrottling?: boolean;
+  allowHttp?: boolean;
 }
 
 export interface BankAccessApiCreateTransactionRequest {
@@ -268,22 +270,30 @@ export class WireGatewayApiClientArgs {
   accountName: string;
   accountPassword: string;
   wireGatewayApiBaseUrl: string;
+  enableThrottling?: boolean;
+  allowHttp?: boolean;
 }
 
+/**
+ * This API look like it belongs to harness
+ * but it will be nice to have in utils to be used by others
+ */
 export class WireGatewayApiClient {
-  httpLib = createPlatformHttpLib();
+  httpLib;
 
-  constructor(private args: WireGatewayApiClientArgs) {}
+  constructor(private args: WireGatewayApiClientArgs) {
+    this.httpLib = createPlatformHttpLib({
+      enableThrottling: !!args.enableThrottling,
+      allowHttp: !!args.allowHttp,
+    });
+  }
 
   async adminAddIncoming(params: {
     amount: string;
     reservePub: string;
     debitAccountPayto: string;
   }): Promise<void> {
-    let url = new URL(
-      `admin/add-incoming`,
-      this.args.wireGatewayApiBaseUrl,
-    );
+    let url = new URL(`admin/add-incoming`, this.args.wireGatewayApiBaseUrl);
     const resp = await this.httpLib.fetch(url.href, {
       method: "POST",
       body: {
@@ -303,10 +313,19 @@ export class WireGatewayApiClient {
   }
 }
 
+/**
+ * This API look like it belongs to harness
+ * but it will be nice to have in utils to be used by others
+ */
 export class BankAccessApiClient {
-  httpLib = createPlatformHttpLib();
+  httpLib;
 
-  constructor(private args: BankAccessApiClientArgs) {}
+  constructor(private args: BankAccessApiClientArgs) {
+    this.httpLib = createPlatformHttpLib({
+      enableThrottling: !!args.enableThrottling,
+      allowHttp: !!args.allowHttp,
+    });
+  }
 
   async getTransactions(): Promise<void> {
     const reqUrl = new URL(
diff --git a/packages/taler-wallet-core/src/host-impl.node.ts 
b/packages/taler-wallet-core/src/host-impl.node.ts
index bf5c14f99..150bba49a 100644
--- a/packages/taler-wallet-core/src/host-impl.node.ts
+++ b/packages/taler-wallet-core/src/host-impl.node.ts
@@ -104,6 +104,7 @@ export async function createNativeWalletHost2(
   } else {
     myHttpLib = createPlatformHttpLib({
       enableThrottling: true,
+      allowHttp: args.config?.features?.allowHttp,
     });
   }
 
diff --git a/packages/taler-wallet-core/src/host-impl.qtart.ts 
b/packages/taler-wallet-core/src/host-impl.qtart.ts
index db7a1fa5c..d10914b10 100644
--- a/packages/taler-wallet-core/src/host-impl.qtart.ts
+++ b/packages/taler-wallet-core/src/host-impl.qtart.ts
@@ -89,7 +89,10 @@ export async function createNativeWalletHost2(
   if (args.httpLib) {
     myHttpLib = args.httpLib;
   } else {
-    myHttpLib = createPlatformHttpLib();
+    myHttpLib = createPlatformHttpLib({
+      enableThrottling: true,
+      allowHttp: args.config?.features?.allowHttp,
+    });
   }
 
   const myVersionChange = (): Promise<void> => {
diff --git a/packages/taler-wallet-core/src/wallet-api-types.ts 
b/packages/taler-wallet-core/src/wallet-api-types.ts
index e85c6ffc3..9ddf82319 100644
--- a/packages/taler-wallet-core/src/wallet-api-types.ts
+++ b/packages/taler-wallet-core/src/wallet-api-types.ts
@@ -247,6 +247,7 @@ export interface WalletConfig {
     denomselAllowLate: boolean;
     devModeActive: boolean;
     insecureTrustExchange: boolean;
+    preventThrottling: boolean;
   };
 
   /**
diff --git a/packages/taler-wallet-core/src/wallet.ts 
b/packages/taler-wallet-core/src/wallet.ts
index 435a4e241..7f78be23a 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -1564,7 +1564,7 @@ export class Wallet {
       http,
       timer,
       cryptoWorkerFactory,
-      config ?? {},
+      Wallet.getEffectiveConfig(config),
     );
   }
 
@@ -1587,8 +1587,33 @@ export class Wallet {
     return w;
   }
 
-  static getDefaultConfig(): Readonly<WalletConfig> {
-    return InternalWalletStateImpl.defaultConfig;
+  public static defaultConfig: Readonly<WalletConfig> = {
+    builtin: {
+      exchanges: ["https://exchange.demo.taler.net/";],
+      auditors: [
+        {
+          currency: "KUDOS",
+          auditorPub: "BW9DC48PHQY4NH011SHHX36DZZ3Q22Y6X7FZ1VD1CMZ2PTFZ6PN0",
+          auditorBaseUrl: "https://auditor.demo.taler.net/";,
+          uids: ["5P25XF8TVQP9AW6VYGY2KV47WT5Y3ZXFSJAA570GJPX5SVJXKBVG"],
+        },
+      ],
+    },
+    features: {
+      batchWithdrawal: false,
+      allowHttp: false,
+    },
+    testing: {
+      devModeActive: false,
+      insecureTrustExchange: false,
+      denomselAllowLate: false,
+    },
+  };
+
+  static getEffectiveConfig(
+    param?: WalletConfigParameter,
+  ): Readonly<WalletConfig> {
+    return deepMerge(Wallet.defaultConfig, param ?? {});
   }
 
   addNotificationListener(f: (n: WalletNotification) => void): void {
@@ -1674,29 +1699,6 @@ class InternalWalletStateImpl implements 
InternalWalletState {
 
   config: Readonly<WalletConfig>;
 
-  public static defaultConfig: Readonly<WalletConfig> = {
-    builtin: {
-      exchanges: ["https://exchange.demo.taler.net/";],
-      auditors: [
-        {
-          currency: "KUDOS",
-          auditorPub: "BW9DC48PHQY4NH011SHHX36DZZ3Q22Y6X7FZ1VD1CMZ2PTFZ6PN0",
-          auditorBaseUrl: "https://auditor.demo.taler.net/";,
-          uids: ["5P25XF8TVQP9AW6VYGY2KV47WT5Y3ZXFSJAA570GJPX5SVJXKBVG"],
-        },
-      ],
-    },
-    features: {
-      batchWithdrawal: false,
-      allowHttp: false,
-    },
-    testing: {
-      devModeActive: false,
-      insecureTrustExchange: false,
-      denomselAllowLate: false,
-    },
-  };
-
   constructor(
     // FIXME: Make this a getter and make
     // the actual value nullable.
@@ -1706,12 +1708,12 @@ class InternalWalletStateImpl implements 
InternalWalletState {
     public http: HttpRequestLibrary,
     public timer: TimerAPI,
     cryptoWorkerFactory: CryptoWorkerFactory,
-    config: WalletConfigParameter,
+    configParam: WalletConfig,
   ) {
     this.cryptoDispatcher = new CryptoDispatcher(cryptoWorkerFactory);
     this.cryptoApi = this.cryptoDispatcher.cryptoApi;
     this.timerGroup = new TimerGroup(timer);
-    this.config = deepMerge(InternalWalletStateImpl.defaultConfig, config);
+    this.config = configParam;
     if (this.config.testing.devModeActive) {
       this.http = new DevExperimentHttpLib(this.http);
     }
@@ -1823,7 +1825,7 @@ class InternalWalletStateImpl implements 
InternalWalletState {
  * @param override
  * @returns
  */
-function deepMerge<T extends object>(full: T, override: any): T {
+function deepMerge<T extends object>(full: T, override: object): T {
   const keys = Object.keys(full);
   const result = { ...full };
   for (const k of keys) {

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]