diff --git a/components/ToastConfig.tsx b/components/ToastConfig.tsx
index d68ade5..cd4b8a7 100644
--- a/components/ToastConfig.tsx
+++ b/components/ToastConfig.tsx
@@ -13,20 +13,16 @@ export const toastConfig: ToastConfig = {
{text1}
- {text2 &&
- {text2}
- }
+ {text2 && {text2}}
),
error: ({ text1, text2, hide }) => (
-
+
{text1}
- {text2 &&
- {text2}
- }
+ {text2 && {text2}}
),
connectionError: ({ text1, text2, hide }) => {
diff --git a/hooks/useBalance.ts b/hooks/useBalance.ts
index b643f4b..90fa221 100644
--- a/hooks/useBalance.ts
+++ b/hooks/useBalance.ts
@@ -1,13 +1,20 @@
import { useAppStore } from "lib/state/appStore";
import useSWR from "swr";
+import { errorToast } from "~/lib/errorToast";
type FetchArgs = Parameters;
-const fetcher = (...args: FetchArgs) => {
+const fetcher = async (...args: FetchArgs) => {
const nwcClient = useAppStore.getState().nwcClient;
if (!nwcClient) {
throw new Error("No NWC client");
}
- return nwcClient.getBalance();
+ try {
+ const balance = await nwcClient.getBalance();
+ return balance;
+ } catch (error) {
+ errorToast(error);
+ throw error;
+ }
};
export function useBalance() {
diff --git a/hooks/useInfo.ts b/hooks/useInfo.ts
index db89bd3..f62618f 100644
--- a/hooks/useInfo.ts
+++ b/hooks/useInfo.ts
@@ -1,13 +1,20 @@
import { useAppStore } from "lib/state/appStore";
import useSWR from "swr";
+import { errorToast } from "~/lib/errorToast";
type FetchArgs = Parameters;
-const fetcher = (...args: FetchArgs) => {
+const fetcher = async (...args: FetchArgs) => {
const nwcClient = useAppStore.getState().nwcClient;
if (!nwcClient) {
throw new Error("No NWC client");
}
- return nwcClient.getInfo();
+ try {
+ const info = await nwcClient.getInfo();
+ return info;
+ } catch (error) {
+ errorToast(error);
+ throw error;
+ }
};
export function useInfo() {
diff --git a/hooks/useTransactions.ts b/hooks/useTransactions.ts
index 574b15f..993d17e 100644
--- a/hooks/useTransactions.ts
+++ b/hooks/useTransactions.ts
@@ -1,10 +1,11 @@
import { useAppStore } from "lib/state/appStore";
import useSWR from "swr";
import { TRANSACTIONS_PAGE_SIZE } from "~/lib/constants";
+import { errorToast } from "~/lib/errorToast";
type FetchArgs = Parameters;
-const fetcher = (...args: FetchArgs) => {
+const fetcher = async (...args: FetchArgs) => {
const nwcClient = useAppStore.getState().nwcClient;
if (!nwcClient) {
throw new Error("No NWC client");
@@ -13,10 +14,16 @@ const fetcher = (...args: FetchArgs) => {
const transactionsUrl = new URL("http://" + (args[0] as string));
const page = +(transactionsUrl.searchParams.get("page") as string);
- return nwcClient.listTransactions({
- limit: TRANSACTIONS_PAGE_SIZE,
- offset: (page - 1) * TRANSACTIONS_PAGE_SIZE,
- });
+ try {
+ const transactions = await nwcClient.listTransactions({
+ limit: TRANSACTIONS_PAGE_SIZE,
+ offset: (page - 1) * TRANSACTIONS_PAGE_SIZE,
+ });
+ return transactions;
+ } catch (error) {
+ errorToast(error);
+ throw error;
+ }
};
export function useTransactions(page = 1) {
diff --git a/lib/errorToast.ts b/lib/errorToast.ts
index f7820c8..d620adc 100644
--- a/lib/errorToast.ts
+++ b/lib/errorToast.ts
@@ -1,8 +1,10 @@
import Toast from "react-native-toast-message";
-export function errorToast(error: Error) {
+export function errorToast(error: Error | unknown) {
Toast.show({
type: "error",
- text1: error.message,
+ text1:
+ (error as Error | undefined)?.message ||
+ "An unknown error occured. Please check your internet connection or try restarting Alby Go",
});
}
diff --git a/lib/swr.ts b/lib/swr.ts
index 20eb19d..ce69b84 100644
--- a/lib/swr.ts
+++ b/lib/swr.ts
@@ -1,5 +1,4 @@
-import { BareFetcher, SWRConfiguration } from "swr";
-import { useAppStore } from "./state/appStore";
+import { SWRConfiguration } from "swr";
// import AsyncStorage from "@react-native-async-storage/async-storage";
export const swrConfiguration: SWRConfiguration = {
diff --git a/pages/receive/Receive.tsx b/pages/receive/Receive.tsx
index 9454d14..66e4b37 100644
--- a/pages/receive/Receive.tsx
+++ b/pages/receive/Receive.tsx
@@ -58,7 +58,7 @@ export function Receive() {
setEnterCustomAmount(false);
} catch (error) {
console.error(error);
- errorToast(error as Error);
+ errorToast(error);
}
setLoading(false);
})();
@@ -100,7 +100,7 @@ export function Receive() {
polling &&
pollCount > 0 &&
receivedTransaction.payment_hash !==
- prevTransaction?.payment_hash
+ prevTransaction?.payment_hash
) {
if (
!invoiceRef.current ||
@@ -169,15 +169,13 @@ export function Receive() {
});
} catch (error) {
console.error("Error sharing:", error);
- errorToast(error as Error);
+ errorToast(error);
}
}
return (
<>
-
+
{!enterCustomAmount && !invoice && !lightningAddress && (
<>
@@ -242,7 +240,11 @@ export function Receive() {
-