Skip to content

Commit

Permalink
add ampinvoice db and fixed suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
nitesh committed May 8, 2024
1 parent cd7a577 commit 74f871d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/state/Send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export const send: ISendModel = {
multiPathPaymentsEnabled,
maxLNFeePercentage,
outgoingChannelId,
payload && payload.isAmpInvoice ? true : false,
(payload && payload.isAmpInvoice) ?? false,
);
} catch (error) {
await dispatch.transaction.syncTransaction({
Expand Down
18 changes: 10 additions & 8 deletions src/state/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,18 @@ export const transaction: ITransactionModel = {
}

// Don't insert open transactions for AMP invoices
if (tx.status === "OPEN" && tx.ampInvoice) {
return;
}
if (tx.ampInvoice) {
if (tx.status === "OPEN") {
return;
}

// If AMP invoice settles, insert a new tx
if (tx.status === "SETTLED" && tx.ampInvoice) {
const id = await createTransaction(db, tx);
actions.addTransaction({ ...tx, id });
// If AMP invoice settles, insert a new tx
if (tx.status === "SETTLED") {
const id = await createTransaction(db, tx);
actions.addTransaction({ ...tx, id });

return;
return;
}
}

const transactions = getState().transactions;
Expand Down
4 changes: 4 additions & 0 deletions src/storage/database/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface IDBTransaction {
status: "ACCEPTED" | "CANCELED" | "OPEN" | "SETTLED" | "UNKNOWN" | "EXPIRED";
paymentRequest: string;
rHash: string;
ampInvoice: boolean;
nodeAliasCached: string | null;
payer: string | null;
valueUSD: number | null;
Expand Down Expand Up @@ -173,6 +174,7 @@ export const createTransaction = async (
?,
?,
?,
?,
?
)`,
[
Expand All @@ -190,6 +192,7 @@ export const createTransaction = async (
transaction.status,
transaction.paymentRequest,
transaction.rHash,
transaction.ampInvoice.toString(),
transaction.nodeAliasCached ?? null,
transaction.payer ?? null,
transaction.valueUSD,
Expand Down Expand Up @@ -390,6 +393,7 @@ const convertDBTransaction = (transaction: IDBTransaction): ITransaction => {
paymentRequest: transaction.paymentRequest,
status: transaction.status,
rHash: transaction.rHash,
ampInvoice: transaction.ampInvoice,
nodeAliasCached: transaction.nodeAliasCached,
payer: transaction.payer,
valueUSD: transaction.valueUSD,
Expand Down

0 comments on commit 74f871d

Please sign in to comment.