@routstr/sdk 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/index.js +12 -4
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +12 -4
- package/dist/client/index.mjs.map +1 -1
- package/dist/index.d.mts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +17 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +17 -5
- package/dist/index.mjs.map +1 -1
- package/dist/wallet/index.js +3 -0
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs +3 -0
- package/dist/wallet/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/client/index.mjs
CHANGED
|
@@ -679,6 +679,9 @@ var BalanceManager = class {
|
|
|
679
679
|
fetchResult.token
|
|
680
680
|
);
|
|
681
681
|
const totalAmountMsat = receiveResult.unit === "msat" ? receiveResult.amount : receiveResult.amount * 1e3;
|
|
682
|
+
if (receiveResult.success) {
|
|
683
|
+
this.storageAdapter.removeApiKey(baseUrl);
|
|
684
|
+
}
|
|
682
685
|
return {
|
|
683
686
|
success: receiveResult.success,
|
|
684
687
|
refundedAmount: totalAmountMsat,
|
|
@@ -1759,7 +1762,7 @@ var ProviderManager = class {
|
|
|
1759
1762
|
};
|
|
1760
1763
|
|
|
1761
1764
|
// client/RoutstrClient.ts
|
|
1762
|
-
var TOPUP_MARGIN =
|
|
1765
|
+
var TOPUP_MARGIN = 1.2;
|
|
1763
1766
|
var RoutstrClient = class {
|
|
1764
1767
|
constructor(walletAdapter, storageAdapter, providerRegistry, alertLevel, mode = "xcashu") {
|
|
1765
1768
|
this.walletAdapter = walletAdapter;
|
|
@@ -2046,12 +2049,14 @@ var RoutstrClient = class {
|
|
|
2046
2049
|
try {
|
|
2047
2050
|
const url = `${baseUrl.replace(/\/$/, "")}${path}`;
|
|
2048
2051
|
if (this.mode === "xcashu") this._log("DEBUG", "HEADERS,", headers);
|
|
2052
|
+
this._log("DEBUG", "HEADERS,", headers);
|
|
2049
2053
|
const response = await fetch(url, {
|
|
2050
2054
|
method,
|
|
2051
2055
|
headers,
|
|
2052
2056
|
body: body === void 0 || method === "GET" ? void 0 : JSON.stringify(body)
|
|
2053
2057
|
});
|
|
2054
2058
|
if (this.mode === "xcashu") this._log("DEBUG", "response,", response);
|
|
2059
|
+
this._log("DEBUG", "response,", response);
|
|
2055
2060
|
response.baseUrl = baseUrl;
|
|
2056
2061
|
response.token = token;
|
|
2057
2062
|
if (!response.ok) {
|
|
@@ -2158,6 +2163,7 @@ var RoutstrClient = class {
|
|
|
2158
2163
|
}
|
|
2159
2164
|
}
|
|
2160
2165
|
if ((status === 402 || status === 413 && responseBody?.includes("Insufficient balance")) && !tryNextProvider && (this.mode === "apikeys" || this.mode === "lazyrefund")) {
|
|
2166
|
+
console.log("RESPONSFE ", responseBody);
|
|
2161
2167
|
const topupResult = await this.balanceManager.topUp({
|
|
2162
2168
|
mintUrl,
|
|
2163
2169
|
baseUrl,
|
|
@@ -2260,8 +2266,6 @@ var RoutstrClient = class {
|
|
|
2260
2266
|
status,
|
|
2261
2267
|
refundResult.message ?? "Unknown error"
|
|
2262
2268
|
);
|
|
2263
|
-
} else {
|
|
2264
|
-
this.storageAdapter.removeApiKey(baseUrl);
|
|
2265
2269
|
}
|
|
2266
2270
|
}
|
|
2267
2271
|
}
|
|
@@ -2360,7 +2364,11 @@ var RoutstrClient = class {
|
|
|
2360
2364
|
baseUrl
|
|
2361
2365
|
);
|
|
2362
2366
|
const latestTokenBalance = latestBalanceInfo.unit === "msat" ? latestBalanceInfo.amount / 1e3 : latestBalanceInfo.amount;
|
|
2363
|
-
this.storageAdapter.
|
|
2367
|
+
const storedApiKeyEntry = this.storageAdapter.getApiKey(baseUrl);
|
|
2368
|
+
if (storedApiKeyEntry?.key.startsWith("cashu") && latestBalanceInfo.apiKey) {
|
|
2369
|
+
this.storageAdapter.removeApiKey(baseUrl);
|
|
2370
|
+
this.storageAdapter.setApiKey(baseUrl, latestBalanceInfo.apiKey);
|
|
2371
|
+
}
|
|
2364
2372
|
this.storageAdapter.updateApiKeyBalance(baseUrl, latestTokenBalance);
|
|
2365
2373
|
satsSpent = initialTokenBalance - latestTokenBalance;
|
|
2366
2374
|
} catch (e) {
|