@@ -134,29 +134,53 @@ export function useV3Positions(
134134) : UseV3PositionsResults {
135135 const positionV2Manager = useV3NFTPositionManagerContract ( ) ;
136136 const positionV4Manager = useV4NFTPositionManagerContract ( ) ;
137- const positionManager = isV4 ? positionV4Manager : positionV2Manager ;
138137 const uniV3PositionManager = useUNIV3NFTPositionManagerContract ( ) ;
139138
140- const algebraBalanceResult = useSingleCallResult (
141- positionManager ,
139+ const algebraV2BalanceResult = useSingleCallResult (
140+ positionV2Manager ,
142141 'balanceOf' ,
143142 [ account ?? undefined ] ,
144143 ) ;
145144
146- const algebraBalance = Number ( algebraBalanceResult . result ?? '0' ) ;
145+ const algebraV4BalanceResult = useSingleCallResult (
146+ positionV4Manager ,
147+ 'balanceOf' ,
148+ [ account ?? undefined ] ,
149+ ) ;
150+
151+ const algebraV2Balance = Number ( algebraV2BalanceResult . result ?? '0' ) ;
152+ const algebraV4Balance = Number ( algebraV4BalanceResult . result ?? '0' ) ;
153+
154+ const algebraV2TokenResults = useSingleContractMultipleData (
155+ positionV2Manager ,
156+ 'tokenOfOwnerByIndex' ,
157+ Array . from ( { length : algebraV2Balance } , ( _ , i ) => i ) . map ( ( v ) => [
158+ account ?? undefined ,
159+ v ,
160+ ] ) ,
161+ ) ;
147162
148- const algebraTokenResults = useSingleContractMultipleData (
149- positionManager ,
163+ const algebraV4TokenResults = useSingleContractMultipleData (
164+ positionV4Manager ,
150165 'tokenOfOwnerByIndex' ,
151- Array . from ( { length : algebraBalance } , ( _ , i ) => i ) . map ( ( v ) => [
166+ Array . from ( { length : algebraV4Balance } , ( _ , i ) => i ) . map ( ( v ) => [
152167 account ?? undefined ,
153168 v ,
154169 ] ) ,
155170 ) ;
156171
157- const algebraIDsLoading = algebraTokenResults . some ( ( call ) => call . loading ) ;
172+ const algebraV2IDsLoading = algebraV2TokenResults . some (
173+ ( call ) => call . loading ,
174+ ) ;
175+ const algebraV4IDsLoading = algebraV4TokenResults . some (
176+ ( call ) => call . loading ,
177+ ) ;
158178
159- const algebraTokenIds = algebraTokenResults
179+ const algebraV2TokenIds = algebraV2TokenResults
180+ . filter ( ( call ) => ! ! call . result )
181+ . map ( ( call ) => BigNumber . from ( call . result ?. toString ( ) ?? '0' ) ) ;
182+
183+ const algebraV4TokenIds = algebraV4TokenResults
160184 . filter ( ( call ) => ! ! call . result )
161185 . map ( ( call ) => BigNumber . from ( call . result ?. toString ( ) ?? '0' ) ) ;
162186
@@ -184,12 +208,21 @@ export function useV3Positions(
184208 . map ( ( call ) => BigNumber . from ( call . result ?. toString ( ) ?? '0' ) ) ;
185209
186210 const {
187- positions : algebraPositions ,
188- loading : algebraPositionsLoading ,
211+ positions : algebraV2Positions ,
212+ loading : algebraV2PositionsLoading ,
189213 } = useV3PositionsFromTokenIds (
190- algebraIDsLoading ? [ ] : algebraTokenIds ,
214+ algebraV2IDsLoading ? [ ] : algebraV2TokenIds ,
215+ false ,
191216 false ,
192- isV4 ,
217+ ) ;
218+
219+ const {
220+ positions : algebraV4Positions ,
221+ loading : algebraV4PositionsLoading ,
222+ } = useV3PositionsFromTokenIds (
223+ algebraV4IDsLoading ? [ ] : algebraV4TokenIds ,
224+ false ,
225+ true ,
193226 ) ;
194227
195228 const {
@@ -229,6 +262,12 @@ export function useV3Positions(
229262 oldTransferredTokenIds . map ( ( id ) => BigNumber . from ( id ) ) ,
230263 ) ;
231264
265+ const algebraPositions = isV4
266+ ? algebraV4Positions
267+ : isV4 === undefined
268+ ? ( algebraV2Positions ?? [ ] ) . concat ( algebraV4Positions ?? [ ] )
269+ : algebraV2Positions ;
270+
232271 const combinedPositions = [
233272 ...( algebraPositions ?? [ ] )
234273 . concat ( isV4 ? [ ] : uniV3Positions ?? [ ] )
@@ -260,9 +299,11 @@ export function useV3Positions(
260299
261300 return {
262301 loading :
263- algebraPositionsLoading ||
302+ algebraV2PositionsLoading ||
303+ algebraV4PositionsLoading ||
264304 uniV3PositionsLoading ||
265- algebraIDsLoading ||
305+ algebraV2IDsLoading ||
306+ algebraV4IDsLoading ||
266307 univ3IDsLoading ||
267308 _positionsOnFarmerLoading ,
268309 positions : combinedPositions ,
0 commit comments