From da28ee338b9a0e3d636d3ae3c9ac8b756dcf8ef9 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Tue, 17 Dec 2024 19:06:41 +0530 Subject: [PATCH 01/16] feat: show pending and failed transactions for nwc --- package.json | 2 +- .../TransactionsTable/TransactionModal.tsx | 30 ++++++++++++++++--- .../components/TransactionsTable/index.tsx | 29 +++++++++++++++--- src/app/hooks/useTransactions.ts | 1 - src/app/icons/FailedTransaction.tsx | 21 +++++++++++++ .../actions/ln/getTransactions.ts | 29 ++++++++++-------- .../connectors/connector.interface.ts | 2 ++ .../background-script/connectors/nwc.ts | 15 +++++++--- src/i18n/locales/en/translation.json | 2 ++ src/types.ts | 1 + 10 files changed, 105 insertions(+), 27 deletions(-) create mode 100644 src/app/icons/FailedTransaction.tsx diff --git a/package.json b/package.json index 2934fa5b66..4174f76398 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ }, "dependencies": { "@bitcoinerlab/secp256k1": "^1.1.1", - "@getalby/sdk": "^3.6.0", + "@getalby/sdk": "^3.8.2", "@headlessui/react": "^1.7.18", "@lightninglabs/lnc-web": "^0.3.1-alpha", "@noble/ciphers": "^0.5.1", diff --git a/src/app/components/TransactionsTable/TransactionModal.tsx b/src/app/components/TransactionsTable/TransactionModal.tsx index 3b2d9589ea..4e36fb74b4 100644 --- a/src/app/components/TransactionsTable/TransactionModal.tsx +++ b/src/app/components/TransactionsTable/TransactionModal.tsx @@ -10,6 +10,7 @@ import { useTranslation } from "react-i18next"; import Hyperlink from "~/app/components/Hyperlink"; import Modal from "~/app/components/Modal"; import { useSettings } from "~/app/context/SettingsContext"; +import CrossIcon from "~/app/icons/FailedTransaction"; import { classNames } from "~/app/utils"; import { Transaction } from "~/types"; @@ -56,17 +57,38 @@ export default function TransactionModal({
{getTransactionType(transaction) == "outgoing" ? ( -
- -
+ transaction.state === "pending" ? ( +
+ +
+ ) : transaction.state === "failed" ? ( +
+ +
+ ) : ( +
+ +
+ ) ) : (
)}
+

- {transaction.type == "received" ? t("received") : t("sent")} + {transaction.type == "received" + ? t("received") + : t( + transaction.state === "settled" + ? "sent" + : transaction.state === "pending" + ? "sending" + : transaction.state === "failed" + ? "failed" + : "sent" + )}

diff --git a/src/app/components/TransactionsTable/index.tsx b/src/app/components/TransactionsTable/index.tsx index 75f2bec035..a0ed9798bf 100644 --- a/src/app/components/TransactionsTable/index.tsx +++ b/src/app/components/TransactionsTable/index.tsx @@ -6,6 +6,7 @@ import { useTranslation } from "react-i18next"; import TransactionModal from "~/app/components/TransactionsTable/TransactionModal"; import { useSettings } from "~/app/context/SettingsContext"; +import CrossIcon from "~/app/icons/FailedTransaction"; import { classNames } from "~/app/utils"; import { Transaction } from "~/types"; @@ -60,9 +61,19 @@ export default function TransactionsTable({
{type == "outgoing" ? ( -
- -
+ tx.state === "pending" ? ( +
+ +
+ ) : tx.state === "failed" ? ( +
+ +
+ ) : ( +
+ +
+ ) ) : (
@@ -74,7 +85,17 @@ export default function TransactionsTable({

{tx.title || tx.boostagram?.message || - (type == "incoming" ? t("received") : t("sent"))} + (type == "incoming" + ? t("received") + : t( + tx.state === "settled" + ? "sent" + : tx.state === "pending" + ? "sending" + : tx.state === "failed" + ? "failed" + : "sent" + ))}

diff --git a/src/app/hooks/useTransactions.ts b/src/app/hooks/useTransactions.ts index f7b24d7377..68e74d1f4b 100644 --- a/src/app/hooks/useTransactions.ts +++ b/src/app/hooks/useTransactions.ts @@ -16,7 +16,6 @@ export const useTransactions = () => { const getTransactionsResponse = await api.getTransactions({ limit, }); - const transactions = getTransactionsResponse.transactions.map( (transaction) => ({ ...transaction, diff --git a/src/app/icons/FailedTransaction.tsx b/src/app/icons/FailedTransaction.tsx new file mode 100644 index 0000000000..65b5436aa9 --- /dev/null +++ b/src/app/icons/FailedTransaction.tsx @@ -0,0 +1,21 @@ +import { SVGProps } from "react"; + +const CrossIcon = (props: SVGProps) => ( + + + +); + +export default CrossIcon; diff --git a/src/extension/background-script/actions/ln/getTransactions.ts b/src/extension/background-script/actions/ln/getTransactions.ts index 341014be6f..cf3fd460d1 100644 --- a/src/extension/background-script/actions/ln/getTransactions.ts +++ b/src/extension/background-script/actions/ln/getTransactions.ts @@ -9,19 +9,22 @@ const getTransactions = async (message: MessageGetTransactions) => { const connector = await state.getState().getConnector(); try { const result = await connector.getTransactions(); - - let transactions: ConnectorTransaction[] = result.data.transactions - .filter((transaction) => transaction.settled) - .map((transaction) => { - const boostagram = utils.getBoostagramFromInvoiceCustomRecords( - transaction.custom_records - ); - return { - ...transaction, - boostagram, - paymentHash: transaction.payment_hash, - }; - }); + const isNWC = connector.connectorType == "nwc"; + // we show pending and failed transactions for nwc. pass on all transactions for nwc connector to frontend + let transactions: ConnectorTransaction[] = result.data.transactions; + if (!isNWC) { + transactions = transactions.filter((transaction) => transaction.settled); + } + transactions = transactions.map((transaction) => { + const boostagram = utils.getBoostagramFromInvoiceCustomRecords( + transaction.custom_records + ); + return { + ...transaction, + boostagram, + paymentHash: transaction.payment_hash, + }; + }); if (limit) { transactions = transactions.slice(0, limit); diff --git a/src/extension/background-script/connectors/connector.interface.ts b/src/extension/background-script/connectors/connector.interface.ts index 7531d30688..c011ebaece 100644 --- a/src/extension/background-script/connectors/connector.interface.ts +++ b/src/extension/background-script/connectors/connector.interface.ts @@ -35,6 +35,7 @@ export interface ConnectorTransaction { totalAmount: number; displayAmount?: [number, ACCOUNT_CURRENCIES]; type: "received" | "sent"; + state?: string; } export interface MakeInvoiceArgs { @@ -150,6 +151,7 @@ export default interface Connector { getOAuthToken?(): OAuthToken | undefined; getSwapInfo?(): Promise; createSwap?(params: CreateSwapParams): Promise; + connectorType?: string; } export function flattenRequestMethods(methods: string[]) { diff --git a/src/extension/background-script/connectors/nwc.ts b/src/extension/background-script/connectors/nwc.ts index e70aaaaabe..57f69b7d8e 100644 --- a/src/extension/background-script/connectors/nwc.ts +++ b/src/extension/background-script/connectors/nwc.ts @@ -88,10 +88,9 @@ class NWCConnector implements Connector { async getTransactions(): Promise { const listTransactionsResponse = await this.nwc.listTransactions({ - unpaid: false, limit: 50, // restricted by relay max event payload size + unpaid_outgoing: true, }); - const transactions: ConnectorTransaction[] = listTransactionsResponse.transactions.map( (transaction, index): ConnectorTransaction => ({ @@ -99,13 +98,17 @@ class NWCConnector implements Connector { memo: transaction.description, preimage: transaction.preimage, payment_hash: transaction.payment_hash, - settled: true, - settleDate: transaction.settled_at * 1000, + settled: transaction.state == "settled", + settleDate: + transaction.state == "settled" + ? transaction.settled_at * 1000 + : transaction.created_at * 1000, totalAmount: Math.floor(transaction.amount / 1000), type: transaction.type == "incoming" ? "received" : "sent", custom_records: this.tlvToCustomRecords( transaction.metadata?.["tlv_records"] as TLVRecord[] | undefined ), + state: transaction.state, }) ); return { @@ -221,6 +224,10 @@ class NWCConnector implements Connector { throw new Error("Method not implemented."); } + get connectorType(): string { + return "nwc"; + } + private customRecordsToTlv( customRecords: Record ): TlvRecord[] { diff --git a/src/i18n/locales/en/translation.json b/src/i18n/locales/en/translation.json index 359e843e17..e796b0dc85 100644 --- a/src/i18n/locales/en/translation.json +++ b/src/i18n/locales/en/translation.json @@ -1253,6 +1253,8 @@ "payment_hash": "Payment Hash", "received": "Received", "sent": "Sent", + "sending": "Sending", + "failed": "Failed", "date_time": "Date & Time", "boostagram": { "sender": "Sender", diff --git a/src/types.ts b/src/types.ts index 60ffc958ac..8883b77b63 100644 --- a/src/types.ts +++ b/src/types.ts @@ -787,6 +787,7 @@ export type Transaction = { type?: "sent" | "received"; value?: string; publisherLink?: string; // either the invoice URL if on PublisherSingleView, or the internal link to Publisher + state?: "settled" | "pending" | "failed"; }; export interface DbPayment { From 9913faad730eaaff632cb26637c296d0f7009411 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Tue, 17 Dec 2024 23:13:00 +0530 Subject: [PATCH 02/16] chore: yarn.lock --- yarn.lock | 53 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/yarn.lock b/yarn.lock index 4c2c951bb3..cca4ab4dee 100644 --- a/yarn.lock +++ b/yarn.lock @@ -675,13 +675,13 @@ resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.52.0.tgz#78fe5f117840f69dc4a353adf9b9cd926353378c" integrity sha512-mjZVbpaeMZludF2fsWLD0Z9gCref1Tk4i9+wddjRvpUNqqcndPkBD09N/Mapey0b3jaXbLm2kICwFv2E64QinA== -"@getalby/sdk@^3.6.0": - version "3.6.0" - resolved "https://registry.yarnpkg.com/@getalby/sdk/-/sdk-3.6.0.tgz#3ca47b9e150621bfb57228c0cbb8edb3b14c9394" - integrity sha512-ZpaxoZJO/71th1uaTt6viBnHn6RKTK+oCPH04sCTig+bn17cj1PAozrlIokHDQpTkkoegz6wx5w4nX+8aoSVSA== +"@getalby/sdk@^3.8.2": + version "3.8.2" + resolved "https://registry.yarnpkg.com/@getalby/sdk/-/sdk-3.8.2.tgz#84a184c46fdebf18652d6c06b92f07ed36129d3d" + integrity sha512-0F4ub/e+t93V9wzR5Vr+Xdfhhy5kK+ZKls/J3yX2YBT27X1Rd3QIPLCTUFCb4RaV6a/e17aZAVJF8Af7r9BeAg== dependencies: - eventemitter3 "^5.0.1" - nostr-tools "^1.17.0" + emittery "^1.0.3" + nostr-tools "2.9.4" "@headlessui/react@^1.7.18": version "1.7.18" @@ -1079,6 +1079,13 @@ dependencies: "@noble/hashes" "1.3.1" +"@noble/curves@1.2.0": + version "1.2.0" + resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.2.0.tgz#92d7e12e4e49b23105a2555c6984d41733d65c35" + integrity sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw== + dependencies: + "@noble/hashes" "1.3.2" + "@noble/curves@^1.4.0": version "1.4.0" resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.4.0.tgz#f05771ef64da724997f69ee1261b2417a49522d6" @@ -1098,6 +1105,11 @@ resolved "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.1.tgz" integrity sha512-EbqwksQwz9xDRGfDST86whPBgM65E0OH/pCgqW0GBVzO22bNE+NuIbeTb714+IfSjU3aRk47EUvXIb5bTsenKA== +"@noble/hashes@1.3.2", "@noble/hashes@^1.1.5": + version "1.3.2" + resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.2.tgz#6f26dbc8fbc7205873ce3cee2f690eba0d421b39" + integrity sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ== + "@noble/hashes@1.3.3", "@noble/hashes@^1.3.1", "@noble/hashes@~1.3.2": version "1.3.3" resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.3.tgz#39908da56a4adc270147bb07968bf3b16cfe1699" @@ -1108,11 +1120,6 @@ resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.4.0.tgz#45814aa329f30e4fe0ba49426f49dfccdd066426" integrity sha512-V1JJ1WTRUqHHrOSh597hURcMqVKVGL/ea3kv0gSnEdsEZ0/+VyPghM1lMNGc00z7CIQorSvbKpuJkxvuHbvdbg== -"@noble/hashes@^1.1.5": - version "1.3.2" - resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.2.tgz#6f26dbc8fbc7205873ce3cee2f690eba0d421b39" - integrity sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ== - "@noble/hashes@^1.2.0": version "1.3.0" resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.0.tgz#085fd70f6d7d9d109671090ccae1d3bec62554a1" @@ -4196,6 +4203,11 @@ emittery@^0.13.1: resolved "https://registry.npmjs.org/emittery/-/emittery-0.13.1.tgz" integrity sha512-DeWwawk6r5yR9jFgnDKYt4sLS0LmHJJi3ZOnb5/JdbYwj3nW+FxQnHIjhBKz8YLC7oRNPVM9NQ47I3CVx34eqQ== +emittery@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/emittery/-/emittery-1.0.3.tgz#c9d2a9c689870f15251bb13b31c67715c26d69ac" + integrity sha512-tJdCJitoy2lrC2ldJcqN4vkqJ00lT+tOWNT1hBJjO/3FDMJa5TTIiYGCKGkn/WfCyOzUMObeohbVTj00fhiLiA== + emoji-log@^1.0.2: version "1.0.2" resolved "https://registry.npmjs.org/emoji-log/-/emoji-log-1.0.2.tgz" @@ -7268,6 +7280,20 @@ normalize-range@^0.1.2: resolved "https://registry.npmjs.org/normalize-range/-/normalize-range-0.1.2.tgz" integrity "sha1-LRDAa9/TEuqXd2laTShDlFa3WUI= sha512-bdok/XvKII3nUpklnV6P2hxtMNrCboOjAcyBuQnWEhO665FwrSNRxU+AqpsyvO6LgGYPspN+lu5CLtw4jPRKNA==" +nostr-tools@2.9.4: + version "2.9.4" + resolved "https://registry.yarnpkg.com/nostr-tools/-/nostr-tools-2.9.4.tgz#ec0e1faa95bf9e5fee30b36c842a270135f40183" + integrity sha512-Powumwkp+EWbdK1T8IsEX4daTLQhtWJvitfZ6OP2BdU1jJZvNlUp3SQB541UYw4uc9jgLbxZW6EZSdZoSfIygQ== + dependencies: + "@noble/ciphers" "^0.5.1" + "@noble/curves" "1.2.0" + "@noble/hashes" "1.3.1" + "@scure/base" "1.1.1" + "@scure/bip32" "1.3.1" + "@scure/bip39" "1.2.1" + optionalDependencies: + nostr-wasm v0.1.0 + nostr-tools@^1.17.0: version "1.17.0" resolved "https://registry.yarnpkg.com/nostr-tools/-/nostr-tools-1.17.0.tgz#b6f62e32fedfd9e68ec0a7ce57f74c44fc768e8c" @@ -7280,6 +7306,11 @@ nostr-tools@^1.17.0: "@scure/bip32" "1.3.1" "@scure/bip39" "1.2.1" +nostr-wasm@v0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/nostr-wasm/-/nostr-wasm-0.1.0.tgz#17af486745feb2b7dd29503fdd81613a24058d94" + integrity sha512-78BTryCLcLYv96ONU8Ws3Q1JzjlAt+43pWQhIl86xZmWeegYCNLPml7yQ+gG3vR6V5h4XGj+TxO+SS5dsThQIA== + npm-run-path@^4.0.1: version "4.0.1" resolved "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz" From 070882c04352f18efdda7c59fd22455530d2138d Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Tue, 17 Dec 2024 23:56:24 +0530 Subject: [PATCH 03/16] chore: update icon --- .../TransactionsTable/TransactionModal.tsx | 4 ++-- .../components/TransactionsTable/index.tsx | 9 +++++--- src/app/icons/FailedTransaction.tsx | 21 ------------------- 3 files changed, 8 insertions(+), 26 deletions(-) delete mode 100644 src/app/icons/FailedTransaction.tsx diff --git a/src/app/components/TransactionsTable/TransactionModal.tsx b/src/app/components/TransactionsTable/TransactionModal.tsx index 4e36fb74b4..17e50e40c2 100644 --- a/src/app/components/TransactionsTable/TransactionModal.tsx +++ b/src/app/components/TransactionsTable/TransactionModal.tsx @@ -3,6 +3,7 @@ import { PopiconsArrowUpSolid, PopiconsChevronBottomLine, PopiconsChevronTopLine, + PopiconsXSolid, } from "@popicons/react"; import dayjs from "dayjs"; import { useEffect, useState } from "react"; @@ -10,7 +11,6 @@ import { useTranslation } from "react-i18next"; import Hyperlink from "~/app/components/Hyperlink"; import Modal from "~/app/components/Modal"; import { useSettings } from "~/app/context/SettingsContext"; -import CrossIcon from "~/app/icons/FailedTransaction"; import { classNames } from "~/app/utils"; import { Transaction } from "~/types"; @@ -63,7 +63,7 @@ export default function TransactionModal({

) : transaction.state === "failed" ? (
- +
) : (
diff --git a/src/app/components/TransactionsTable/index.tsx b/src/app/components/TransactionsTable/index.tsx index a0ed9798bf..0aae671996 100644 --- a/src/app/components/TransactionsTable/index.tsx +++ b/src/app/components/TransactionsTable/index.tsx @@ -1,12 +1,15 @@ import Loading from "@components/Loading"; -import { PopiconsArrowDownSolid, PopiconsArrowUpSolid } from "@popicons/react"; +import { + PopiconsArrowDownSolid, + PopiconsArrowUpSolid, + PopiconsXSolid, +} from "@popicons/react"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import TransactionModal from "~/app/components/TransactionsTable/TransactionModal"; import { useSettings } from "~/app/context/SettingsContext"; -import CrossIcon from "~/app/icons/FailedTransaction"; import { classNames } from "~/app/utils"; import { Transaction } from "~/types"; @@ -67,7 +70,7 @@ export default function TransactionsTable({
) : tx.state === "failed" ? (
- +
) : (
diff --git a/src/app/icons/FailedTransaction.tsx b/src/app/icons/FailedTransaction.tsx deleted file mode 100644 index 65b5436aa9..0000000000 --- a/src/app/icons/FailedTransaction.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import { SVGProps } from "react"; - -const CrossIcon = (props: SVGProps) => ( - - - -); - -export default CrossIcon; From 02b955cd12db5c42ccd976efeb258d8758d6018a Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Wed, 18 Dec 2024 10:36:32 +0530 Subject: [PATCH 04/16] feat: pass creationDate separately --- src/app/hooks/useTransactions.ts | 7 +++++-- src/common/utils/helpers.ts | 2 +- .../background-script/connectors/connector.interface.ts | 3 ++- src/extension/background-script/connectors/lawallet.ts | 2 +- src/extension/background-script/connectors/lndhub.ts | 2 +- src/extension/background-script/connectors/nwc.ts | 8 ++++---- src/types.ts | 3 ++- 7 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/app/hooks/useTransactions.ts b/src/app/hooks/useTransactions.ts index 68e74d1f4b..7cbacd1ab4 100644 --- a/src/app/hooks/useTransactions.ts +++ b/src/app/hooks/useTransactions.ts @@ -20,8 +20,11 @@ export const useTransactions = () => { (transaction) => ({ ...transaction, title: transaction.memo, - date: dayjs(transaction.settleDate).fromNow(), - timestamp: transaction.settleDate, + date: dayjs( + transaction.settleDate || transaction.creationDate + ).fromNow(), + timestamp: + transaction.settleDate || transaction.creationDate || Date.now(), }) ); diff --git a/src/common/utils/helpers.ts b/src/common/utils/helpers.ts index f104465a2d..6bb19e14a8 100644 --- a/src/common/utils/helpers.ts +++ b/src/common/utils/helpers.ts @@ -68,7 +68,7 @@ export function mergeTransactions( payments: ConnectorTransaction[] ): ConnectorTransaction[] { const mergedTransactions = [...invoices, ...payments].sort((a, b) => { - return b.settleDate - a.settleDate; + return (b.settleDate ?? Date.now()) - (a.settleDate ?? Date.now()); }); return mergedTransactions; diff --git a/src/extension/background-script/connectors/connector.interface.ts b/src/extension/background-script/connectors/connector.interface.ts index c011ebaece..c587528e99 100644 --- a/src/extension/background-script/connectors/connector.interface.ts +++ b/src/extension/background-script/connectors/connector.interface.ts @@ -31,7 +31,8 @@ export interface ConnectorTransaction { /** * Settle date in UNIX milliseconds */ - settleDate: number; + settleDate?: number; + creationDate?: number; totalAmount: number; displayAmount?: [number, ACCOUNT_CURRENCIES]; type: "received" | "sent"; diff --git a/src/extension/background-script/connectors/lawallet.ts b/src/extension/background-script/connectors/lawallet.ts index 999059686a..7d5c38565f 100644 --- a/src/extension/background-script/connectors/lawallet.ts +++ b/src/extension/background-script/connectors/lawallet.ts @@ -128,7 +128,7 @@ export default class LaWallet implements Connector { return { data: { transactions: parsedTransactions.sort( - (a, b) => b.settleDate - a.settleDate + (a, b) => (b.settleDate ?? Date.now()) - (a.settleDate ?? Date.now()) ), }, }; diff --git a/src/extension/background-script/connectors/lndhub.ts b/src/extension/background-script/connectors/lndhub.ts index 0286a61a17..f50ad1031a 100644 --- a/src/extension/background-script/connectors/lndhub.ts +++ b/src/extension/background-script/connectors/lndhub.ts @@ -120,7 +120,7 @@ export default class LndHub implements Connector { }) ) .sort((a, b) => { - return b.settleDate - a.settleDate; + return (b.settleDate ?? Date.now()) - (a.settleDate ?? Date.now()); }); return invoices; diff --git a/src/extension/background-script/connectors/nwc.ts b/src/extension/background-script/connectors/nwc.ts index 57f69b7d8e..b212b05284 100644 --- a/src/extension/background-script/connectors/nwc.ts +++ b/src/extension/background-script/connectors/nwc.ts @@ -99,10 +99,10 @@ class NWCConnector implements Connector { preimage: transaction.preimage, payment_hash: transaction.payment_hash, settled: transaction.state == "settled", - settleDate: - transaction.state == "settled" - ? transaction.settled_at * 1000 - : transaction.created_at * 1000, + ...(transaction.state == "settled" && transaction.settled_at + ? { settleDate: transaction.settled_at * 1000 } + : {}), + creationDate: transaction.created_at * 1000, totalAmount: Math.floor(transaction.amount / 1000), type: transaction.type == "incoming" ? "received" : "sent", custom_records: this.tlvToCustomRecords( diff --git a/src/types.ts b/src/types.ts index 8883b77b63..1cf2495f25 100644 --- a/src/types.ts +++ b/src/types.ts @@ -959,7 +959,8 @@ export interface Invoice { memo?: string; type: "received" | "sent"; settled: boolean; - settleDate: number; + settleDate?: number; + creationDate?: number; totalAmount: number; totalAmountFiat?: string; displayAmount?: [number, ACCOUNT_CURRENCIES]; From cebe80d072d2214352085a251bf06ce4055ad812 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Tue, 24 Dec 2024 14:20:43 +0530 Subject: [PATCH 05/16] chore: typings for state var --- .../background-script/connectors/connector.interface.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extension/background-script/connectors/connector.interface.ts b/src/extension/background-script/connectors/connector.interface.ts index c587528e99..2b7e605457 100644 --- a/src/extension/background-script/connectors/connector.interface.ts +++ b/src/extension/background-script/connectors/connector.interface.ts @@ -36,7 +36,7 @@ export interface ConnectorTransaction { totalAmount: number; displayAmount?: [number, ACCOUNT_CURRENCIES]; type: "received" | "sent"; - state?: string; + state?: "settled" | "pending" | "failed"; } export interface MakeInvoiceArgs { From 14060debf37fd3c4aa67efac770f46b1b7f8794f Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Tue, 24 Dec 2024 16:00:04 +0530 Subject: [PATCH 06/16] fix: colors --- .../TransactionsTable/TransactionModal.tsx | 13 ++++++++++--- src/app/components/TransactionsTable/index.tsx | 13 ++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/app/components/TransactionsTable/TransactionModal.tsx b/src/app/components/TransactionsTable/TransactionModal.tsx index 17e50e40c2..19a2e499a3 100644 --- a/src/app/components/TransactionsTable/TransactionModal.tsx +++ b/src/app/components/TransactionsTable/TransactionModal.tsx @@ -62,8 +62,8 @@ export default function TransactionModal({
) : transaction.state === "failed" ? ( -
- +
+
) : (
@@ -77,7 +77,12 @@ export default function TransactionModal({ )}
-

+

{transaction.type == "received" ? t("received") : t( @@ -98,6 +103,8 @@ export default function TransactionModal({ "text-3xl font-medium", transaction.type == "received" ? "text-green-600 dark:text-emerald-500" + : transaction.state == "failed" + ? "text-red-400 dark:text-rose-600" : "text-orange-600 dark:text-amber-600" )} > diff --git a/src/app/components/TransactionsTable/index.tsx b/src/app/components/TransactionsTable/index.tsx index 0aae671996..4d560d2b64 100644 --- a/src/app/components/TransactionsTable/index.tsx +++ b/src/app/components/TransactionsTable/index.tsx @@ -69,8 +69,8 @@ export default function TransactionsTable({

) : tx.state === "failed" ? ( -
- +
+
) : (
@@ -85,7 +85,12 @@ export default function TransactionsTable({
-

+

{tx.title || tx.boostagram?.message || (type == "incoming" @@ -112,6 +117,8 @@ export default function TransactionsTable({ "text-sm", type == "incoming" ? "text-green-600 dark:text-emerald-500" + : tx.state == "failed" + ? "text-red-600 dark:text-rose-500" : "text-orange-600 dark:text-amber-600" )} > From f5aa8be514212d1d282b4d4cfcbc8653c207c289 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Tue, 24 Dec 2024 16:36:19 +0530 Subject: [PATCH 07/16] fix: typescript --- src/common/utils/helpers.ts | 2 +- .../background-script/connectors/connector.interface.ts | 2 +- src/extension/background-script/connectors/lawallet.ts | 2 +- src/extension/background-script/connectors/lndhub.ts | 2 +- src/extension/background-script/connectors/nwc.ts | 4 +--- src/types.ts | 2 +- 6 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/common/utils/helpers.ts b/src/common/utils/helpers.ts index 6bb19e14a8..b54e97d3c3 100644 --- a/src/common/utils/helpers.ts +++ b/src/common/utils/helpers.ts @@ -68,7 +68,7 @@ export function mergeTransactions( payments: ConnectorTransaction[] ): ConnectorTransaction[] { const mergedTransactions = [...invoices, ...payments].sort((a, b) => { - return (b.settleDate ?? Date.now()) - (a.settleDate ?? Date.now()); + return (b.settleDate ?? 0) - (a.settleDate ?? 0); }); return mergedTransactions; diff --git a/src/extension/background-script/connectors/connector.interface.ts b/src/extension/background-script/connectors/connector.interface.ts index 2b7e605457..a668f0289e 100644 --- a/src/extension/background-script/connectors/connector.interface.ts +++ b/src/extension/background-script/connectors/connector.interface.ts @@ -31,7 +31,7 @@ export interface ConnectorTransaction { /** * Settle date in UNIX milliseconds */ - settleDate?: number; + settleDate: number | null; creationDate?: number; totalAmount: number; displayAmount?: [number, ACCOUNT_CURRENCIES]; diff --git a/src/extension/background-script/connectors/lawallet.ts b/src/extension/background-script/connectors/lawallet.ts index 7d5c38565f..68ee820a5e 100644 --- a/src/extension/background-script/connectors/lawallet.ts +++ b/src/extension/background-script/connectors/lawallet.ts @@ -128,7 +128,7 @@ export default class LaWallet implements Connector { return { data: { transactions: parsedTransactions.sort( - (a, b) => (b.settleDate ?? Date.now()) - (a.settleDate ?? Date.now()) + (a, b) => (b.settleDate ?? 0) - (a.settleDate ?? 0) ), }, }; diff --git a/src/extension/background-script/connectors/lndhub.ts b/src/extension/background-script/connectors/lndhub.ts index f50ad1031a..af623a1f7e 100644 --- a/src/extension/background-script/connectors/lndhub.ts +++ b/src/extension/background-script/connectors/lndhub.ts @@ -120,7 +120,7 @@ export default class LndHub implements Connector { }) ) .sort((a, b) => { - return (b.settleDate ?? Date.now()) - (a.settleDate ?? Date.now()); + return (b.settleDate ?? 0) - (a.settleDate ?? 0); }); return invoices; diff --git a/src/extension/background-script/connectors/nwc.ts b/src/extension/background-script/connectors/nwc.ts index b212b05284..67f77b2da4 100644 --- a/src/extension/background-script/connectors/nwc.ts +++ b/src/extension/background-script/connectors/nwc.ts @@ -99,9 +99,7 @@ class NWCConnector implements Connector { preimage: transaction.preimage, payment_hash: transaction.payment_hash, settled: transaction.state == "settled", - ...(transaction.state == "settled" && transaction.settled_at - ? { settleDate: transaction.settled_at * 1000 } - : {}), + settleDate: transaction.settled_at * 1000, creationDate: transaction.created_at * 1000, totalAmount: Math.floor(transaction.amount / 1000), type: transaction.type == "incoming" ? "received" : "sent", diff --git a/src/types.ts b/src/types.ts index 1cf2495f25..372df0cda5 100644 --- a/src/types.ts +++ b/src/types.ts @@ -959,7 +959,7 @@ export interface Invoice { memo?: string; type: "received" | "sent"; settled: boolean; - settleDate?: number; + settleDate: number | null; creationDate?: number; totalAmount: number; totalAmountFiat?: string; From 6686c979ea67beebbbd0732e6b9d579f1a34a8a5 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Tue, 24 Dec 2024 17:03:03 +0530 Subject: [PATCH 08/16] feat: filter transactions by settleDate at connectorLevel --- .../actions/ln/getTransactions.ts | 29 +++++++++---------- .../background-script/connectors/alby.ts | 28 +++++++++--------- .../background-script/connectors/commando.ts | 2 +- .../connectors/connector.interface.ts | 1 - .../background-script/connectors/galoy.ts | 8 +++-- .../background-script/connectors/lawallet.ts | 6 ++-- .../background-script/connectors/lnbits.ts | 8 ++--- .../background-script/connectors/lnc.ts | 2 +- .../background-script/connectors/lnd.ts | 2 +- .../background-script/connectors/lndhub.ts | 2 +- .../background-script/connectors/nwc.ts | 4 --- 11 files changed, 45 insertions(+), 47 deletions(-) diff --git a/src/extension/background-script/actions/ln/getTransactions.ts b/src/extension/background-script/actions/ln/getTransactions.ts index cf3fd460d1..62f71715c5 100644 --- a/src/extension/background-script/actions/ln/getTransactions.ts +++ b/src/extension/background-script/actions/ln/getTransactions.ts @@ -9,22 +9,19 @@ const getTransactions = async (message: MessageGetTransactions) => { const connector = await state.getState().getConnector(); try { const result = await connector.getTransactions(); - const isNWC = connector.connectorType == "nwc"; - // we show pending and failed transactions for nwc. pass on all transactions for nwc connector to frontend - let transactions: ConnectorTransaction[] = result.data.transactions; - if (!isNWC) { - transactions = transactions.filter((transaction) => transaction.settled); - } - transactions = transactions.map((transaction) => { - const boostagram = utils.getBoostagramFromInvoiceCustomRecords( - transaction.custom_records - ); - return { - ...transaction, - boostagram, - paymentHash: transaction.payment_hash, - }; - }); + + let transactions: ConnectorTransaction[] = result.data.transactions.map( + (transaction) => { + const boostagram = utils.getBoostagramFromInvoiceCustomRecords( + transaction.custom_records + ); + return { + ...transaction, + boostagram, + paymentHash: transaction.payment_hash, + }; + } + ); if (limit) { transactions = transactions.slice(0, limit); diff --git a/src/extension/background-script/connectors/alby.ts b/src/extension/background-script/connectors/alby.ts index fada7ec0a2..536ea2bc20 100644 --- a/src/extension/background-script/connectors/alby.ts +++ b/src/extension/background-script/connectors/alby.ts @@ -113,19 +113,21 @@ export default class Alby implements Connector { client.invoices({}) )) as Invoice[]; - const transactions: ConnectorTransaction[] = invoicesResponse.map( - (invoice, index): ConnectorTransaction => ({ - custom_records: invoice.custom_records, - id: `${invoice.payment_request}-${index}`, - memo: invoice.comment || invoice.memo, - preimage: invoice.preimage ?? "", - payment_hash: invoice.payment_hash, - settled: invoice.settled, - settleDate: new Date(invoice.settled_at).getTime(), - totalAmount: invoice.amount, - type: invoice.type == "incoming" ? "received" : "sent", - }) - ); + const transactions: ConnectorTransaction[] = invoicesResponse + .map( + (invoice, index): ConnectorTransaction => ({ + custom_records: invoice.custom_records, + id: `${invoice.payment_request}-${index}`, + memo: invoice.comment || invoice.memo, + preimage: invoice.preimage ?? "", + payment_hash: invoice.payment_hash, + settled: invoice.settled, + settleDate: new Date(invoice.settled_at).getTime(), + totalAmount: invoice.amount, + type: invoice.type == "incoming" ? "received" : "sent", + }) + ) + .filter((transaction) => transaction.settled); return { data: { diff --git a/src/extension/background-script/connectors/commando.ts b/src/extension/background-script/connectors/commando.ts index 9a627a49a5..1c167a11c9 100644 --- a/src/extension/background-script/connectors/commando.ts +++ b/src/extension/background-script/connectors/commando.ts @@ -261,7 +261,7 @@ export default class Commando implements Connector { const transactions: ConnectorTransaction[] = mergeTransactions( incomingInvoicesResponse, outgoingInvoicesResponse - ); + ).filter((transaction) => transaction.settled); return { data: { diff --git a/src/extension/background-script/connectors/connector.interface.ts b/src/extension/background-script/connectors/connector.interface.ts index a668f0289e..d3063f0083 100644 --- a/src/extension/background-script/connectors/connector.interface.ts +++ b/src/extension/background-script/connectors/connector.interface.ts @@ -152,7 +152,6 @@ export default interface Connector { getOAuthToken?(): OAuthToken | undefined; getSwapInfo?(): Promise; createSwap?(params: CreateSwapParams): Promise; - connectorType?: string; } export function flattenRequestMethods(methods: string[]) { diff --git a/src/extension/background-script/connectors/galoy.ts b/src/extension/background-script/connectors/galoy.ts index 4bf71ef0c9..ee080463dd 100644 --- a/src/extension/background-script/connectors/galoy.ts +++ b/src/extension/background-script/connectors/galoy.ts @@ -238,7 +238,7 @@ class Galoy implements Connector { ); } - transactions.push({ + const transaction: ConnectorTransaction = { id: edge.cursor, memo: tx.memo || paymentRequestDescription, preimage: @@ -249,7 +249,11 @@ class Galoy implements Connector { totalAmount: absSettlementAmount, type: transactionType, displayAmount, - }); + }; + + if (transaction.settled) { + transactions.push(transaction); + } } } diff --git a/src/extension/background-script/connectors/lawallet.ts b/src/extension/background-script/connectors/lawallet.ts index 68ee820a5e..00f272a2ae 100644 --- a/src/extension/background-script/connectors/lawallet.ts +++ b/src/extension/background-script/connectors/lawallet.ts @@ -127,9 +127,9 @@ export default class LaWallet implements Connector { return { data: { - transactions: parsedTransactions.sort( - (a, b) => (b.settleDate ?? 0) - (a.settleDate ?? 0) - ), + transactions: parsedTransactions + .sort((a, b) => (b.settleDate ?? 0) - (a.settleDate ?? 0)) + .filter((transaction) => transaction.settled), }, }; } diff --git a/src/extension/background-script/connectors/lnbits.ts b/src/extension/background-script/connectors/lnbits.ts index d5440ec611..68b76fea95 100644 --- a/src/extension/background-script/connectors/lnbits.ts +++ b/src/extension/background-script/connectors/lnbits.ts @@ -122,8 +122,8 @@ class LnBits implements Connector { webhook_status: string; }[] ) => { - const transactions: ConnectorTransaction[] = data.map( - (transaction, index): ConnectorTransaction => { + const transactions: ConnectorTransaction[] = data + .map((transaction, index): ConnectorTransaction => { return { id: `${transaction.checking_id}-${index}`, memo: transaction.memo, @@ -138,8 +138,8 @@ class LnBits implements Connector { totalAmount: Math.abs(Math.floor(transaction.amount / 1000)), type: transaction.amount > 0 ? "received" : "sent", }; - } - ); + }) + .filter((transaction) => transaction.settled); return { data: { diff --git a/src/extension/background-script/connectors/lnc.ts b/src/extension/background-script/connectors/lnc.ts index fb93faee18..a9a8fa2fe6 100644 --- a/src/extension/background-script/connectors/lnc.ts +++ b/src/extension/background-script/connectors/lnc.ts @@ -282,7 +282,7 @@ class Lnc implements Connector { const transactions: ConnectorTransaction[] = mergeTransactions( incomingInvoices, outgoingInvoices - ); + ).filter((transaction) => transaction.settled); return { data: { diff --git a/src/extension/background-script/connectors/lnd.ts b/src/extension/background-script/connectors/lnd.ts index f9fef3e3a3..1dd8c72063 100644 --- a/src/extension/background-script/connectors/lnd.ts +++ b/src/extension/background-script/connectors/lnd.ts @@ -484,7 +484,7 @@ class Lnd implements Connector { const transactions: ConnectorTransaction[] = mergeTransactions( invoices, payments - ); + ).filter((transaction) => transaction.settled); return { data: { diff --git a/src/extension/background-script/connectors/lndhub.ts b/src/extension/background-script/connectors/lndhub.ts index af623a1f7e..5afdb1dbe1 100644 --- a/src/extension/background-script/connectors/lndhub.ts +++ b/src/extension/background-script/connectors/lndhub.ts @@ -133,7 +133,7 @@ export default class LndHub implements Connector { const transactions: ConnectorTransaction[] = mergeTransactions( incomingInvoices, outgoingInvoices - ); + ).filter((transaction) => transaction.settled); return { data: { diff --git a/src/extension/background-script/connectors/nwc.ts b/src/extension/background-script/connectors/nwc.ts index 67f77b2da4..51b5fbbb59 100644 --- a/src/extension/background-script/connectors/nwc.ts +++ b/src/extension/background-script/connectors/nwc.ts @@ -222,10 +222,6 @@ class NWCConnector implements Connector { throw new Error("Method not implemented."); } - get connectorType(): string { - return "nwc"; - } - private customRecordsToTlv( customRecords: Record ): TlvRecord[] { From a9a9e4c4d7073d8073ca4b013a89140f32d369d3 Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Thu, 2 Jan 2025 11:35:07 +0700 Subject: [PATCH 09/16] fix: add missing pending animations --- src/app/components/TransactionsTable/TransactionModal.tsx | 2 +- src/app/components/TransactionsTable/index.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/components/TransactionsTable/TransactionModal.tsx b/src/app/components/TransactionsTable/TransactionModal.tsx index 19a2e499a3..605f423c0d 100644 --- a/src/app/components/TransactionsTable/TransactionModal.tsx +++ b/src/app/components/TransactionsTable/TransactionModal.tsx @@ -58,7 +58,7 @@ export default function TransactionModal({

{getTransactionType(transaction) == "outgoing" ? ( transaction.state === "pending" ? ( -
+
) : transaction.state === "failed" ? ( diff --git a/src/app/components/TransactionsTable/index.tsx b/src/app/components/TransactionsTable/index.tsx index 4d560d2b64..5c90fb8d1f 100644 --- a/src/app/components/TransactionsTable/index.tsx +++ b/src/app/components/TransactionsTable/index.tsx @@ -65,7 +65,7 @@ export default function TransactionsTable({
{type == "outgoing" ? ( tx.state === "pending" ? ( -
+
) : tx.state === "failed" ? ( From c44add11a1dd1748901403503ee32ecec18f745d Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Thu, 2 Jan 2025 19:21:51 +0530 Subject: [PATCH 10/16] chore: change pending transaction icons to blue --- src/app/components/TransactionsTable/TransactionModal.tsx | 8 ++++---- src/app/components/TransactionsTable/index.tsx | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/app/components/TransactionsTable/TransactionModal.tsx b/src/app/components/TransactionsTable/TransactionModal.tsx index 605f423c0d..c6654bb5a0 100644 --- a/src/app/components/TransactionsTable/TransactionModal.tsx +++ b/src/app/components/TransactionsTable/TransactionModal.tsx @@ -58,12 +58,12 @@ export default function TransactionModal({
{getTransactionType(transaction) == "outgoing" ? ( transaction.state === "pending" ? ( -
- +
+
) : transaction.state === "failed" ? ( -
- +
+
) : (
diff --git a/src/app/components/TransactionsTable/index.tsx b/src/app/components/TransactionsTable/index.tsx index 5c90fb8d1f..d370bc8556 100644 --- a/src/app/components/TransactionsTable/index.tsx +++ b/src/app/components/TransactionsTable/index.tsx @@ -65,12 +65,12 @@ export default function TransactionsTable({
{type == "outgoing" ? ( tx.state === "pending" ? ( -
- +
+
) : tx.state === "failed" ? (
- +
) : (
From a8478b8a01ecda0e69e431a18d7cf0b95bb4982e Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Thu, 9 Jan 2025 20:11:56 +0530 Subject: [PATCH 11/16] feat: add creationDate for all connectors --- src/app/hooks/useTransactions.ts | 3 +- .../background-script/connectors/alby.ts | 1 + .../background-script/connectors/commando.ts | 37 +++++++++++++++---- .../connectors/connector.interface.ts | 2 +- .../background-script/connectors/galoy.ts | 1 + .../background-script/connectors/lawallet.ts | 1 + .../background-script/connectors/lnbits.ts | 7 ++++ .../background-script/connectors/lnc.ts | 2 + .../background-script/connectors/lnd.ts | 2 + .../background-script/connectors/lndhub.ts | 2 + src/types.ts | 2 +- 11 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/app/hooks/useTransactions.ts b/src/app/hooks/useTransactions.ts index 7cbacd1ab4..11ff46a2fe 100644 --- a/src/app/hooks/useTransactions.ts +++ b/src/app/hooks/useTransactions.ts @@ -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, }) ); diff --git a/src/extension/background-script/connectors/alby.ts b/src/extension/background-script/connectors/alby.ts index 536ea2bc20..8542b60a69 100644 --- a/src/extension/background-script/connectors/alby.ts +++ b/src/extension/background-script/connectors/alby.ts @@ -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", }) diff --git a/src/extension/background-script/connectors/commando.ts b/src/extension/background-script/connectors/commando.ts index 1c167a11c9..1e723ee28b 100644 --- a/src/extension/background-script/connectors/commando.ts +++ b/src/extension/background-script/connectors/commando.ts @@ -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, @@ -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); }); } @@ -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); }); } diff --git a/src/extension/background-script/connectors/connector.interface.ts b/src/extension/background-script/connectors/connector.interface.ts index d3063f0083..4349e6b934 100644 --- a/src/extension/background-script/connectors/connector.interface.ts +++ b/src/extension/background-script/connectors/connector.interface.ts @@ -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"; diff --git a/src/extension/background-script/connectors/galoy.ts b/src/extension/background-script/connectors/galoy.ts index ee080463dd..ff2d2121b1 100644 --- a/src/extension/background-script/connectors/galoy.ts +++ b/src/extension/background-script/connectors/galoy.ts @@ -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, diff --git a/src/extension/background-script/connectors/lawallet.ts b/src/extension/background-script/connectors/lawallet.ts index 00f272a2ae..a5cfa9ac75 100644 --- a/src/extension/background-script/connectors/lawallet.ts +++ b/src/extension/background-script/connectors/lawallet.ts @@ -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: {}, diff --git a/src/extension/background-script/connectors/lnbits.ts b/src/extension/background-script/connectors/lnbits.ts index 68b76fea95..59cdc015ad 100644 --- a/src/extension/background-script/connectors/lnbits.ts +++ b/src/extension/background-script/connectors/lnbits.ts @@ -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, @@ -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", }; diff --git a/src/extension/background-script/connectors/lnc.ts b/src/extension/background-script/connectors/lnc.ts index a9a8fa2fe6..136467b70c 100644 --- a/src/extension/background-script/connectors/lnc.ts +++ b/src/extension/background-script/connectors/lnc.ts @@ -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", }; @@ -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", }; diff --git a/src/extension/background-script/connectors/lnd.ts b/src/extension/background-script/connectors/lnd.ts index 1dd8c72063..0160a06aee 100644 --- a/src/extension/background-script/connectors/lnd.ts +++ b/src/extension/background-script/connectors/lnd.ts @@ -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, @@ -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", }; diff --git a/src/extension/background-script/connectors/lndhub.ts b/src/extension/background-script/connectors/lndhub.ts index 5afdb1dbe1..bc5bff1463 100644 --- a/src/extension/background-script/connectors/lndhub.ts +++ b/src/extension/background-script/connectors/lndhub.ts @@ -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", }) @@ -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", }) diff --git a/src/types.ts b/src/types.ts index 372df0cda5..f09aa9e96b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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]; From a54914e267881230f1490f7cd09b6c8e1be2b62e Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Fri, 10 Jan 2025 13:37:20 +0530 Subject: [PATCH 12/16] feat: update sorting --- src/common/utils/helpers.ts | 12 +++++-- .../background-script/connectors/lawallet.ts | 20 ++++++----- .../background-script/connectors/lndhub.ts | 34 +++++++++---------- 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/common/utils/helpers.ts b/src/common/utils/helpers.ts index b54e97d3c3..161dab873a 100644 --- a/src/common/utils/helpers.ts +++ b/src/common/utils/helpers.ts @@ -63,13 +63,19 @@ export async function poll({ return new Promise(executePoll); } +function hasSettleDate( + transaction: ConnectorTransaction +): transaction is ConnectorTransaction & { settleDate: number } { + return transaction.settleDate !== null; +} + export function mergeTransactions( invoices: ConnectorTransaction[], payments: ConnectorTransaction[] ): ConnectorTransaction[] { - const mergedTransactions = [...invoices, ...payments].sort((a, b) => { - return (b.settleDate ?? 0) - (a.settleDate ?? 0); - }); + const mergedTransactions = [...invoices, ...payments] + .filter(hasSettleDate) + .sort((a, b) => b.settleDate - a.settleDate); return mergedTransactions; } diff --git a/src/extension/background-script/connectors/lawallet.ts b/src/extension/background-script/connectors/lawallet.ts index a5cfa9ac75..a489d0616a 100644 --- a/src/extension/background-script/connectors/lawallet.ts +++ b/src/extension/background-script/connectors/lawallet.ts @@ -112,12 +112,14 @@ export default class LaWallet implements Connector { } ); - const transactions = _transactions.map((event) => { - return { - ...event, - kind: event.kind as EventKind, - }; - }) as Event[]; + const transactions: Event[] = _transactions + .map((event) => { + return { + ...event, + kind: event.kind as EventKind, + }; + }) + .sort((a, b) => b.created_at - a.created_at); const parsedTransactions: ConnectorTransaction[] = await Promise.all( transactions.map( @@ -127,9 +129,9 @@ export default class LaWallet implements Connector { return { data: { - transactions: parsedTransactions - .sort((a, b) => (b.settleDate ?? 0) - (a.settleDate ?? 0)) - .filter((transaction) => transaction.settled), + transactions: parsedTransactions.filter( + (transaction) => transaction.settled + ), }, }; } diff --git a/src/extension/background-script/connectors/lndhub.ts b/src/extension/background-script/connectors/lndhub.ts index bc5bff1463..24243e599d 100644 --- a/src/extension/background-script/connectors/lndhub.ts +++ b/src/extension/background-script/connectors/lndhub.ts @@ -105,24 +105,22 @@ export default class LndHub implements Connector { }[] >("GET", "/getuserinvoices", undefined); - const invoices: ConnectorTransaction[] = data - .map( - (invoice, index): ConnectorTransaction => ({ - custom_records: invoice.custom_records, - id: `${invoice.payment_request}-${index}`, - memo: invoice.description, - preimage: "", // lndhub doesn't support preimage (yet) - payment_hash: invoice.payment_hash, - settled: invoice.ispaid, - settleDate: invoice.timestamp * 1000, - creationDate: invoice.timestamp * 1000, - totalAmount: invoice.amt, - type: "received", - }) - ) - .sort((a, b) => { - return (b.settleDate ?? 0) - (a.settleDate ?? 0); - }); + data.sort((a, b) => b.timestamp - a.timestamp); + + const invoices: ConnectorTransaction[] = data.map( + (invoice, index): ConnectorTransaction => ({ + custom_records: invoice.custom_records, + id: `${invoice.payment_request}-${index}`, + memo: invoice.description, + preimage: "", // lndhub doesn't support preimage (yet) + payment_hash: invoice.payment_hash, + settled: invoice.ispaid, + settleDate: invoice.timestamp * 1000, + creationDate: invoice.timestamp * 1000, + totalAmount: invoice.amt, + type: "received", + }) + ); return invoices; } From 40b374abc7920d6c10deb2a9a4af77bb99df5fe4 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Fri, 10 Jan 2025 14:57:22 +0530 Subject: [PATCH 13/16] feat: date --> timeAgo --- src/app/components/TransactionsTable/index.test.tsx | 10 +++++----- src/app/components/TransactionsTable/index.tsx | 2 +- src/app/hooks/useTransactions.ts | 2 +- src/app/utils/payments.ts | 2 +- src/types.ts | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/app/components/TransactionsTable/index.test.tsx b/src/app/components/TransactionsTable/index.test.tsx index cf29b6bf12..8e8089de80 100644 --- a/src/app/components/TransactionsTable/index.test.tsx +++ b/src/app/components/TransactionsTable/index.test.tsx @@ -22,7 +22,7 @@ const transactions: Props = { { timestamp: 1656573909064, createdAt: "1656573909064", - date: "5 days ago", + timeAgo: "5 days ago", description: "Polar Invoice for bob", host: "https://openai.com/dall-e-2/", id: "1", @@ -49,7 +49,7 @@ const invoices: Props = { totalAmountFiat: "$13.02", preimage: "", title: "lambo lambo", - date: "4 days ago", + timeAgo: "4 days ago", }, { id: "lnbcrt6543210n1p3tadjepp5rv6ufq4vumg66l9gcyxqhy89n6w90mx0mh6gcj0sawrf6xuep5ssdq5g9kxy7fqd9h8vmmfvdjscqzpgxqyz5vqsp5f9yzxeqjw33ule4rffuh0py32gjjsx8z48cd4xjl8ej3rn7zdtdq9qyyssqe6qvkfe260myc9ypgs5n63xzwcx82fderg8p5ysh6c2fvpz5xu4ksvhs5av0wwestk5pmucmhk8lpjhmy7wqyq9c29xgm9na2q5xv5spy5kukj", @@ -59,7 +59,7 @@ const invoices: Props = { totalAmountFiat: "$127.80", preimage: "", title: "Alby invoice", - date: "6 days ago", + timeAgo: "6 days ago", }, ], }; @@ -74,7 +74,7 @@ const invoicesWithBoostagram: Props = { totalAmountFiat: "$13.02", preimage: "", title: "lambo lambo", - date: "4 days ago", + timeAgo: "4 days ago", }, { id: "lnbcrt888880n1p3tad30pp56j6g34wctydrfx4wwdwj3schell8uqug6jnlehlkpw02mdfd9wlqdq0v36k6urvd9hxwuccqzpgxqyz5vqsp5995q4egstsvnyetwvpax6jw8q0fnn4tyz3gp35k3yex29emhsylq9qyyssq0yxpx6peyn4vsepwj3l68w9sc5dqnkt07zff6aw4kqvcfs0fpu4jpfh929w6vqrgtjfkmrlwghq4s9t4mnwrh4dlkm6wjem5uq8eu4gpwqln0j", @@ -84,7 +84,7 @@ const invoicesWithBoostagram: Props = { totalAmountFiat: "$17.36", preimage: "", title: "dumplings", - date: "5 days ago", + timeAgo: "5 days ago", boostagram: { app_name: "Fountain", name: "Friedemann", diff --git a/src/app/components/TransactionsTable/index.tsx b/src/app/components/TransactionsTable/index.tsx index d370bc8556..0134081058 100644 --- a/src/app/components/TransactionsTable/index.tsx +++ b/src/app/components/TransactionsTable/index.tsx @@ -107,7 +107,7 @@ export default function TransactionsTable({

- {tx.date} + {tx.timeAgo}

diff --git a/src/app/hooks/useTransactions.ts b/src/app/hooks/useTransactions.ts index 11ff46a2fe..c3839a294c 100644 --- a/src/app/hooks/useTransactions.ts +++ b/src/app/hooks/useTransactions.ts @@ -20,7 +20,7 @@ export const useTransactions = () => { (transaction) => ({ ...transaction, title: transaction.memo, - date: dayjs( + timeAgo: dayjs( transaction.settleDate || transaction.creationDate ).fromNow(), timestamp: transaction.settleDate || transaction.creationDate, diff --git a/src/app/utils/payments.ts b/src/app/utils/payments.ts index 16bca621e0..4b3368d6a3 100644 --- a/src/app/utils/payments.ts +++ b/src/app/utils/payments.ts @@ -8,7 +8,7 @@ export const convertPaymentToTransaction = ( ...payment, id: `${payment.id}`, type: "sent", - date: dayjs(+payment.createdAt).fromNow(), + timeAgo: dayjs(+payment.createdAt).fromNow(), title: payment.description || payment.name, publisherLink: publisherLink || payment.location, timestamp: parseInt(payment.createdAt), diff --git a/src/types.ts b/src/types.ts index f09aa9e96b..03d65b44a0 100644 --- a/src/types.ts +++ b/src/types.ts @@ -771,7 +771,7 @@ export type Transaction = { boostagram?: Invoice["boostagram"]; createdAt?: string; currency?: string; - date: string; + timeAgo: string; paymentHash?: string; description?: string; host?: string; From 82c6078e2712aa044cf0114d1711b19cc93378a1 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Fri, 10 Jan 2025 17:33:47 +0530 Subject: [PATCH 14/16] feat: new transaction icon colors --- .../TransactionsTable/TransactionModal.tsx | 14 +++++++------- src/app/components/TransactionsTable/index.tsx | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/app/components/TransactionsTable/TransactionModal.tsx b/src/app/components/TransactionsTable/TransactionModal.tsx index c6654bb5a0..900d73dbc1 100644 --- a/src/app/components/TransactionsTable/TransactionModal.tsx +++ b/src/app/components/TransactionsTable/TransactionModal.tsx @@ -58,21 +58,21 @@ export default function TransactionModal({
{getTransactionType(transaction) == "outgoing" ? ( transaction.state === "pending" ? ( -
- +
+
) : transaction.state === "failed" ? ( -
- +
+
) : ( -
- +
+
) ) : (
- +
)}
diff --git a/src/app/components/TransactionsTable/index.tsx b/src/app/components/TransactionsTable/index.tsx index 0134081058..d12a6b8043 100644 --- a/src/app/components/TransactionsTable/index.tsx +++ b/src/app/components/TransactionsTable/index.tsx @@ -65,21 +65,21 @@ export default function TransactionsTable({
{type == "outgoing" ? ( tx.state === "pending" ? ( -
- +
+
) : tx.state === "failed" ? (
- +
) : ( -
- +
+
) ) : (
- +
)}
From 1784673f5ac01c768776b47b9e63ebe3bca55ada Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Wed, 15 Jan 2025 12:16:31 +0530 Subject: [PATCH 15/16] fix: remove filtering from merge transactions --- src/common/utils/helpers.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/common/utils/helpers.ts b/src/common/utils/helpers.ts index 161dab873a..b54e97d3c3 100644 --- a/src/common/utils/helpers.ts +++ b/src/common/utils/helpers.ts @@ -63,19 +63,13 @@ export async function poll({ return new Promise(executePoll); } -function hasSettleDate( - transaction: ConnectorTransaction -): transaction is ConnectorTransaction & { settleDate: number } { - return transaction.settleDate !== null; -} - export function mergeTransactions( invoices: ConnectorTransaction[], payments: ConnectorTransaction[] ): ConnectorTransaction[] { - const mergedTransactions = [...invoices, ...payments] - .filter(hasSettleDate) - .sort((a, b) => b.settleDate - a.settleDate); + const mergedTransactions = [...invoices, ...payments].sort((a, b) => { + return (b.settleDate ?? 0) - (a.settleDate ?? 0); + }); return mergedTransactions; } From ffcc1eb921d9791b9a4cbc6792ab67574c36d696 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Thu, 23 Jan 2025 17:02:17 +0530 Subject: [PATCH 16/16] feat: update js-sdk --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 4174f76398..e615450999 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ }, "dependencies": { "@bitcoinerlab/secp256k1": "^1.1.1", - "@getalby/sdk": "^3.8.2", + "@getalby/sdk": "^3.9.0", "@headlessui/react": "^1.7.18", "@lightninglabs/lnc-web": "^0.3.1-alpha", "@noble/ciphers": "^0.5.1", diff --git a/yarn.lock b/yarn.lock index cca4ab4dee..f7e27451d7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -675,10 +675,10 @@ resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.52.0.tgz#78fe5f117840f69dc4a353adf9b9cd926353378c" integrity sha512-mjZVbpaeMZludF2fsWLD0Z9gCref1Tk4i9+wddjRvpUNqqcndPkBD09N/Mapey0b3jaXbLm2kICwFv2E64QinA== -"@getalby/sdk@^3.8.2": - version "3.8.2" - resolved "https://registry.yarnpkg.com/@getalby/sdk/-/sdk-3.8.2.tgz#84a184c46fdebf18652d6c06b92f07ed36129d3d" - integrity sha512-0F4ub/e+t93V9wzR5Vr+Xdfhhy5kK+ZKls/J3yX2YBT27X1Rd3QIPLCTUFCb4RaV6a/e17aZAVJF8Af7r9BeAg== +"@getalby/sdk@^3.9.0": + version "3.9.0" + resolved "https://registry.yarnpkg.com/@getalby/sdk/-/sdk-3.9.0.tgz#4eb4dd9512fc41312c8a894b7f653360feb61eac" + integrity sha512-qgNXr4FsX0a+PPvWgb112Q8h1/ov31zVP4LjsDYr5+W0CkrRbW9pQnsHPycVPLB5H8k5WVRRNkxYBBoWIBAwyw== dependencies: emittery "^1.0.3" nostr-tools "2.9.4"