Skip to content

Commit f099d28

Browse files
committed
chore: refactor quickbuy to not rely on swaps state
1 parent 4f97a52 commit f099d28

6 files changed

Lines changed: 450 additions & 226 deletions

File tree

app/components/Views/SocialLeaderboard/TraderPositionView/components/QuickBuyBottomSheet/QuickBuyBottomSheet.tsx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,6 @@ const QuickBuyBottomSheetInner: React.FC<InnerProps> = ({
4848
sourceBalanceFiat,
4949
isQuoteLoading,
5050
isSubmittingTx,
51-
estimatedPoints,
52-
isRewardsLoading,
53-
shouldShowLiveRewardsEstimate,
54-
shouldShowRewardsOptInCta,
55-
shouldShowRewardsFallbackZero,
56-
hasRewardsError,
57-
rewardsAccountScope,
5851
hasError,
5952
hasValidAmount,
6053
isConfirmDisabled,
@@ -111,13 +104,6 @@ const QuickBuyBottomSheetInner: React.FC<InnerProps> = ({
111104
setIsSourcePickerOpen={setIsSourcePickerOpen}
112105
setSelectedSourceToken={setSelectedSourceToken}
113106
sourceBalanceFiat={sourceBalanceFiat}
114-
estimatedPoints={estimatedPoints}
115-
isRewardsLoading={isRewardsLoading}
116-
shouldShowLiveRewardsEstimate={shouldShowLiveRewardsEstimate}
117-
shouldShowRewardsOptInCta={shouldShowRewardsOptInCta}
118-
shouldShowRewardsFallbackZero={shouldShowRewardsFallbackZero}
119-
hasRewardsError={hasRewardsError}
120-
rewardsAccountScope={rewardsAccountScope}
121107
isConfirmDisabled={isConfirmDisabled}
122108
isConfirmLoading={isConfirmLoading}
123109
getButtonLabel={getButtonLabel}

app/components/Views/SocialLeaderboard/TraderPositionView/components/QuickBuyBottomSheet/QuickBuyFooter.tsx

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,8 @@ import BadgeWrapper, {
2424
import BadgeNetwork from '../../../../../../component-library/components/Badges/Badge/variants/BadgeNetwork';
2525
import { getNetworkImageSource } from '../../../../../../util/networks';
2626
import type { Hex } from '@metamask/utils';
27-
import type { InternalAccount } from '@metamask/keyring-internal-api';
2827
import type { BridgeToken } from '../../../../../UI/Bridge/types';
2928
import SourceTokenPicker from './SourceTokenPicker';
30-
import RewardsAnimations, {
31-
RewardAnimationState,
32-
} from '../../../../../UI/Rewards/components/RewardPointsAnimation';
33-
import AddRewardsAccount from '../../../../../UI/Rewards/components/AddRewardsAccount/AddRewardsAccount';
3429
import { strings } from '../../../../../../../locales/i18n';
3530

3631
const USD_PRESETS = ['1', '20', '50', '100'];
@@ -47,13 +42,6 @@ interface QuickBuyFooterProps {
4742
React.SetStateAction<BridgeToken | undefined>
4843
>;
4944
sourceBalanceFiat: string | undefined;
50-
estimatedPoints: number | null;
51-
isRewardsLoading: boolean;
52-
shouldShowLiveRewardsEstimate: boolean;
53-
shouldShowRewardsOptInCta: boolean;
54-
shouldShowRewardsFallbackZero: boolean;
55-
hasRewardsError: boolean;
56-
rewardsAccountScope: InternalAccount | null;
5745
isConfirmDisabled: boolean;
5846
isConfirmLoading: boolean;
5947
getButtonLabel: () => string;
@@ -72,13 +60,6 @@ const QuickBuyFooter: React.FC<QuickBuyFooterProps> = ({
7260
setIsSourcePickerOpen,
7361
setSelectedSourceToken,
7462
sourceBalanceFiat,
75-
estimatedPoints,
76-
isRewardsLoading,
77-
shouldShowLiveRewardsEstimate,
78-
shouldShowRewardsOptInCta,
79-
shouldShowRewardsFallbackZero,
80-
hasRewardsError,
81-
rewardsAccountScope,
8263
isConfirmDisabled,
8364
isConfirmLoading,
8465
getButtonLabel,
@@ -217,61 +198,6 @@ const QuickBuyFooter: React.FC<QuickBuyFooterProps> = ({
217198
{`$${usdAmount || '0'}`}
218199
</Text>
219200
</Box>
220-
221-
{/* Est. points row */}
222-
<Box
223-
flexDirection={BoxFlexDirection.Row}
224-
alignItems={BoxAlignItems.Center}
225-
justifyContent={BoxJustifyContent.Between}
226-
>
227-
<Box
228-
flexDirection={BoxFlexDirection.Row}
229-
alignItems={BoxAlignItems.Center}
230-
gap={2}
231-
>
232-
<Text
233-
variant={TextVariant.BodyMd}
234-
color={TextColor.TextAlternative}
235-
>
236-
{strings('social_leaderboard.quick_buy.est_points')}
237-
</Text>
238-
<Icon
239-
name={IconName.Info}
240-
size={IconSize.Sm}
241-
color={colors.icon.alternative}
242-
/>
243-
</Box>
244-
<Box alignItems={BoxAlignItems.End}>
245-
{shouldShowLiveRewardsEstimate ? (
246-
<RewardsAnimations
247-
value={estimatedPoints ?? 0}
248-
state={
249-
isRewardsLoading
250-
? RewardAnimationState.Loading
251-
: hasRewardsError
252-
? RewardAnimationState.ErrorState
253-
: RewardAnimationState.Idle
254-
}
255-
/>
256-
) : shouldShowRewardsOptInCta ? (
257-
<AddRewardsAccount
258-
testID="quick-buy-add-rewards-account"
259-
account={rewardsAccountScope ?? undefined}
260-
/>
261-
) : shouldShowRewardsFallbackZero ? (
262-
<Text variant={TextVariant.BodyMd} color={TextColor.TextDefault}>
263-
0
264-
</Text>
265-
) : (
266-
<Text
267-
variant={TextVariant.BodyMd}
268-
color={TextColor.TextAlternative}
269-
>
270-
-
271-
</Text>
272-
)}
273-
</Box>
274-
</Box>
275201
</Box>
276202

277203
{/* Buy button */}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { FeatureId } from '@metamask/bridge-controller';
2+
3+
// Debounce interval for quote fetches when user inputs change.
4+
export const QUICKBUY_QUOTE_DEBOUNCE_MS = 400;
5+
6+
// Re-fetch quotes after this period of idle time so the confirm button never
7+
// uses an expired quote. The controller does not poll for us since we call
8+
// fetchQuotes directly.
9+
export const QUICKBUY_QUOTE_STALE_TIMEOUT_MS = 30_000;
10+
11+
// Slippage defaults (expressed as percent strings to match the bridge hooks).
12+
export const QUICKBUY_DEFAULT_SLIPPAGE = '0.5';
13+
export const QUICKBUY_STABLECOIN_SLIPPAGE = '0.1';
14+
export const QUICKBUY_SOLANA_SLIPPAGE = '1.0';
15+
16+
// FeatureId passed to BridgeController.fetchQuotes. Reuses PERPS so the backend
17+
// applies the same routing / fee semantics TransactionPayController already uses
18+
// for perpsDeposit.
19+
export const QUICKBUY_FEATURE_ID = FeatureId.PERPS;

0 commit comments

Comments
 (0)