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 2 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
14 changes: 11 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,16 @@ function useNativeAddressPosition({
);

return useMemo(() => {
const nativePositions =
value?.positions?.filter(
(item) =>
item.chain === chain.toString() &&
item.type === 'asset' &&
!item.protocol
) ?? [];
invariant(nativePositions.length <= 1, 'multiple native positions');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I don't understand why we want to crash here. Let's assume backend sends an extra position by mistake. Does this prevent us from signing a transaction?

Copy link
Contributor Author

@vyorkin vyorkin Feb 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, you're right. Replaced invariant error with console.warn ✅

return {
data: value?.positions?.find(
(item) => item.chain === chain.toString() && item.type === 'asset'
),
data: nativePositions[0],
isLoading,
};
}, [chain, isLoading, value?.positions]);
Expand Down
Loading