@nostr-dev-kit/ndk-mobile
Version:
NDK Mobile
41 lines (37 loc) • 1.55 kB
JavaScript
;
import { NDKNutzap, NdkNutzapStatus } from "@nostr-dev-kit/ndk";
// Define database row type for type checking - specific to this implementation
/**
* Gets all nutzap states from the monitor state table.
* This function is bound to the NDKCacheAdapterSqlite instance.
*/
export async function getAllNutzapStates() {
const result = new Map();
const nutzaps = await this.db.getAllAsync("SELECT * FROM nutzap_monitor_state");
for (const row of nutzaps) {
const state = {
status: row.status
};
// Only deserialize nutzap for states where we might need it
if (row.nutzap && ![NdkNutzapStatus.REDEEMED, NdkNutzapStatus.SPENT].includes(state.status)) {
try {
const rawEvent = JSON.parse(row.nutzap);
// We need the NDK instance to create the NDKNutzap object
// Assuming NDK instance is available via `this.ndk` - needs verification/adjustment
if (this.ndk) {
state.nutzap = new NDKNutzap(this.ndk, rawEvent);
} else {
console.warn("NDK instance not available on cache adapter, cannot deserialize Nutzap event");
}
} catch (e) {
console.error("Failed to parse nutzap", e);
}
}
if (row.redeemed_by_id) state.redeemedById = row.redeemed_by_id;
if (row.error_message) state.errorMessage = row.error_message;
if (row.redeemed_amount) state.redeemedAmount = Number.parseInt(row.redeemed_amount);
result.set(row.event_id, state);
}
return result;
}
//# sourceMappingURL=nutzap-state-get.js.map