Closed sstefdev closed 2 months ago
The changes involve enhancements to the view-requests.svelte
component for improved handling of wallet address and network changes, as well as updates to the global.d.ts
file for Ethereum functionality. Additionally, the button.svelte
component is modified to allow more flexible click event handling. New variables and methods are introduced to optimize performance and usability in managing requests and event listeners.
File | Change Summary |
---|---|
packages/invoice-dashboard/src/lib/view-requests.svelte |
Introduced previousWalletAddress and previousNetwork to optimize fetching requests based on wallet state changes. Modified getRequests for better error handling and conditional execution. Updated reactive statements for performance. |
packages/invoice-dashboard/src/types/global.d.ts |
Enhanced Window interface with on and removeListener methods for event handling, and added autoRefreshOnNetworkChange property to manage network change behavior. |
shared/components/button/button.svelte |
Added onClick and preventDefault properties for flexible click event handling. Encapsulated click logic in handleClick function to manage default actions and custom behavior. |
Objective | Addressed | Explanation |
---|---|---|
Prevent dashboard reload on "Switch Chain" button (Issue #95) | ❌ | The changes do not address the dashboard reload issue directly. |
view-requests.svelte
related to handling request data and the introduction of the isRequestPayed
variable.view-requests.svelte
, relevant to managing requests and associated data.view-requests.svelte
regarding the handling of request statuses, related to optimizing request fetching logic.packages/invoice-dashboard/src/lib/view-requests.svelte (4)
`61-62`: **LGTM!** The addition of `previousWalletAddress` and `previousNetwork` variables is a good optimization. It allows the component to track the last known wallet address and network, preventing unnecessary network calls when the address remains the same. This enhances the component's responsiveness to changes in the wallet state. --- `87-102`: **Great improvements to the `getRequests` function!** The addition of the check for `wallet` and `requestNetwork` before executing the request fetching logic is a good safety measure. It ensures that requests are only made when the necessary data is available, preventing potential errors. Furthermore, the use of the `finally` block to reset the loading state improves the code's readability and reliability. It guarantees that the loading state is always reset, regardless of whether an error occurs during the request fetching process. These changes enhance the robustness and user experience of the component. --- `106-124`: **Nice update to the `getOneRequest` function!** The addition of the check for `activeRequest` before executing the logic is a good practice. It prevents unnecessary function execution when there is no active request to fetch. Moreover, the use of the `finally` block to reset the loading state, similar to the `getRequests` function, improves code consistency and reliability. It ensures that the loading state is always reset, regardless of any errors that may occur during the process. These changes contribute to a more robust and user-friendly component. --- `136-153`: **Excellent refinement of the reactive statement!** Comparing the current wallet address and network against their previous values is a smart approach to detect changes in the wallet state. This allows the component to invoke the `getRequests` function only when necessary, i.e., when either the wallet address or network has changed. This optimization enhances the component's performance by minimizing redundant network requests. It ensures that the component fetches requests only when there is a actual change in the wallet state, reducing unnecessary network overhead. Furthermore, updating the previous wallet address and network after the comparison maintains an accurate record of the last known values. This ensures consistency in detecting future changes. Overall, these changes significantly improve the component's responsiveness and efficiency in handling wallet state changes.
Fixes #95
Problem
When someone tries to use the button Switch Network or even switch network from their wallet, that triggers a refetch of the whole table and gives impression of page reloading
Solution
preventDefault
to the button just in casewindow.ethereum
functions to the types fileSummary by CodeRabbit
Summary by CodeRabbit
New Features
Bug Fixes
Documentation