aboutsummaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-04-24 12:53:20 -0300
committerSebastian <sebasjm@gmail.com>2023-04-24 12:53:20 -0300
commit205d7364ed74d90068ae2a1cc402e77ac2f0bbad (patch)
treea6fba8791c77a891bee2d64ffc4d8cf0c97f76ee /packages
parent3004ece1f8153fdf8ddb283e5d767dd5b5c2e179 (diff)
wallet effective config
Diffstat (limited to 'packages')
-rw-r--r--packages/taler-wallet-core/src/bank-api-client.ts35
-rw-r--r--packages/taler-wallet-core/src/host-impl.node.ts1
-rw-r--r--packages/taler-wallet-core/src/host-impl.qtart.ts5
-rw-r--r--packages/taler-wallet-core/src/wallet-api-types.ts1
-rw-r--r--packages/taler-wallet-core/src/wallet.ts60
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) {