Skip to content

Commit a926887

Browse files
committed
Refactor method call logic with verbose logging
1 parent 634b369 commit a926887

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

js/src/base/Exchange.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2830,7 +2830,14 @@ export default class Exchange {
28302830
}
28312831
try {
28322832
this.last_proof = undefined;
2833-
const methodCalled = urlToMethodMap[this.id].find(preset_url => url.split("?")[0].startsWith(preset_url));
2833+
const path = url.split("?")[0];
2834+
const idMap = urlToMethodMap[this.id] ?? {};
2835+
const matchedEntry = Object.entries(idMap).find(([prefix]) => path.startsWith(prefix));
2836+
const methodCalled = matchedEntry?.[1] ?? "";
2837+
if (this.verbose) {
2838+
this.log("MethodCalled:", methodCalled + "\n");
2839+
}
2840+
// TODO: make the method Arrays that use verity configurable
28342841
if (this.useVerity && ["get", "post"].includes(method.toLowerCase()) && ["fetchBalance", "fetchDepositAddress", "fetchDepositAddress", "fetchDepositAddresses", "fetchDepositAddressesByNetwork", "fetchDeposits", "withdraw"].includes(methodCalled)) {
28352842
const client = new verity.VerityClient({ prover_url: this.verityProverUrl });
28362843
const lowercase = Object.keys(axiosConfig.headers).map(h => `req:header:${h.toLowerCase()}`).join(",");

ts/src/base/Exchange.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3144,7 +3144,19 @@ export default class Exchange {
31443144

31453145
try {
31463146
this.last_proof = undefined;
3147-
const methodCalled = urlToMethodMap[this.id].find(preset_url=>url.split("?")[0].startsWith(preset_url))
3147+
const path = url.split("?")[0];
3148+
const idMap = urlToMethodMap[this.id] ?? {};
3149+
3150+
const matchedEntry:any = Object.entries(idMap).find(([prefix]) =>
3151+
path.startsWith(prefix)
3152+
);
3153+
3154+
const methodCalled:string = matchedEntry?.[1] ?? "";
3155+
if (this.verbose) {
3156+
this.log("MethodCalled:", methodCalled+ "\n");
3157+
}
3158+
3159+
// TODO: make the method Arrays that use verity configurable
31483160
if (this.useVerity && ["get", "post"].includes(method.toLowerCase()) && ["fetchBalance", "fetchDepositAddress", "fetchDepositAddress", "fetchDepositAddresses", "fetchDepositAddressesByNetwork", "fetchDeposits", "withdraw"].includes(methodCalled)) {
31493161
const client = new verity.VerityClient({ prover_url: this.verityProverUrl });
31503162
const lowercase = Object.keys(axiosConfig.headers).map(h => `req:header:${h.toLowerCase()}`).join(",");

0 commit comments

Comments
 (0)