Skip to content
Open
Show file tree
Hide file tree
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
19 changes: 19 additions & 0 deletions components/Card/CardDepositInternalForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import DepositPublicAddress from '@/components/DepositOption/DepositPublicAddress';
import Max from '@/components/Max';
import TierBalanceOutflowNotice from '@/components/TierBalance/TierBalanceOutflowNotice';
import { Button } from '@/components/ui/button';
import {
DropdownMenu,
Expand All @@ -50,6 +51,7 @@
import useDepositFromSolidUsdc from '@/hooks/useDepositFromSolidUsdc';
import { usePreviewDepositToCard } from '@/hooks/usePreviewDepositToCard';
import useSwapAndBridgeToCard from '@/hooks/useSwapAndBridgeToCard';
import { useTierBalanceOutflowWarning } from '@/hooks/useTierBalance';
import useUser from '@/hooks/useUser';
import { track } from '@/lib/analytics';
import { getAsset } from '@/lib/assets';
Expand Down Expand Up @@ -77,7 +79,7 @@
getCardDepositTokenSymbol,
getCardFundingAddress,
} from '@/lib/utils';
import { getChain } from '@/lib/wagmi';

Check warning on line 82 in components/Card/CardDepositInternalForm.tsx

View workflow job for this annotation

GitHub Actions / lint

'getChain' is defined but never used. Allowed unused vars must match /^_/u
import { CardDepositSource, useCardDepositStore } from '@/store/useCardDepositStore';
import { useDepositStore } from '@/store/useDepositStore';

Expand Down Expand Up @@ -402,7 +404,7 @@
);
}

function DestinationDisplay({

Check warning on line 407 in components/Card/CardDepositInternalForm.tsx

View workflow job for this annotation

GitHub Actions / lint

'DestinationDisplay' is defined but never used. Allowed unused vars must match /^_/u
fundingChainLabel,
destinationTokenSymbol,
}: {
Expand Down Expand Up @@ -616,6 +618,19 @@
const { data: savingsMinimum } = useSponsoredMinimum(ADDRESSES.fuse.cardDepositManager);
const isSavingsSource = watchedFrom === CardDepositSource.SAVINGS;

// Topping up from savings spends soUSD out of Earn, which can cost a tier held
// or being built on the "Hold in Earn" route. Priced at the soUSD rate read
// above, or the share's wallet quote until that lands.
const savingsOutflowUsd = useMemo(() => {
const amount = Number(watchedAmount || 0);
if (!isSavingsSource || !Number.isFinite(amount) || amount <= 0) return 0;
return amount * (exchangeRate > 0 ? exchangeRate : soUsdToken?.quoteRate || 0);
}, [isSavingsSource, watchedAmount, exchangeRate, soUsdToken?.quoteRate]);
const { warning: tierBalanceWarning, proceed: proceedPastWarning } = useTierBalanceOutflowWarning(
'card_topup',
savingsOutflowUsd,
);

const schema = useMemo(() => {
return z.object({
amount: z
Expand Down Expand Up @@ -738,6 +753,7 @@
const onSubmit = useCallback(
async (data: any) => {
if (!user) return;
proceedPastWarning();

// Track submission
const trackingParams: Record<string, unknown> = {
Expand Down Expand Up @@ -860,6 +876,7 @@
setTransaction,
swapAndBridge,
updateActivity,
proceedPastWarning,
],
);

Expand Down Expand Up @@ -1053,6 +1070,8 @@
/>
)}

{isSavingsSource && <TierBalanceOutflowNotice warning={tierBalanceWarning} />}

{/* {watchedFrom !== CardDepositSource.EXTERNAL && (
<DestinationDisplay
fundingChainLabel={getChain(fundingChainId)?.name ?? 'Card'}
Expand Down
9 changes: 8 additions & 1 deletion components/Earn/EarnScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useState } from 'react';
import { Href, router } from 'expo-router';

import EarnTierBalanceCard from '@/components/Earn/EarnTierBalanceCard';
import EarnYieldBoostCard from '@/components/Earn/EarnYieldBoostCard';
import HeaderHelpButton from '@/components/Navbar/HeaderHelpButton';
import PageLayout from '@/components/PageLayout';
Expand Down Expand Up @@ -154,7 +155,13 @@ export default function EarnScreen() {
past30={past30}
products={products}
onOpenProduct={type => router.push(openYieldProduct(type) as Href)}
boost={<EarnYieldBoostCard />}
boost={
<>
{/* Draws nothing unless the "Hold in Earn" tier route is staged to this user. */}
<EarnTierBalanceCard />
<EarnYieldBoostCard />
</>
}
/>
</PageLayout>
);
Expand Down
88 changes: 88 additions & 0 deletions components/Earn/EarnTierBalanceCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { useEffect, useRef } from 'react';
import { Pressable, View } from 'react-native';

import { PointsProgress } from '@/components/Rewards/NewRewards/TierUpgradeCard';
import { Text } from '@/components/ui/text';
import { TRACKING_EVENTS } from '@/constants/tracking-events';
import { useAddToEarn, useTierBalance } from '@/hooks/useTierBalance';
import { track } from '@/lib/analytics';
import { trackNeedsTopUp, trackNudgeCopy, trackProgress } from '@/lib/tierBalance';
import { cn } from '@/lib/utils';

interface EarnTierBalanceCardProps {
className?: string;
}

/**
* The "Hold in Earn" route on the Earn page: how far the balance here is from
* unlocking (or keeping) a tier, laid out like the yield boost card beside it,
* with the points card's progress bar.
*
* Every figure is the backend's — the shortfall, the threshold, the days — and
* the card draws nothing for anyone the route is not staged to, or for an Ultra
* member by another route, who has nothing left to unlock.
*/
const EarnTierBalanceCard = ({ className }: EarnTierBalanceCardProps) => {
const { balance, relevant } = useTierBalance();
const addToEarn = useAddToEarn('earn');

// Reported once per tier and state.
const viewed = useRef<string | null>(null);
useEffect(() => {
if (!relevant) return;
const key = `${relevant.tier}:${relevant.status}`;
if (viewed.current === key) return;
viewed.current = key;
track(TRACKING_EVENTS.TIER_BALANCE_OPTION_VIEWED, {
route: 'balance',
tier: relevant.tier,
status: relevant.status,
surface: 'earn',
});
}, [relevant]);

if (!balance || !relevant) return null;

const { title, body } = trackNudgeCopy(relevant, balance);
const progress = trackProgress(relevant, balance);
const canAdd = trackNeedsTopUp(relevant);

return (
<View className={cn('overflow-hidden rounded-[20px] bg-card', className)}>
<View className="gap-3 px-4 py-[18px]">
<View className="flex-row items-center gap-3">
<View className="min-w-0 flex-1 gap-[5px]">
<Text className="text-[16px] font-semibold leading-5 text-white">{title}</Text>
<Text className="text-[14px] leading-[18px] text-white/50">{body}</Text>
</View>
{canAdd ? (
<Pressable
accessibilityRole="button"
accessibilityLabel={`Deposit to Earn. ${title}`}
onPress={() => addToEarn(relevant)}
className="h-[37px] min-w-[80px] items-center justify-center rounded-full bg-[#94F27F] px-[21px] transition-all active:scale-95 active:opacity-80"
>
<Text
className="text-black"
style={{ fontFamily: 'MonaSans_600SemiBold', fontSize: 16, lineHeight: 20 }}
>
Deposit
</Text>
</Pressable>
) : null}
</View>
<View className="flex-row items-center gap-[10px]">
<PointsProgress percent={progress.percent} />
<View className="flex-row items-baseline">
{progress.value ? (
<Text className="text-[14px] leading-[18px] text-white">{progress.value}</Text>
) : null}
<Text className="text-[14px] leading-[18px] text-white/50">{progress.target}</Text>
</View>
</View>
</View>
</View>
);
};

export default EarnTierBalanceCard;
5 changes: 4 additions & 1 deletion components/Earn/EarnView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ export interface EarnViewProps {
past30: number | undefined;
products: EarnProduct[];
onOpenProduct: (type: VaultType) => void;
/** The yield boost card; it renders nothing for a user without one. */
/**
* The yield boost card and the "Hold in Earn" tier nudge; each renders nothing
* for a user without one.
*/
boost?: ReactNode;
}

Expand Down
51 changes: 47 additions & 4 deletions components/Rewards/NewRewards/RewardsBenefitsScreenNew.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ import PageLayout from '@/components/PageLayout';
import { BackButton } from '@/components/ui/back-button';
import { Text } from '@/components/ui/text';
import { path } from '@/constants/path';
import { TRACKING_EVENTS } from '@/constants/tracking-events';
import { useCardProvider } from '@/hooks/useCardProvider';
import { useCardStatus } from '@/hooks/useCardStatus';
import { useRewardsUserData, useTierBenefits } from '@/hooks/useRewards';
import { useSavingsFundFlow } from '@/hooks/useSavingsFundFlow';
import { useAddToEarn } from '@/hooks/useTierBalance';
import { useTierMembership } from '@/hooks/useTierMembership';
import { track } from '@/lib/analytics';
import { isHigherTier } from '@/lib/rewardsUpgrade';
import { activeTierBalance, tierBalanceTrack } from '@/lib/tierBalance';
import { availableRoutes, findOffer, offerFirstYearFeeUsd } from '@/lib/tierUpgrade';
import { RewardsTier } from '@/lib/types';
import { RewardsTier, type TierBalanceTrackDto } from '@/lib/types';
import { useSwapState } from '@/store/swapStore';
import { useDepositStore } from '@/store/useDepositStore';
import { useRewardsUpgradeStore } from '@/store/useRewardsUpgradeStore';
Expand Down Expand Up @@ -237,6 +241,9 @@ function RewardsBenefitsForAccount({ initialTier }: { initialTier: RewardsTier |
: undefined;
const { data: membership } = useTierMembership();
const openTierUpgrade = useTierUpgradeStore(state => state.open);
// The "Hold in Earn" route, for a user it is staged to; null for everyone else.
const balance = activeTierBalance(membership);
const addToEarn = useAddToEarn('tier_benefits');
const [selectedTierOverride, setSelectedTierOverride] = useState<RewardsTier | null>(initialTier);
const [isUpgradeSheetOpen, setIsUpgradeSheetOpen] = useState(false);
const [upgradeTier, setUpgradeTier] = useState<RewardsTier.PRIME | RewardsTier.ULTRA>(
Expand Down Expand Up @@ -300,6 +307,34 @@ function RewardsBenefitsForAccount({ initialTier }: { initialTier: RewardsTier |
return availableRoutes(offer, membership.contracts);
};

/**
* This tier's "Hold in Earn" track, when the page should offer it: Prime and
* Ultra, unless the user already holds the tier by another route and the
* track has nothing to report.
*/
const balanceTrackFor = (tier: RewardsTier): TierBalanceTrackDto | undefined => {
if (!balance || tier === RewardsTier.CORE) return undefined;
const balanceTrack = tierBalanceTrack(balance, tier);
const holdsTier = !isHigherTier(tier, membership?.currentTier ?? RewardsTier.CORE);
return holdsTier && balanceTrack.status === 'none' ? undefined : balanceTrack;
};

// Reported once per tier and state, when its page is the one on screen.
const selectedBalanceTrack = balanceTrackFor(selectedTier);
const viewedBalanceTracks = useRef(new Set<string>());
useEffect(() => {
if (!selectedBalanceTrack) return;
const key = `${selectedBalanceTrack.tier}:${selectedBalanceTrack.status}`;
if (viewedBalanceTracks.current.has(key)) return;
viewedBalanceTracks.current.add(key);
track(TRACKING_EVENTS.TIER_BALANCE_OPTION_VIEWED, {
route: 'balance',
tier: selectedBalanceTrack.tier,
status: selectedBalanceTrack.status,
surface: 'tier_benefits',
});
}, [selectedBalanceTrack]);

const ctaFor = (tier: RewardsTier) => {
const offer = findOffer(membership, tier);

Expand Down Expand Up @@ -558,15 +593,20 @@ function RewardsBenefitsForAccount({ initialTier }: { initialTier: RewardsTier |
showCardFx={showCardFx}
offer={membership?.enabled ? findOffer(membership, tier) : undefined}
contracts={membership?.contracts}
balance={balance}
balanceTrack={balanceTrackFor(tier)}
onAddToEarn={addToEarn}
showUpgradeSpace={
!ctaFor(tier).held &&
(tier !== RewardsTier.CORE || (isError && !isRewardsFetching))
}
subtitle={(() => {
const pointsEnabled = membership?.pointsUnlockEnabled ?? true;
const offerCopy = membership?.enabled
? tierOfferSubtitle(findOffer(membership, tier), membership.contracts)
: null;
const offerCopy = tierOfferSubtitle(
membership?.enabled ? findOffer(membership, tier) : undefined,
membership?.contracts,
balanceTrackFor(tier),
);
const copy =
tier === RewardsTier.CORE
? 'Starting tier'
Expand All @@ -584,6 +624,9 @@ function RewardsBenefitsForAccount({ initialTier }: { initialTier: RewardsTier |
fontSize: 16 * Math.min(pageWidth / 420, 1),
lineHeight: 20,
color: 'rgba(255,255,255,0.7)',
// Three ways to a tier can run to a second line.
textAlign: 'center',
paddingHorizontal: 16,
}}
>
{copy}
Expand Down
Loading
Loading