-
Notifications
You must be signed in to change notification settings - Fork 9
On changing network, causes to the dashboard to refetch data #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,6 +58,8 @@ | |
| }) | ||
| | undefined; | ||
| let currencyManager: CurrencyManager; | ||
| let previousWalletAddress: string | undefined; | ||
| let previousNetwork: string | undefined; | ||
| let columns = { | ||
| issuedAt: false, | ||
|
|
@@ -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; | ||
| } | ||
| }; | ||
|
|
@@ -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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
|
||
| 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; | ||
| }; | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.