| 
1 | 1 | import {  | 
 | 2 | +  ComputedUserReserve,  | 
2 | 3 |   FormattedGhoReserveData,  | 
3 | 4 |   FormattedGhoUserData,  | 
4 | 5 |   formatUserSummaryWithDiscount,  | 
5 | 6 |   USD_DECIMALS,  | 
6 | 7 |   UserReserveData,  | 
7 | 8 | } from '@aave/math-utils';  | 
 | 9 | +import { AaveV3Ethereum } from '@bgd-labs/aave-address-book';  | 
8 | 10 | import { formatUnits } from 'ethers/lib/utils';  | 
9 | 11 | import React, { PropsWithChildren, useContext } from 'react';  | 
10 | 12 | import { EmodeCategory } from 'src/helpers/types';  | 
@@ -140,9 +142,42 @@ export const AppDataProvider: React.FC<PropsWithChildren> = ({ children }) => {  | 
140 | 142 |           formatUnits(baseCurrencyData.marketReferenceCurrencyPriceInUsd, USD_DECIMALS)  | 
141 | 143 |         ),  | 
142 | 144 |       });  | 
 | 145 | + | 
 | 146 | +      const userGhoReserve = user.userReservesData.find(  | 
 | 147 | +        (r) => r.reserve.underlyingAsset === AaveV3Ethereum.ASSETS.GHO.UNDERLYING.toLowerCase()  | 
 | 148 | +      );  | 
 | 149 | + | 
 | 150 | +      if (!userGhoReserve) {  | 
 | 151 | +        throw new Error('GHO reserve not found in user reserves data');  | 
 | 152 | +      }  | 
 | 153 | + | 
 | 154 | +      const mergeUserReserves = (reserve: ComputedUserReserve<FormattedReservesAndIncentives>) => {  | 
 | 155 | +        if (reserve.underlyingAsset !== AaveV3Ethereum.ASSETS.GHO.UNDERLYING.toLowerCase()) {  | 
 | 156 | +          return reserve;  | 
 | 157 | +        }  | 
 | 158 | + | 
 | 159 | +        if (reserve.variableBorrows === '0') {  | 
 | 160 | +          return reserve;  | 
 | 161 | +        }  | 
 | 162 | + | 
 | 163 | +        // This amount takes into account the discount applied on the accrued interest.  | 
 | 164 | +        const userGhoDebtBalance = formattedGhoUserData.userGhoBorrowBalance.toString();  | 
 | 165 | + | 
 | 166 | +        // Merge with the user reserves so the correct debt balance can be shown throughout the app.  | 
 | 167 | +        return {  | 
 | 168 | +          ...reserve,  | 
 | 169 | +          variableBorrows: userGhoDebtBalance,  | 
 | 170 | +          variableBorrowsUSD: userGhoDebtBalance,  | 
 | 171 | +          totalBorrowsUSD: userGhoDebtBalance,  | 
 | 172 | +          totalBorrows: userGhoDebtBalance,  | 
 | 173 | +          totalBorrowsMarketReferenceCurrency: userGhoDebtBalance,  | 
 | 174 | +        };  | 
 | 175 | +      };  | 
 | 176 | + | 
143 | 177 |       user = {  | 
144 | 178 |         ...user,  | 
145 | 179 |         ...userSummaryWithDiscount,  | 
 | 180 | +        userReservesData: user.userReservesData.map(mergeUserReserves),  | 
146 | 181 |       };  | 
147 | 182 |     }  | 
148 | 183 |   }  | 
 | 
0 commit comments