@routstr/sdk 0.3.4 → 0.3.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 +37 -5
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +37 -5
- package/dist/client/index.mjs.map +1 -1
- package/dist/index.js +38 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +38 -8
- package/dist/index.mjs.map +1 -1
- package/dist/storage/index.js +1 -3
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/index.mjs +1 -3
- package/dist/storage/index.mjs.map +1 -1
- package/dist/wallet/index.js +37 -5
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs +37 -5
- package/dist/wallet/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1219,19 +1219,50 @@ var CashuSpender = class {
|
|
|
1219
1219
|
apiKeyEntry.baseUrl
|
|
1220
1220
|
);
|
|
1221
1221
|
if (apiKeyEntryFull && this.balanceManager) {
|
|
1222
|
+
try {
|
|
1223
|
+
const balanceResult = await this.balanceManager.getTokenBalance(
|
|
1224
|
+
apiKeyEntryFull.key,
|
|
1225
|
+
apiKeyEntry.baseUrl
|
|
1226
|
+
);
|
|
1227
|
+
if (balanceResult.isInvalidApiKey) {
|
|
1228
|
+
this.storageAdapter.removeApiKey(apiKeyEntry.baseUrl);
|
|
1229
|
+
results.push({
|
|
1230
|
+
baseUrl: apiKeyEntry.baseUrl,
|
|
1231
|
+
success: true
|
|
1232
|
+
});
|
|
1233
|
+
continue;
|
|
1234
|
+
}
|
|
1235
|
+
if (balanceResult.amount >= 0) {
|
|
1236
|
+
const balanceSat = balanceResult.unit === "msat" ? Math.floor(balanceResult.amount / 1e3) : balanceResult.amount;
|
|
1237
|
+
this.storageAdapter.updateApiKeyBalance(
|
|
1238
|
+
apiKeyEntry.baseUrl,
|
|
1239
|
+
balanceSat
|
|
1240
|
+
);
|
|
1241
|
+
}
|
|
1242
|
+
} catch {
|
|
1243
|
+
}
|
|
1244
|
+
const refreshedEntry = this.storageAdapter.getApiKey(
|
|
1245
|
+
apiKeyEntry.baseUrl
|
|
1246
|
+
);
|
|
1247
|
+
if (!refreshedEntry) continue;
|
|
1222
1248
|
const refundResult = await this.balanceManager.refundApiKey({
|
|
1223
1249
|
mintUrl,
|
|
1224
1250
|
baseUrl: apiKeyEntry.baseUrl,
|
|
1225
|
-
apiKey:
|
|
1251
|
+
apiKey: refreshedEntry.key,
|
|
1226
1252
|
forceRefund
|
|
1227
1253
|
});
|
|
1228
1254
|
if (refundResult.success) {
|
|
1229
1255
|
this.storageAdapter.removeApiKey(apiKeyEntry.baseUrl);
|
|
1230
1256
|
} else {
|
|
1231
|
-
this.storageAdapter.
|
|
1232
|
-
apiKeyEntry.baseUrl
|
|
1233
|
-
apiKeyEntry.amount
|
|
1257
|
+
const currentEntry = this.storageAdapter.getApiKey(
|
|
1258
|
+
apiKeyEntry.baseUrl
|
|
1234
1259
|
);
|
|
1260
|
+
if (currentEntry) {
|
|
1261
|
+
this.storageAdapter.updateApiKeyBalance(
|
|
1262
|
+
apiKeyEntry.baseUrl,
|
|
1263
|
+
currentEntry.balance
|
|
1264
|
+
);
|
|
1265
|
+
}
|
|
1235
1266
|
}
|
|
1236
1267
|
results.push({
|
|
1237
1268
|
baseUrl: apiKeyEntry.baseUrl,
|
|
@@ -1440,7 +1471,8 @@ var BalanceManager = class _BalanceManager {
|
|
|
1440
1471
|
};
|
|
1441
1472
|
}
|
|
1442
1473
|
if (fetchResult.error === "No balance to refund") {
|
|
1443
|
-
|
|
1474
|
+
this.storageAdapter.removeApiKey(baseUrl);
|
|
1475
|
+
return { success: true, message: "No balance to refund, key cleaned up" };
|
|
1444
1476
|
}
|
|
1445
1477
|
const receiveResult = await this.cashuSpender.receiveToken(
|
|
1446
1478
|
fetchResult.token
|
|
@@ -4253,9 +4285,7 @@ var createStorageAdapterFromStore = (store) => ({
|
|
|
4253
4285
|
const distributionMap = {};
|
|
4254
4286
|
for (const entry of apiKeys) {
|
|
4255
4287
|
const sum = entry.balance || 0;
|
|
4256
|
-
|
|
4257
|
-
distributionMap[entry.baseUrl] = (distributionMap[entry.baseUrl] || 0) + sum;
|
|
4258
|
-
}
|
|
4288
|
+
distributionMap[entry.baseUrl] = (distributionMap[entry.baseUrl] || 0) + sum;
|
|
4259
4289
|
}
|
|
4260
4290
|
return Object.entries(distributionMap).map(([baseUrl, amt]) => ({ baseUrl, amount: amt })).sort((a, b) => b.amount - a.amount);
|
|
4261
4291
|
},
|