Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MAX_PAGINATION_PAGE_SIZE, memoSharingConfig } from "@/config"
import { MAX_PAGINATION_PAGE_SIZE } from "@/config"
import { LedgerError } from "@/domain/ledger"
import { checkedToPaginatedQueryArgs } from "@/domain/primitives"
import { WalletTransactionHistory } from "@/domain/wallets"
Expand Down Expand Up @@ -40,7 +40,6 @@ export const getAccountTransactionsForContact = async ({
const transaction = WalletTransactionHistory.fromLedger({
txn: edge.node,
nonEndUserWalletIds,
memoSharingConfig,
})

return {
Expand Down
2 changes: 1 addition & 1 deletion core/api/src/app/payments/send-lightning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ const lockedPaymentViaIntraledgerSteps = async ({
}

const journal = await LedgerFacade.recordIntraledger({
description: paymentFlow.descriptionFromInvoice,
description: walletInvoice.description || paymentFlow.descriptionFromInvoice,
amount: {
btc: paymentFlow.btcPaymentAmount,
usd: paymentFlow.usdPaymentAmount,
Expand Down
3 changes: 0 additions & 3 deletions core/api/src/app/wallets/get-transaction-by-id.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { memoSharingConfig } from "@/config"
import { WalletTransactionHistory } from "@/domain/wallets"
import { checkedToLedgerTransactionId } from "@/domain/ledger"

Expand All @@ -25,7 +24,6 @@ export const getTransactionForWalletById = async ({
return WalletTransactionHistory.fromLedger({
txn: ledgerTransaction,
nonEndUserWalletIds: Object.values(await getNonEndUserWalletIds()),
memoSharingConfig,
})
}

Expand All @@ -43,6 +41,5 @@ export const getTransactionById = async (
return WalletTransactionHistory.fromLedger({
txn: ledgerTransaction,
nonEndUserWalletIds: Object.values(await getNonEndUserWalletIds()),
memoSharingConfig,
})
}
2 changes: 0 additions & 2 deletions core/api/src/app/wallets/get-transaction-by-journal-id.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { memoSharingConfig } from "@/config"
import { WalletTransactionHistory } from "@/domain/wallets"
import { getNonEndUserWalletIds, LedgerService } from "@/services/ledger"

Expand All @@ -20,6 +19,5 @@ export const getTransactionForWalletByJournalId = async ({
return WalletTransactionHistory.fromLedger({
txn: ledgerTransaction,
nonEndUserWalletIds: Object.values(await getNonEndUserWalletIds()),
memoSharingConfig,
})
}
3 changes: 1 addition & 2 deletions core/api/src/app/wallets/get-transactions-by-addresses.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MAX_PAGINATION_PAGE_SIZE, memoSharingConfig } from "@/config"
import { MAX_PAGINATION_PAGE_SIZE } from "@/config"

import { LedgerError } from "@/domain/ledger"
import { WalletTransactionHistory } from "@/domain/wallets"
Expand Down Expand Up @@ -42,7 +42,6 @@ export const getTransactionsForWalletsByAddresses = async ({
const transaction = WalletTransactionHistory.fromLedger({
txn: edge.node,
nonEndUserWalletIds,
memoSharingConfig,
})

return {
Expand Down
3 changes: 0 additions & 3 deletions core/api/src/app/wallets/get-transactions-by-hash.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { memoSharingConfig } from "@/config"
import { WalletTransactionHistory } from "@/domain/wallets"

import { getNonEndUserWalletIds, LedgerService } from "@/services/ledger"
Expand All @@ -24,7 +23,6 @@ export const getTransactionsForWalletByPaymentHash = async ({
WalletTransactionHistory.fromLedger({
txn,
nonEndUserWalletIds,
memoSharingConfig,
}),
)
}
Expand All @@ -41,7 +39,6 @@ export const getTransactionsByHash = async (
WalletTransactionHistory.fromLedger({
txn,
nonEndUserWalletIds,
memoSharingConfig,
}),
)
}
3 changes: 1 addition & 2 deletions core/api/src/app/wallets/get-transactions-for-wallet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MAX_PAGINATION_PAGE_SIZE, memoSharingConfig } from "@/config"
import { MAX_PAGINATION_PAGE_SIZE } from "@/config"

import { LedgerError } from "@/domain/ledger"
import { WalletTransactionHistory } from "@/domain/wallets"
Expand Down Expand Up @@ -35,7 +35,6 @@ export const getTransactionsForWallets = async ({
const transaction = WalletTransactionHistory.fromLedger({
txn: edge.node,
nonEndUserWalletIds,
memoSharingConfig,
})

return {
Expand Down
1 change: 1 addition & 0 deletions core/api/src/domain/wallet-invoices/index.types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ type WalletInvoiceWithOptionalLnInvoice = {
createdAt: Date
processingCompleted: boolean
externalId: LedgerExternalId
description?: string
lnInvoice?: LnInvoice // LnInvoice is optional because some older invoices don't have it
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export const WIBWithAmount = (state: WIBWithAmountState): WIBWithAmount => {
lnInvoice: registeredInvoice.invoice,
processingCompleted: false,
externalId,
description: state.description,
}
return walletInvoice
}
Expand Down
38 changes: 1 addition & 37 deletions core/api/src/domain/wallets/tx-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@ import { AdminLedgerTransactionType, LedgerTransactionType } from "@/domain/ledg
const translateLedgerTxnToWalletTxn = <S extends WalletCurrency>({
txn,
nonEndUserWalletIds,
memoSharingConfig,
}: {
txn: LedgerTransaction<S>
nonEndUserWalletIds: WalletId[]
memoSharingConfig: MemoSharingConfig
}): WalletTransaction => {
const {
type,
credit,
currency,
satsAmount: satsAmountRaw,
satsFee: satsFeeRaw,
Expand Down Expand Up @@ -65,12 +62,9 @@ const translateLedgerTxnToWalletTxn = <S extends WalletCurrency>({
const memo = translateMemo({
memoFromPayer,
lnMemo,
credit,
currency,
walletId,
nonEndUserWalletIds,
journalId,
memoSharingConfig,
})

const baseTransaction: BaseWalletTransaction = {
Expand Down Expand Up @@ -205,26 +199,6 @@ const translateLedgerTxnToWalletTxn = <S extends WalletCurrency>({
return walletTransaction
}

const shouldDisplayMemo = ({
memo,
credit,
currency,
memoSharingConfig,
}: {
memo: string | undefined
credit: CurrencyBaseAmount
currency: WalletCurrency
memoSharingConfig: MemoSharingConfig
}) => {
if ((!!memo && memoSharingConfig.authorizedMemos.includes(memo)) || credit === 0)
return true

if (currency === WalletCurrency.Btc)
return credit >= memoSharingConfig.memoSharingSatsThreshold

return credit >= memoSharingConfig.memoSharingCentsThreshold
}

const statusFromTxn = (txn: LedgerTransaction<WalletCurrency>): TxStatus => {
switch (txn.lnPaymentState) {
case undefined:
Expand All @@ -251,32 +225,22 @@ const statusFromTxn = (txn: LedgerTransaction<WalletCurrency>): TxStatus => {
export const translateMemo = ({
memoFromPayer,
lnMemo,
credit,
currency,
walletId,
nonEndUserWalletIds,
journalId,
memoSharingConfig,
}: {
memoFromPayer?: string
lnMemo?: string
credit: CurrencyBaseAmount
currency: WalletCurrency
walletId: WalletId | undefined
nonEndUserWalletIds: WalletId[]
journalId: LedgerJournalId
memoSharingConfig: MemoSharingConfig
}): string | null => {
if (walletId && nonEndUserWalletIds.includes(walletId)) {
return `JournalId:${journalId}`
}

const memo = memoFromPayer || lnMemo
if (shouldDisplayMemo({ memo, credit, currency, memoSharingConfig })) {
return memo || null
}

return null
return memo || null
}

export const WalletTransactionHistory = {
Expand Down
4 changes: 4 additions & 0 deletions core/api/src/services/mongoose/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ const walletInvoiceSchema = new Schema<WalletInvoiceRecord>({
type: String,
},

description: {
type: String,
},

externalId: {
required: true,
type: String,
Expand Down
1 change: 1 addition & 0 deletions core/api/src/services/mongoose/schema.types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ interface WalletInvoiceRecord {
pubkey: string
paid: boolean
paymentRequest?: string // optional because we historically did not store it
description?: string // optional because we historically did not store it
externalId: string
}

Expand Down
3 changes: 3 additions & 0 deletions core/api/src/services/mongoose/wallet-invoices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export const WalletInvoicesRepository = (): IWalletInvoicesRepository => {
paid,
usdAmount,
externalId,
description,
lnInvoice,
}: WalletInvoicesPersistNewArgs): Promise<WalletInvoice | RepositoryError> => {
try {
Expand All @@ -152,6 +153,7 @@ export const WalletInvoicesRepository = (): IWalletInvoicesRepository => {
cents: usdAmount ? Number(usdAmount.amount) : undefined,
currency: recipientWalletDescriptor.currency,
paymentRequest: lnInvoice.paymentRequest,
...(description !== undefined ? { description } : {}),
externalId,
}).save()
return ensureWalletInvoiceHasLnInvoice(walletInvoiceFromRaw(walletInvoice))
Expand Down Expand Up @@ -307,6 +309,7 @@ const walletInvoiceFromRaw = (
createdAt: new Date(result.timestamp.getTime()),
processingCompleted: result.processingCompleted,
externalId: result.externalId as LedgerExternalId,
...(result.description !== undefined ? { description: result.description } : {}),
lnInvoice,
}
}
Expand Down
1 change: 1 addition & 0 deletions core/api/test/helpers/wallet-invoices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ export const createMockWalletInvoice = (
createdAt: new Date(),
processingCompleted: false,
externalId,
description: "mock invoice description",
}
}
4 changes: 4 additions & 0 deletions core/api/test/integration/app/wallets/send-lightning.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,7 @@ describe("initiated via lightning", () => {

const externalId = randomLedgerExternalId()
if (externalId instanceof Error) throw externalId
const invoiceDescription = `lnurl comment ${randomUUID()}`

// Persist invoice as self-invoice
const persisted = await WalletInvoicesRepository().persistNew({
Expand All @@ -1104,6 +1105,7 @@ describe("initiated via lightning", () => {
lnInvoice,
processingCompleted: false,
externalId,
description: invoiceDescription,
})
if (persisted instanceof Error) throw persisted

Expand Down Expand Up @@ -1131,6 +1133,8 @@ describe("initiated via lightning", () => {
expect(lnIntraledgerLedgerMetadataSpy).toHaveBeenCalledTimes(1)
const args = recordIntraledgerSpy.mock.calls[0][0]
expect(args.metadata.type).toBe(LedgerTransactionType.LnIntraLedger)
expect(args.description).toBe(invoiceDescription)
expect(args.description).not.toBe(memo)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ describe("WalletInvoiceBuilder", () => {
const WIBWithDescription = WIBWithExternalId.withDescription({
description: testDescription,
})
const checkDescription = ({ lnInvoice }: WalletInvoice) => {
const checkDescription = ({ description, lnInvoice }: WalletInvoice) => {
expect(description).toEqual(testDescription)
expect(lnInvoice.description).toEqual(testDescription)
}
const WIBWithDescriptionAndNoExternalId = WIBWithNoExternalId.withDescription({
Expand Down
Loading
Loading