wallet effective config

This commit is contained in:
Sebastian 2023-04-24 12:53:20 -03:00
parent 3004ece1f8
commit 205d7364ed
No known key found for this signature in database
GPG Key ID: 173909D1A5F66069
5 changed files with 64 additions and 38 deletions

View File

@ -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(

View File

@ -104,6 +104,7 @@ export async function createNativeWalletHost2(
} else {
myHttpLib = createPlatformHttpLib({
enableThrottling: true,
allowHttp: args.config?.features?.allowHttp,
});
}

View File

@ -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> => {

View File

@ -247,6 +247,7 @@ export interface WalletConfig {
denomselAllowLate: boolean;
devModeActive: boolean;
insecureTrustExchange: boolean;
preventThrottling: boolean;
};
/**

View File

@ -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) {