Skip to content

Commit 5b965d4

Browse files
committed
chore: check null conditions in poolSelectors
1 parent cf58cab commit 5b965d4

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

src/store/poolSelectors.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,38 @@ export const selectCurrentChainIdV3MarketKey = (state: RootStore): CustomMarket
2323
export const selectCurrentChainIdV2MarketData = (state: RootStore) => {
2424
const v2MarketKey = selectCurrentChainIdV2MarketKey(state);
2525
const marketData = marketsData[v2MarketKey];
26-
return state.data
27-
.get(state.currentChainId)
28-
?.get(marketData.addresses.LENDING_POOL_ADDRESS_PROVIDER);
26+
const v2MarketAddressProvider = marketData
27+
? marketData.addresses.LENDING_POOL_ADDRESS_PROVIDER
28+
: undefined;
29+
const currentChainId = state.currentChainId;
30+
if (v2MarketAddressProvider && currentChainId) {
31+
return state.data.get(state.currentChainId)?.get(v2MarketAddressProvider);
32+
}
33+
return undefined;
2934
};
3035

3136
export const selectCurrentChainIdV3MarketData = (state: RootStore) => {
32-
const v3MarketKey = selectCurrentChainIdV3MarketKey(state);
37+
const v3MarketKey = selectCurrentChainIdV2MarketKey(state);
3338
const marketData = marketsData[v3MarketKey];
34-
return state.data
35-
.get(state.currentChainId)
36-
?.get(marketData.addresses.LENDING_POOL_ADDRESS_PROVIDER);
39+
const v3MarketAddressProvider = marketData
40+
? marketData.addresses.LENDING_POOL_ADDRESS_PROVIDER
41+
: undefined;
42+
const currentChainId = state.currentChainId;
43+
if (v3MarketAddressProvider && currentChainId) {
44+
return state.data.get(state.currentChainId)?.get(v3MarketAddressProvider);
45+
}
46+
return undefined;
3747
};
3848

3949
export const selectCurrentUserLendingPoolData = (state: RootStore) => {
40-
return state.data
41-
.get(state.currentChainId)
42-
?.get(state.currentMarketData.addresses.LENDING_POOL_ADDRESS_PROVIDER);
50+
const marketAddressProvider = state.currentMarketData
51+
? state.currentMarketData.addresses.LENDING_POOL_ADDRESS_PROVIDER
52+
: undefined;
53+
const currentChainId = state.currentChainId;
54+
if (marketAddressProvider && currentChainId) {
55+
return state.data.get(state.currentChainId)?.get(marketAddressProvider);
56+
}
57+
return undefined;
4358
};
4459

4560
export const selectFormatUserEmodeCategoryId = (reserve?: PoolReserve) => {

0 commit comments

Comments
 (0)