Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions app/components/UI/Predict/controllers/PredictController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1595,8 +1595,14 @@ export class PredictController extends BaseController<

const signer = this.getSigner();

// Get claimable positions from state
const claimablePositions = this.state.claimablePositions[signer.address];
// Get claimable positions from state (case-insensitive address match)
const normalizedSignerAddress = signer.address.toLowerCase();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we create a utils function for this logic? This function can be shared for the controller and the selector.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed 1e36186

const matchedAddress = Object.keys(this.state.claimablePositions).find(
(addressKey) => addressKey.toLowerCase() === normalizedSignerAddress,
);
const claimablePositions = matchedAddress
? this.state.claimablePositions[matchedAddress]
: undefined;

if (!claimablePositions || claimablePositions.length === 0) {
throw new Error('No claimable positions found');
Expand Down
11 changes: 7 additions & 4 deletions app/components/UI/Predict/selectors/predictController/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ const selectPredictClaimablePositionsByAddress = ({
}: {
address: string;
}) =>
createSelector(
selectPredictClaimablePositions,
(claimablePositions) => claimablePositions[address] || [],
);
createSelector(selectPredictClaimablePositions, (claimablePositions) => {
const normalizedAddress = address.toLowerCase();
const matchedKey = Object.keys(claimablePositions).find(
(key) => key.toLowerCase() === normalizedAddress,
);
return matchedKey ? claimablePositions[matchedKey] : [];
});
Comment thread
vinnyhoward marked this conversation as resolved.

const selectPredictWonPositions = ({ address }: { address: string }) =>
createSelector(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, {
useCallback,
useImperativeHandle,
useRef,
useState,
} from 'react';
import { ScrollView } from 'react-native';
import { useNavigation, NavigationProp } from '@react-navigation/native';
Expand Down Expand Up @@ -91,9 +92,16 @@ const PredictionsSection = forwardRef<SectionRefreshHandle>((_, ref) => {
refresh: refreshClaimable,
} = usePredictPositionsForHomepage(undefined, true);

const [isClaiming, setIsClaiming] = useState(false);

const handleClaim = useCallback(async () => {
await claim();
await refreshClaimable();
setIsClaiming(true);
try {
await claim();
await refreshClaimable();
} finally {
setIsClaiming(false);
}
}, [claim, refreshClaimable]);

const totalClaimable = claimablePositions.reduce(
Expand Down Expand Up @@ -170,8 +178,12 @@ const PredictionsSection = forwardRef<SectionRefreshHandle>((_, ref) => {
);
}

// Render positions if user has any
if (hasPositions || isLoadingPositions) {
// Render positions if user has active positions, or claimable winnings
if (
hasPositions ||
isLoadingPositions ||
(!isLoadingClaimable && totalClaimable > 0)
) {
return (
<Box gap={3}>
<SectionTitle title={title} onPress={handleViewAllPredictions} />
Expand All @@ -190,14 +202,17 @@ const PredictionsSection = forwardRef<SectionRefreshHandle>((_, ref) => {
/>
))
)}
{!isLoadingPositions && !isLoadingClaimable && totalClaimable > 0 && (
<Box paddingHorizontal={4} paddingTop={1} paddingBottom={3}>
<PredictClaimButton
amount={totalClaimable}
onPress={handleClaim}
/>
</Box>
)}
{!isLoadingPositions &&
!isLoadingClaimable &&
!isClaiming &&
totalClaimable > 0 && (
<Box paddingHorizontal={4} paddingTop={1} paddingBottom={3}>
<PredictClaimButton
amount={totalClaimable}
onPress={handleClaim}
/>
</Box>
)}
</Box>
</Box>
);
Expand Down
Loading