date-fns#compareAsc JavaScript Examples
The following examples show how to use
date-fns#compareAsc.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: monitor.js From lnft with GNU Affero General Public License v3.0 | 6 votes |
isSpent = async ({ ins }, artwork_id) => {
try {
let { transactions } = await q(getLastTransaction, { artwork_id });
if (
!transactions.length ||
compareAsc(
parseISO(transactions[0].created_at),
subMinutes(new Date(), 2)
) > 0
)
return false;
for (let i = 0; i < ins.length; i++) {
let { index, hash } = ins[i];
let txid = reverse(hash).toString("hex");
let { spent } = await electrs
.url(`/tx/${txid}/outspend/${index}`)
.get()
.json();
if (spent) return true;
}
return false;
} catch (e) {
console.log("problem checking spent status", e);
return false;
}
}
Example #2
Source File: utils.js From lnft with GNU Affero General Public License v3.0 | 6 votes |
isCurrent = ({ transferred_at: t }, created_at, type) =>
type === "bid" && (!t || compareAsc(parseISO(created_at), parseISO(t)) > 0)
Example #3
Source File: index.js From monsuivipsy with Apache License 2.0 | 5 votes |
canEdit = (d) => {
const limitDate = beforeToday(7);
const canEditBool = compareAsc(parseISO(d), limitDate) === 1;
return canEditBool;
}
Example #4
Source File: artworks.js From lnft with GNU Affero General Public License v3.0 | 5 votes |
app.post("/transaction", auth, async (req, res) => {
try {
const { transaction } = req.body;
let { artworks } = await q(getTransactionArtwork, {
id: transaction.artwork_id,
});
let {
id: artwork_id,
bid_increment,
auction_end,
auction_start,
owner,
title,
bid,
slug,
} = artworks[0];
if (
bid &&
transaction.type === "bid" &&
transaction.amount < bid.amount + bid_increment &&
auction_end &&
compareAsc(parseISO(auction_end), new Date()) > 0
) {
throw new Error(
`Minimum bid is ${((bid.amount + bid_increment) / 100000000).toFixed(
8
)}`
);
}
if (transaction.type === "purchase") {
let { id: owner_id } = await getUser(req);
await q(setOwner, { id: artwork_id, owner_id });
}
let locals = {
outbid: false,
title,
url: `${SERVER_URL}/a/${slug}`,
};
try {
await mail.send({
template: "notify-bid",
locals,
message: {
to: owner.display_name,
},
});
if (bid && bid.user) {
locals.outbid = true;
await mail.send({
template: "notify-bid",
locals,
message: {
to: bid.user.display_name,
},
});
}
} catch (err) {
console.error("Unable to send email");
console.error(err);
}
let result = await api(req.headers)
.post({ query: createTransaction, variables: { transaction } })
.json();
if (result.errors) throw new Error(result.errors[0].message);
res.send(result.data.insert_transactions_one);
} catch (e) {
console.log("problem creating transaction", e);
res.code(500).send(e.message);
}
});
Example #5
Source File: wallet.js From lnft with GNU Affero General Public License v3.0 | 5 votes |
isMultisig = ({ has_royalty, auction_end }) => {
return !!(
(auction_end && compareAsc(parseISO(auction_end), new Date()) > 0) ||
has_royalty
);
}
Example #6
Source File: index.js From discovery-mobile-ui with MIT License | 5 votes |
sortByDate = ({ timelineDate: t1 }, { timelineDate: t2 }) => compareAsc(t1, t2)
Example #7
Source File: auctions.js From lnft with GNU Affero General Public License v3.0 | 4 votes |
setInterval(async () => {
try {
let { artworks } = await q(getFinishedAuctions, {
now: formatISO(new Date()),
});
for (let i = 0; i < artworks.length; i++) {
let artwork = artworks[i];
let { bid } = artwork;
await q(closeAuction, {
id: artwork.id,
artwork: {
auction_start: null,
auction_end: null,
},
});
console.log("finalizing auction for", artwork.slug);
console.log("reserve price", artwork.reserve_price);
try {
if (
!(bid && bid.psbt) ||
compareAsc(parseISO(bid.created_at), parseISO(artwork.auction_end)) >
0 ||
bid.amount < artwork.reserve_price
)
throw new Error("no bid");
let combined = combine(artwork.auction_tx, bid.psbt);
await check(combined);
let psbt = await sign(combined);
await broadcast(psbt);
await q(releaseToken, {
id: artwork.id,
owner_id: bid.user.id,
amount: bid.amount,
hash: psbt.extractTransaction().getId(),
psbt: psbt.toBase64(),
asset: artwork.asking_asset,
bid_id: bid.id,
type: "release",
});
console.log("released to high bidder");
} catch (e) {
console.log("couldn't release to bidder,", e.message);
await q(cancelBids, {
id: artwork.id,
start: artwork.auction_start,
end: artwork.auction_end,
});
if (artwork.has_royalty) continue;
try {
let psbt = await sign(artwork.auction_release_tx);
await broadcast(psbt);
console.log("released to current owner");
await q(releaseToken, {
id: artwork.id,
owner_id: artwork.owner.id,
amount: 0,
hash: psbt.extractTransaction().getId(),
psbt: psbt.toBase64(),
asset: artwork.asking_asset,
type: "return",
});
} catch (e) {
console.log("problem releasing", e);
}
}
}
} catch (e) {
console.log(e);
}
}, 2000);