Skip to content

Commit

Permalink
feat: add creationDate for all connectors
Browse files Browse the repository at this point in the history
  • Loading branch information
pavanjoshi914 committed Jan 9, 2025
1 parent d9ddb2d commit a8478b8
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 12 deletions.
3 changes: 1 addition & 2 deletions src/app/hooks/useTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ export const useTransactions = () => {
date: dayjs(
transaction.settleDate || transaction.creationDate
).fromNow(),
timestamp:
transaction.settleDate || transaction.creationDate || Date.now(),
timestamp: transaction.settleDate || transaction.creationDate,
})
);

Expand Down
1 change: 1 addition & 0 deletions src/extension/background-script/connectors/alby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export default class Alby implements Connector {
payment_hash: invoice.payment_hash,
settled: invoice.settled,
settleDate: new Date(invoice.settled_at).getTime(),
creationDate: new Date(invoice.created_at).getTime(),
totalAmount: invoice.amount,
type: invoice.type == "incoming" ? "received" : "sent",
})
Expand Down
37 changes: 29 additions & 8 deletions src/extension/background-script/connectors/commando.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import LnMessage from "lnmessage";
import { v4 as uuidv4 } from "uuid";
import { Account } from "~/types";

import lightningPayReq from "bolt11-signet";
import { mergeTransactions } from "~/common/utils/helpers";
import Connector, {
CheckPaymentArgs,
Expand Down Expand Up @@ -238,18 +239,28 @@ export default class Commando implements Connector {
.then((resp) => {
const parsed = resp as CommandoListInvoicesResponse;
return parsed.invoices
.map(
(invoice, index): ConnectorTransaction => ({
.map((invoice, index): ConnectorTransaction => {
const decoded = invoice.bolt11
? lightningPayReq.decode(invoice.bolt11)
: null;

const creationDate =
decoded && decoded.timestamp
? decoded.timestamp * 1000
: new Date(0).getTime();

return {
id: invoice.label,
memo: invoice.description,
settled: invoice.status === "paid",
creationDate: creationDate,
preimage: invoice.payment_preimage,
payment_hash: invoice.payment_hash,
settleDate: invoice.paid_at * 1000,
type: "received",
totalAmount: Math.floor(invoice.amount_received_msat / 1000),
})
)
};
})
.filter((invoice) => invoice.settled);
});
}
Expand Down Expand Up @@ -280,18 +291,28 @@ export default class Commando implements Connector {
.then((resp) => {
const parsed = resp as CommandoListSendPaysResponse;
return parsed.payments
.map(
(payment, index): ConnectorTransaction => ({
.map((payment, index): ConnectorTransaction => {
const decoded = payment.bolt11
? lightningPayReq.decode(payment.bolt11)
: null;

const creationDate =
decoded && decoded.timestamp
? decoded.timestamp * 1000
: new Date(0).getTime();

return {
id: `${payment.id}`,
memo: payment.description ?? "",
settled: payment.status === "complete",
preimage: payment.payment_preimage,
creationDate: creationDate,
payment_hash: payment.payment_hash,
settleDate: payment.created_at * 1000,
type: "sent",
totalAmount: payment.amount_sent_msat / 1000,
})
)
};
})
.filter((payment) => payment.settled);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface ConnectorTransaction {
* Settle date in UNIX milliseconds
*/
settleDate: number | null;
creationDate?: number;
creationDate: number;
totalAmount: number;
displayAmount?: [number, ACCOUNT_CURRENCIES];
type: "received" | "sent";
Expand Down
1 change: 1 addition & 0 deletions src/extension/background-script/connectors/galoy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ class Galoy implements Connector {
payment_hash: tx.initiationVia.paymentHash || "",
settled: tx.status === "SUCCESS",
settleDate: createdAtDate.getTime(),
creationDate: createdAtDate.getTime(),
totalAmount: absSettlementAmount,
type: transactionType,
displayAmount,
Expand Down
1 change: 1 addition & 0 deletions src/extension/background-script/connectors/lawallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ export async function parseTransaction(
preimage: await extractPreimage(event, privateKey),
settled: true,
settleDate: event.created_at * 1000,
creationDate: event.created_at * 1000,
totalAmount: content.tokens.BTC / 1000,
type: event.tags[1][1] === userPubkey ? "received" : "sent",
custom_records: {},
Expand Down
7 changes: 7 additions & 0 deletions src/extension/background-script/connectors/lnbits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ class LnBits implements Connector {
) => {
const transactions: ConnectorTransaction[] = data
.map((transaction, index): ConnectorTransaction => {
const decoded = lightningPayReq.decode(transaction.bolt11);

const creationDate = decoded.timestamp
? decoded.timestamp * 1000
: new Date(0).getTime();

return {
id: `${transaction.checking_id}-${index}`,
memo: transaction.memo,
Expand All @@ -135,6 +141,7 @@ class LnBits implements Connector {
payment_hash: transaction.payment_hash,
settled: !transaction.pending,
settleDate: transaction.time * 1000,
creationDate: creationDate,
totalAmount: Math.abs(Math.floor(transaction.amount / 1000)),
type: transaction.amount > 0 ? "received" : "sent",
};
Expand Down
2 changes: 2 additions & 0 deletions src/extension/background-script/connectors/lnc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ class Lnc implements Connector {
preimage: invoice.rPreimage.toString(),
settled: invoice.state === "SETTLED",
settleDate: parseInt(invoice.settleDate) * 1000,
creationDate: parseInt(invoice.creationDate) * 1000,
totalAmount: parseInt(invoice.value),
type: "received",
};
Expand Down Expand Up @@ -313,6 +314,7 @@ class Lnc implements Connector {
payment_hash: payment.paymentHash,
settled: true,
settleDate: parseInt(payment.creationTimeNs) / 1_000_000,
creationDate: parseInt(payment.creationTimeNs) / 1_000_000,
totalAmount: parseInt(payment.valueSat),
type: "sent",
};
Expand Down
2 changes: 2 additions & 0 deletions src/extension/background-script/connectors/lnd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ class Lnd implements Connector {
payment_hash: utils.base64ToHex(invoice.r_hash),
settled: invoice.settled,
settleDate: parseInt(invoice.settle_date) * 1000,
creationDate: parseInt(invoice.creation_date) * 1000,
totalAmount: parseInt(invoice.value),
type: "received",
custom_records,
Expand Down Expand Up @@ -533,6 +534,7 @@ class Lnd implements Connector {
payment_hash: payment.payment_hash,
settled: true,
settleDate: parseInt(payment.creation_date) * 1000,
creationDate: parseInt(payment.creation_date) * 1000,
totalAmount: payment.value_sat,
type: "sent",
};
Expand Down
2 changes: 2 additions & 0 deletions src/extension/background-script/connectors/lndhub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export default class LndHub implements Connector {
payment_hash: invoice.payment_hash,
settled: invoice.ispaid,
settleDate: invoice.timestamp * 1000,
creationDate: invoice.timestamp * 1000,
totalAmount: invoice.amt,
type: "received",
})
Expand Down Expand Up @@ -176,6 +177,7 @@ export default class LndHub implements Connector {
),
settled: true,
settleDate: transaction.timestamp * 1000,
creationDate: transaction.timestamp * 1000,
totalAmount: transaction.value,
type: "sent",
})
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ export interface Invoice {
type: "received" | "sent";
settled: boolean;
settleDate: number | null;
creationDate?: number;
creationDate: number;
totalAmount: number;
totalAmountFiat?: string;
displayAmount?: [number, ACCOUNT_CURRENCIES];
Expand Down

0 comments on commit a8478b8

Please sign in to comment.