From 3bf305481cbf1514edf3cb839dd3dcae22723dcc Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Wed, 12 Jul 2023 17:20:01 +0530 Subject: [PATCH 01/17] feat: lightning address buttton add lightning address button in receive screen fetch lightning address and write to clipboard handle edge cases - if lightning address unavailable add translations add loading states signed-off-by: pavan joshi --- src/app/screens/Receive/index.tsx | 64 +++++++++++++++++++++++----- src/common/lib/api.ts | 2 +- src/i18n/locales/en/translation.json | 6 ++- 3 files changed, 58 insertions(+), 14 deletions(-) diff --git a/src/app/screens/Receive/index.tsx b/src/app/screens/Receive/index.tsx index 9338e459a3..6db585dd2d 100644 --- a/src/app/screens/Receive/index.tsx +++ b/src/app/screens/Receive/index.tsx @@ -41,19 +41,23 @@ function Receive() { description: "", expiration: "", }); - const [loading, setLoading] = useState(false); + const [loadingInvoice, setLoadingInvoice] = useState(false); + const [loadingLightningAddress, setLoadingLightningAddress] = useState(false); const [invoice, setInvoice] = useState<{ paymentRequest: string; rHash: string; } | null>(); - const [copyLabel, setCopyLabel] = useState( + const [copyInvoiceLabel, setCopyInvoiceLabel] = useState( tCommon("actions.copy_invoice") as string ); + const [copyLightningAddressLabel, setCopyLightningAddressLabel] = useState( + t("actions.copy_lightning_address") as string + ); const [paid, setPaid] = useState(false); const [pollingForPayment, setPollingForPayment] = useState(false); const mounted = useRef(false); const isAlbyUser = - isAlbyOAuthAccount(auth.account?.alias) || + isAlbyOAuthAccount(auth.account?.connectorType) || isAlbyLNDHubAccount(auth.account?.alias, auth.account?.connectorType); useEffect(() => { @@ -119,7 +123,7 @@ function Receive() { async function createInvoice() { try { - setLoading(true); + setLoadingInvoice(true); const response = await api.makeInvoice({ amount: formData.amount, memo: formData.description, @@ -131,7 +135,7 @@ function Receive() { toast.error(e.message); } } finally { - setLoading(false); + setLoadingInvoice(false); } } @@ -140,6 +144,14 @@ function Receive() { createInvoice(); } + async function getLightningAddress() { + setLoadingLightningAddress(true); + const response = await api.getAccountInfo(); + const lightningAddress = response.info.lightning_address; + setLoadingLightningAddress(false); + return lightningAddress; + } + function renderInvoice() { if (!invoice) return null; return ( @@ -178,9 +190,9 @@ function Receive() { onClick={async () => { try { navigator.clipboard.writeText(invoice.paymentRequest); - setCopyLabel(tCommon("copied")); + setCopyInvoiceLabel(tCommon("copied")); setTimeout(() => { - setCopyLabel(tCommon("actions.copy_invoice")); + setCopyInvoiceLabel(tCommon("actions.copy_invoice")); }, 1000); } catch (e) { if (e instanceof Error) { @@ -189,7 +201,7 @@ function Receive() { } }} icon={} - label={copyLabel} + label={copyInvoiceLabel} /> @@ -243,7 +255,7 @@ function Receive() { ) : (
-
+
@@ -273,8 +285,8 @@ function Receive() { label={t("actions.create_invoice")} fullWidth primary - loading={loading} - disabled={loading} + loading={loadingInvoice} + disabled={loadingInvoice} />
@@ -291,6 +303,36 @@ function Receive() {
+
+
+
From b899c236b4118450f82ec207aebef6eaa47652f4 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Wed, 12 Jul 2023 18:28:09 +0530 Subject: [PATCH 03/17] feat: fix tests signed-off-by: pavan joshi --- src/app/screens/Receive/index.test.tsx | 3 +++ src/app/screens/Receive/index.tsx | 1 + 2 files changed, 4 insertions(+) diff --git a/src/app/screens/Receive/index.test.tsx b/src/app/screens/Receive/index.test.tsx index 85086d516f..ee0ac75f7d 100644 --- a/src/app/screens/Receive/index.test.tsx +++ b/src/app/screens/Receive/index.test.tsx @@ -14,6 +14,9 @@ jest.mock("~/common/lib/api", () => { getSettings: jest.fn(() => Promise.resolve(mockSettings)), getCurrencyRate: jest.fn(() => Promise.resolve({ rate: 11 })), makeInvoice: jest.fn(), + getAccountInfo: jest.fn(() => + Promise.resolve({ info: { lightning_address: "hello@getalby.com" } }) + ), }; }); diff --git a/src/app/screens/Receive/index.tsx b/src/app/screens/Receive/index.tsx index d749c84e76..723cbe60ea 100644 --- a/src/app/screens/Receive/index.tsx +++ b/src/app/screens/Receive/index.tsx @@ -153,6 +153,7 @@ function Receive() { useEffect(() => { getLightningAddress(); }, []); + function renderInvoice() { if (!invoice) return null; return ( From 4248e3ffa863552949223c070a3abb4a69c8a9e6 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Wed, 12 Jul 2023 18:29:43 +0530 Subject: [PATCH 04/17] chore: remove get lightning address message, as every account will have ln address signed-off-by: Pavan Joshi --- src/app/screens/Receive/index.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/app/screens/Receive/index.tsx b/src/app/screens/Receive/index.tsx index 723cbe60ea..e58cb2fc61 100644 --- a/src/app/screens/Receive/index.tsx +++ b/src/app/screens/Receive/index.tsx @@ -320,8 +320,6 @@ function Receive() { t("actions.copy_lightning_address") ); }, 1000); - } else { - toast.info(t("get_lightning_address")); } } catch (e) { if (e instanceof Error) { From d111e094b32ab0e3f97cb472c7fbf831c8b2b0d7 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Thu, 13 Jul 2023 08:37:38 +0530 Subject: [PATCH 05/17] fix: remove unused translation --- src/i18n/locales/en/translation.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/i18n/locales/en/translation.json b/src/i18n/locales/en/translation.json index dbba65b006..342991ceda 100644 --- a/src/i18n/locales/en/translation.json +++ b/src/i18n/locales/en/translation.json @@ -689,8 +689,7 @@ "waiting": "waiting for payment...", "status": "Check payment status" }, - "receive_via_bitcoin_address": "Receive via bitcoin address", - "get_lightning_address": "Get your lightning address at https://getalby.com/user" + "receive_via_bitcoin_address": "Receive via bitcoin address" }, "on_chain": { "title": "Receive via bitcoin address", From 206917ab57c613972ed354af532421482dee7205 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Fri, 14 Jul 2023 12:38:33 +0530 Subject: [PATCH 06/17] chore: disable button till account is loaded signed-off-by: Pavan Joshi --- src/app/screens/Receive/index.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/app/screens/Receive/index.tsx b/src/app/screens/Receive/index.tsx index e58cb2fc61..7be96cbfbd 100644 --- a/src/app/screens/Receive/index.tsx +++ b/src/app/screens/Receive/index.tsx @@ -42,6 +42,7 @@ function Receive() { expiration: "", }); const [loadingInvoice, setLoadingInvoice] = useState(false); + const [loadingLightningAddress, setLoadingLightningAddress] = useState(false); const [invoice, setInvoice] = useState<{ paymentRequest: string; rHash: string; @@ -145,9 +146,11 @@ function Receive() { } async function getLightningAddress() { + setLoadingLightningAddress(true); const response = await api.getAccountInfo(); const lightningAddress = response.info.lightning_address; if (lightningAddress) setLightningAddress(lightningAddress); + setLoadingLightningAddress(false); } useEffect(() => { @@ -309,6 +312,7 @@ function Receive() {
-
-
-
+
+
+
-
+