Skip to content
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

Fix native position filter [WLT-4174] #417

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/ui/shared/requests/useNativeBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getDecimals } from 'src/modules/networks/asset';
import { useAddressPositions } from 'defi-sdk';
import { isTruthy } from 'is-truthy-ts';
import { useNetworks } from 'src/modules/networks/useNetworks';
import { invariant } from 'src/shared/invariant';
import { useEvmNativeAddressPosition } from './useEvmNativeAddressPosition';
import { useNativeAssetId } from './useNativeAsset';

Expand All @@ -19,6 +20,7 @@ function useNativeAddressPosition({
enabled?: boolean;
}) {
const id = useNativeAssetId(chain);

const { value, isLoading } = useAddressPositions(
{
address,
Expand All @@ -29,10 +31,18 @@ function useNativeAddressPosition({
);

return useMemo(() => {
const nativePositions =
value?.positions?.filter(
(item) =>
item.chain === chain.toString() &&
item.type === 'asset' &&
!item.protocol
) ?? [];
if (nativePositions.length > 1) {
console.warn('multiple native positions');
}
return {
data: value?.positions?.find(
(item) => item.chain === chain.toString() && item.type === 'asset'
),
data: nativePositions[0],
isLoading,
};
}, [chain, isLoading, value?.positions]);
Expand Down
Loading