|  | 
| 58 | 58 |       }) | 
| 59 | 59 |     | undefined; | 
| 60 | 60 |   let currencyManager: CurrencyManager; | 
|  | 61 | +  let previousWalletAddress: string | undefined; | 
|  | 62 | +  let previousNetwork: string | undefined; | 
| 61 | 63 | 
 | 
| 62 | 64 |   let columns = { | 
| 63 | 65 |     issuedAt: false, | 
|  | 
| 82 | 84 |   }); | 
| 83 | 85 | 
 | 
| 84 | 86 |   const getRequests = async () => { | 
| 85 |  | -    try { | 
| 86 |  | -      loading = true; | 
|  | 87 | +    if (!wallet || !requestNetwork) return; | 
|  | 88 | +    loading = true; | 
| 87 | 89 | 
 | 
|  | 90 | +    try { | 
| 88 | 91 |       const requestsData = await requestNetwork?.fromIdentity({ | 
| 89 | 92 |         type: Types.Identity.TYPE.ETHEREUM_ADDRESS, | 
| 90 |  | -        value: signer, | 
|  | 93 | +        value: wallet?.accounts[0]?.address, | 
| 91 | 94 |       }); | 
| 92 |  | -
 | 
| 93 | 95 |       requests = requestsData | 
| 94 | 96 |         ?.map((request) => request.getData()) | 
| 95 | 97 |         .sort((a, b) => b.timestamp - a.timestamp); | 
| 96 |  | -
 | 
| 97 |  | -      loading = false; | 
| 98 | 98 |     } catch (error) { | 
| 99 |  | -      loading = false; | 
| 100 | 99 |       console.error("Failed to fetch requests:", error); | 
|  | 100 | +    } finally { | 
|  | 101 | +      loading = false; | 
| 101 | 102 |     } | 
| 102 | 103 |   }; | 
| 103 | 104 | 
 | 
| 104 | 105 |   const getOneRequest = async (activeRequest: any) => { | 
| 105 |  | -    try { | 
| 106 |  | -      loading = true; | 
|  | 106 | +    if (!activeRequest) return; | 
|  | 107 | +    loading = true; | 
| 107 | 108 | 
 | 
|  | 109 | +    try { | 
| 108 | 110 |       const _request = await requestNetwork?.fromRequestId( | 
| 109 | 111 |         activeRequest?.requestId! | 
| 110 | 112 |       ); | 
| 111 |  | -
 | 
| 112 | 113 |       requests = requests?.filter( | 
| 113 | 114 |         (request) => request.requestId !== activeRequest.requestId | 
| 114 | 115 |       ); | 
| 115 | 116 |       requests = [...requests, _request.getData()].sort( | 
| 116 | 117 |         (a, b) => b.timestamp - a.timestamp | 
| 117 | 118 |       ); | 
| 118 |  | -
 | 
| 119 |  | -      loading = false; | 
| 120 | 119 |     } catch (error) { | 
| 121 |  | -      loading = false; | 
| 122 | 120 |       console.error("Failed to fetch request:", error); | 
|  | 121 | +    } finally { | 
|  | 122 | +      loading = false; | 
| 123 | 123 |     } | 
| 124 | 124 |   }; | 
| 125 | 125 | 
 | 
|  | 
| 133 | 133 |   let currentPage = 1; | 
| 134 | 134 |   let totalPages = 1; | 
| 135 | 135 | 
 | 
| 136 |  | -  $: wallet, getRequests(); | 
| 137 |  | -  $: wallet, (activeRequest = undefined); | 
|  | 136 | +  $: { | 
|  | 137 | +    const currentWalletAddress = wallet?.accounts[0]?.address; | 
|  | 138 | +    const currentNetwork = wallet?.chains[0]?.id; | 
|  | 139 | +
 | 
|  | 140 | +    if ( | 
|  | 141 | +      currentWalletAddress && | 
|  | 142 | +      currentWalletAddress !== previousWalletAddress | 
|  | 143 | +    ) { | 
|  | 144 | +      getRequests(); | 
|  | 145 | +      previousWalletAddress = currentWalletAddress; | 
|  | 146 | +
 | 
|  | 147 | +      activeRequest = undefined; | 
|  | 148 | +    } | 
|  | 149 | +
 | 
|  | 150 | +    if (currentNetwork && currentNetwork !== previousNetwork) { | 
|  | 151 | +      previousNetwork = currentNetwork; | 
|  | 152 | +    } | 
|  | 153 | +  } | 
| 138 | 154 | 
 | 
| 139 | 155 |   $: { | 
| 140 | 156 |     if (sortColumn && sortOrder) { | 
|  | 
0 commit comments