Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions packages/invoice-dashboard/src/lib/view-requests.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
})
| undefined;
let currencyManager: CurrencyManager;
let previousWalletAddress: string | undefined;
let previousNetwork: string | undefined;
let columns = {
issuedAt: false,
Expand All @@ -82,44 +84,41 @@
});
const getRequests = async () => {
try {
loading = true;
if (!wallet || !requestNetwork) return;
loading = true;
try {
const requestsData = await requestNetwork?.fromIdentity({
type: Types.Identity.TYPE.ETHEREUM_ADDRESS,
value: signer,
value: wallet?.accounts[0]?.address,
});
requests = requestsData
?.map((request) => request.getData())
.sort((a, b) => b.timestamp - a.timestamp);
loading = false;
} catch (error) {
loading = false;
console.error("Failed to fetch requests:", error);
} finally {
loading = false;
}
};
const getOneRequest = async (activeRequest: any) => {
try {
if (!activeRequest) return;
loading = true;
const _request = await requestNetwork?.fromRequestId(
activeRequest?.requestId!
);
requests = requests?.filter(
(request) => request.requestId !== activeRequest.requestId
);
requests = [...requests, _request.getData()].sort(
(a, b) => b.timestamp - a.timestamp
);
loading = false;
} catch (error) {
loading = false;
console.error("Failed to fetch request:", error);
} finally {
loading = false;
}
};
Expand All @@ -133,8 +132,24 @@
let currentPage = 1;
let totalPages = 1;
$: wallet, getRequests();
$: wallet, (activeRequest = undefined);
$: {
const currentWalletAddress = wallet?.accounts[0]?.address;
const currentNetwork = wallet?.chains[0]?.id;
if (
currentWalletAddress &&
currentWalletAddress !== previousWalletAddress
) {
getRequests();
previousWalletAddress = currentWalletAddress;
activeRequest = undefined;
}
if (currentNetwork && currentNetwork !== previousNetwork) {
previousNetwork = currentNetwork;
}
}
Comment on lines +136 to +153
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the impact of having both the currentWalletAddress and currentNetwork logic in the same reactive statement $:?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, we are using it only there, so I thought we didn't need it outside this reactive statement.

$: {
if (sortColumn && sortOrder) {
Expand Down
6 changes: 6 additions & 0 deletions packages/invoice-dashboard/src/types/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
declare interface Window {
ethereum: {
on: (event: string, callback: (accounts: string[]) => void) => void;
removeListener: (
event: string,
callback: (accounts: string[]) => void
) => void;
request: (request: { method: string }) => Promise<void>;
autoRefreshOnNetworkChange: boolean;
};
}
11 changes: 10 additions & 1 deletion shared/components/button/button.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,25 @@
let className: $$Props["class"] = undefined;
export let builders: $$Props["builders"] = [];
export { className as class };
export let onClick: (event: MouseEvent) => void = () => {};
export let preventDefault: boolean = true;

$: classes = ["rn-btn", className].filter(Boolean).join(" ");

function handleClick(event: MouseEvent) {
if (preventDefault) {
event.preventDefault();
}
onClick(event);
}
</script>

<ButtonPrimitive.Root
{builders}
class={classes}
type="button"
{...$$restProps}
on:click
on:click={handleClick}
on:keydown
>
<slot />
Expand Down