Skip to content

Commit ae44bcd

Browse files
committed
fix: codderrabit comments fixed - added unwatch for wallet and try catch for etger signer
1 parent ba4f99b commit ae44bcd

File tree

5 files changed

+25
-13
lines changed

5 files changed

+25
-13
lines changed

packages/create-invoice-form/src/lib/create-invoice-form.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
}
8585
8686
$: {
87-
formData.creatorId = account?.address as string;
87+
formData.creatorId = (account?.address ?? "") as string;
8888
invoiceTotals = calculateInvoiceTotals(formData.items);
8989
}
9090

packages/create-invoice-form/src/lib/react/CreateInvoiceForm.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from "react";
2+
import { Config as WagmiConfig } from "@wagmi/core";
23
import type { IConfig } from "@requestnetwork/shared-types";
34
import type { RequestNetwork, Types } from "@requestnetwork/request-client.js";
4-
import { Config as WagmiConfig } from "@wagmi/core";
5+
56
export interface CreateInvoiceFormProps {
67
config: IConfig;
78
wagmiConfig: WagmiConfig;

packages/invoice-dashboard/src/lib/react/InvoiceDashboard.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from "react";
2+
import { Config as WagmiConfig } from "@wagmi/core";
23
import type { IConfig } from "@requestnetwork/shared-types";
34
import type { WalletState } from "@requestnetwork/shared-types/web3Onboard";
45
import type { RequestNetwork } from "@requestnetwork/request-client.js";
56
import { Currency } from "../types";
6-
import { Config as WagmiConfig } from "wagmi";
77

88
export interface InvoiceDashboardProps {
99
config: IConfig;

packages/invoice-dashboard/src/lib/view-requests.svelte

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
55
<script lang="ts">
66
import { getAccount, watchAccount } from "@wagmi/core";
7-
import type { Config as WagmiConfig } from "wagmi";
87
// Components
98
import Copy from "@requestnetwork/shared-components/copy.svelte";
109
import Dropdown from "@requestnetwork/shared-components/dropdown.svelte";
@@ -22,7 +21,11 @@
2221
import Download from "@requestnetwork/shared-icons/download.svelte";
2322
import Search from "@requestnetwork/shared-icons/search.svelte";
2423
// Types
25-
import type { GetAccountReturnType } from "@wagmi/core";
24+
import type {
25+
GetAccountReturnType,
26+
Config as WagmiConfig,
27+
WatchAccountReturnType,
28+
} from "@wagmi/core";
2629
import { Types } from "@requestnetwork/request-client.js";
2730
import type { IConfig } from "@requestnetwork/shared-types";
2831
import type { RequestNetwork } from "@requestnetwork/request-client.js";
@@ -32,7 +35,7 @@
3235
import { exportToPDF } from "@requestnetwork/shared-utils/generateInvoice";
3336
import { getCurrencyFromManager } from "@requestnetwork/shared-utils/getCurrency";
3437
import { CurrencyManager } from "@requestnetwork/currency";
35-
import { onMount, tick } from "svelte";
38+
import { onDestroy, onMount, tick } from "svelte";
3639
import { formatUnits } from "viem";
3740
import { capitalize, debounce, formatAddress } from "../utils";
3841
import { Drawer, InvoiceView } from "./dashboard";
@@ -90,12 +93,13 @@
9093
}
9194
}
9295
93-
$: {
94-
watchAccount(wagmiConfig, {
96+
let unwatchAccount: WatchAccountReturnType | undefined;
97+
98+
onMount(() => {
99+
unwatchAccount = watchAccount(wagmiConfig, {
95100
onChange(data) {
96101
if (data?.address !== account?.address) {
97102
account = data;
98-
99103
if (account?.address) {
100104
getRequests();
101105
} else {
@@ -107,7 +111,11 @@
107111
}
108112
},
109113
});
110-
}
114+
});
115+
116+
onDestroy(() => {
117+
if (unwatchAccount) unwatchAccount();
118+
});
111119
112120
$: {
113121
signer = account?.address;

packages/invoice-dashboard/src/utils/wallet-utils.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ export async function getEthersSigner(
2929
config: Config,
3030
{ chainId }: { chainId?: number } = {}
3131
) {
32-
const client = await getConnectorClient(config, { chainId });
33-
34-
return clientToSigner(client);
32+
try {
33+
const client = await getConnectorClient(config, { chainId });
34+
return clientToSigner(client);
35+
} catch (e) {
36+
console.log("Failed to obtain client from getConnectorClient");
37+
}
3538
}

0 commit comments

Comments
 (0)