diff --git a/src/common/lib/api.ts b/src/common/lib/api.ts index d37ff43c68..2bd9bd300c 100644 --- a/src/common/lib/api.ts +++ b/src/common/lib/api.ts @@ -25,7 +25,6 @@ import type { LnurlAuthResponse, MessageAccountEdit, MessageAccountValidate, - MessageInvoices, MessageLnurlAuth, MessageSettingsSet, MessageTransactions, @@ -171,8 +170,6 @@ export const unlock = (password: string) => msg.request("unlock", { password }); export const getBlocklist = (host: string) => msg.request("getBlocklist", { host }); -export const getInvoices = (options?: MessageInvoices["args"]) => - msg.request<{ invoices: Invoice[] }>("getInvoices", options); export const getTransactions = (options?: MessageTransactions["args"]) => msg.request<{ transactions: Invoice[] }>("getTransactions", options); export const lnurlAuth = ( @@ -298,7 +295,6 @@ export default { removeAccount, unlock, getBlocklist, - getInvoices, getTransactions, lnurlAuth, getCurrencyRate, diff --git a/src/common/lib/utils.ts b/src/common/lib/utils.ts index 53ef50922f..38ae048347 100644 --- a/src/common/lib/utils.ts +++ b/src/common/lib/utils.ts @@ -1,12 +1,8 @@ import browser, { Runtime } from "webextension-polyfill"; import { ABORT_PROMPT_ERROR } from "~/common/constants"; import { getPosition as getWindowPosition } from "~/common/utils/window"; -import type { - DeferredPromise, - Invoice, - OriginData, - OriginDataInternal, -} from "~/types"; +import { ConnectorTransaction } from "~/extension/background-script/connectors/connector.interface"; +import type { DeferredPromise, OriginData, OriginDataInternal } from "~/types"; const utils = { base64ToHex: (str: string) => { @@ -173,7 +169,7 @@ const utils = { }); }, getBoostagramFromInvoiceCustomRecords: ( - custom_records: Invoice["custom_records"] | undefined + custom_records: ConnectorTransaction["custom_records"] | undefined ) => { try { let boostagramDecoded: string | undefined; diff --git a/src/extension/background-script/actions/ln/index.ts b/src/extension/background-script/actions/ln/index.ts index 60dd1d157e..072d835eb0 100644 --- a/src/extension/background-script/actions/ln/index.ts +++ b/src/extension/background-script/actions/ln/index.ts @@ -1,7 +1,7 @@ import checkPayment from "./checkPayment"; import connectPeer from "./connectPeer"; import getInfo from "./getInfo"; -import invoices from "./invoices"; + import keysend from "./keysend"; import makeInvoice from "./makeInvoice"; import request from "./request"; @@ -14,7 +14,6 @@ export { checkPayment, connectPeer, getInfo, - invoices, keysend, makeInvoice, request, diff --git a/src/extension/background-script/actions/ln/invoices.ts b/src/extension/background-script/actions/ln/invoices.ts deleted file mode 100644 index 9f52557a28..0000000000 --- a/src/extension/background-script/actions/ln/invoices.ts +++ /dev/null @@ -1,38 +0,0 @@ -import utils from "~/common/lib/utils"; -import state from "~/extension/background-script/state"; -import type { Invoice, MessageInvoices } from "~/types"; - -const invoices = async (message: MessageInvoices) => { - const isSettled = message.args.isSettled; - const limit = message.args.limit; - - const connector = await state.getState().getConnector(); - try { - const result = await connector.getInvoices(); - let invoices: Invoice[] = result.data.invoices - .filter((invoice) => (isSettled ? invoice.settled : !invoice.settled)) - .map((invoice) => { - const boostagram = utils.getBoostagramFromInvoiceCustomRecords( - invoice.custom_records - ); - return { ...invoice, boostagram }; - }); - - if (limit) { - invoices = invoices.slice(0, limit); - } - - return { - data: { - invoices, - }, - }; - } catch (e) { - console.error(e); - if (e instanceof Error) { - return { error: e.message }; - } - } -}; - -export default invoices; diff --git a/src/extension/background-script/actions/ln/transactions.ts b/src/extension/background-script/actions/ln/transactions.ts index 33dc9fc7cd..e54af91680 100644 --- a/src/extension/background-script/actions/ln/transactions.ts +++ b/src/extension/background-script/actions/ln/transactions.ts @@ -1,6 +1,7 @@ import utils from "~/common/lib/utils"; +import { ConnectorTransaction } from "~/extension/background-script/connectors/connector.interface"; import state from "~/extension/background-script/state"; -import type { Invoice, MessageTransactions } from "~/types"; +import type { MessageTransactions } from "~/types"; const transactions = async (message: MessageTransactions) => { const isSettled = message.args.isSettled; @@ -10,7 +11,7 @@ const transactions = async (message: MessageTransactions) => { try { const result = await connector.getTransactions(); - let transactions: Invoice[] = result.data.transactions + let transactions: ConnectorTransaction[] = result.data.transactions .filter((transaction) => isSettled ? transaction.settled : !transaction.settled ) diff --git a/src/extension/background-script/connectors/connector.interface.ts b/src/extension/background-script/connectors/connector.interface.ts index 1b96f70630..75a256431b 100644 --- a/src/extension/background-script/connectors/connector.interface.ts +++ b/src/extension/background-script/connectors/connector.interface.ts @@ -137,7 +137,6 @@ export default interface Connector { unload(): Promise; getInfo(): Promise; getBalance(): Promise; - getInvoices(): Promise; getTransactions(): Promise; makeInvoice(args: MakeInvoiceArgs): Promise; sendPayment(args: SendPaymentArgs): Promise; diff --git a/src/extension/background-script/connectors/lndhub.ts b/src/extension/background-script/connectors/lndhub.ts index 18521d4583..ddeec17d71 100644 --- a/src/extension/background-script/connectors/lndhub.ts +++ b/src/extension/background-script/connectors/lndhub.ts @@ -157,7 +157,10 @@ export default class LndHub implements Connector { fee: string; keysend: boolean; memo: string; - payment_hash: string; + payment_hash: { + type: string; + data: ArrayBuffer; + }; payment_preimage: string; r_hash: { type: "Buffer"; @@ -175,7 +178,9 @@ export default class LndHub implements Connector { id: `${index}`, memo: transaction.memo, preimage: transaction.payment_preimage, - payment_hash: transaction.payment_hash, + payment_hash: Buffer.from(transaction.payment_hash.data).toString( + "hex" + ), settled: true, settleDate: transaction.timestamp * 1000, totalAmount: transaction.value, diff --git a/src/extension/background-script/router.ts b/src/extension/background-script/router.ts index b64fa8522d..c9e5d177ab 100644 --- a/src/extension/background-script/router.ts +++ b/src/extension/background-script/router.ts @@ -30,7 +30,6 @@ const routes = { lock: accounts.lock, unlock: accounts.unlock, getInfo: ln.getInfo, - getInvoices: ln.invoices, getTransactions: ln.transactions, sendPayment: ln.sendPayment, sendPaymentAsync: ln.sendPaymentAsync, diff --git a/src/types.ts b/src/types.ts index 4972c9c9b8..db46e2b765 100644 --- a/src/types.ts +++ b/src/types.ts @@ -342,10 +342,6 @@ export interface MessageAllowanceList extends MessageDefault { action: "listAllowances"; } -export interface MessageInvoices extends Omit { - args: { limit?: number; isSettled?: boolean }; - action: "getInvoices"; -} export interface MessageTransactions extends Omit { args: { limit?: number; isSettled?: boolean }; action: "getTransactions";