UNPKG

@arkade-os/boltz-swap

Version:

A production-ready TypeScript package that brings Boltz submarine-swaps to Arkade.

26 lines (24 loc) 1.02 kB
// src/repositories/swap-repository.ts function hasImpossibleSwapsFilter(filter) { if (!filter) return false; return Array.isArray(filter.id) && filter.id.length === 0 || Array.isArray(filter.status) && filter.status.length === 0 || Array.isArray(filter.type) && filter.type.length === 0; } function matchesCriterion(value, criterion) { if (criterion === void 0) return true; return Array.isArray(criterion) ? criterion.includes(value) : value === criterion; } function applySwapsFilter(swaps, filter) { return swaps.filter( (swap) => !!swap && matchesCriterion(swap.id, filter.id) && matchesCriterion(swap.status, filter.status) && matchesCriterion(swap.type, filter.type) ); } function applyCreatedAtOrder(swaps, filter) { if (filter?.orderBy !== "createdAt") return swaps; const direction = filter.orderDirection === "asc" ? 1 : -1; return swaps.slice().sort((a, b) => (a.createdAt - b.createdAt) * direction); } export { hasImpossibleSwapsFilter, applySwapsFilter, applyCreatedAtOrder };