Skip to content

Commit 0a30ffa

Browse files
authored
Revert "feat(card): cp-7.58 Card Status changes" (#21640)
Reverts #21533 <!-- CURSOR_SUMMARY --> --- > [!NOTE] > <sup>[Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) is generating a summary for commit d1f9438. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 57cda1a commit 0a30ffa

File tree

18 files changed

+3887
-1581
lines changed

18 files changed

+3887
-1581
lines changed

app/components/UI/Card/Views/CardHome/CardHome.test.tsx

Lines changed: 0 additions & 316 deletions
Large diffs are not rendered by default.

app/components/UI/Card/Views/CardHome/CardHome.tsx

Lines changed: 9 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { useGetPriorityCardToken } from '../../hooks/useGetPriorityCardToken';
3333
import { strings } from '../../../../../../locales/i18n';
3434
import { useAssetBalance } from '../../hooks/useAssetBalance';
3535
import { useNavigateToCardPage } from '../../hooks/useNavigateToCardPage';
36-
import { AllowanceState, CardStatus, CardType, CardWarning } from '../../types';
36+
import { AllowanceState, CardType, CardWarning } from '../../types';
3737
import CardAssetItem from '../../components/CardAssetItem';
3838
import ManageCardListItem from '../../components/ManageCardListItem';
3939
import CardImage from '../../components/CardImage';
@@ -54,9 +54,8 @@ import { useCardSDK } from '../../sdk';
5454
import Routes from '../../../../../constants/navigation/Routes';
5555
import useIsBaanxLoginEnabled from '../../hooks/isBaanxLoginEnabled';
5656
import useCardDetails from '../../hooks/useCardDetails';
57-
import { selectIsAuthenticatedCard } from '../../../../../core/redux/slices/card';
58-
import { useCardProvision } from '../../hooks/useCardProvision';
5957
import CardWarningBox from '../../components/CardWarningBox/CardWarningBox';
58+
import { selectIsAuthenticatedCard } from '../../../../../core/redux/slices/card';
6059
import { useIsSwapEnabledForPriorityToken } from '../../hooks/useIsSwapEnabledForPriorityToken';
6160

6261
/**
@@ -99,15 +98,10 @@ const CardHome = () => {
9998
useAssetBalance(priorityToken);
10099
const {
101100
cardDetails,
102-
pollCardStatusUntilProvisioned,
103101
fetchCardDetails,
104102
isLoading: isLoadingCardDetails,
105103
error: cardDetailsError,
106-
warning: cardDetailsWarning,
107-
isLoadingPollCardStatusUntilProvisioned,
108104
} = useCardDetails();
109-
const { provisionCard, isLoading: isLoadingProvisionCard } =
110-
useCardProvision();
111105
const { navigateToCardPage } = useNavigateToCardPage(navigation);
112106
const { openSwaps } = useOpenSwaps({
113107
priorityToken,
@@ -265,21 +259,6 @@ const CardHome = () => {
265259
[isLoadingPriorityToken, isLoadingCardDetails],
266260
);
267261

268-
const enableCardAction = useCallback(async () => {
269-
await provisionCard();
270-
const isProvisioned = await pollCardStatusUntilProvisioned();
271-
272-
if (isProvisioned) {
273-
fetchPriorityToken();
274-
changeAssetAction();
275-
}
276-
}, [
277-
provisionCard,
278-
pollCardStatusUntilProvisioned,
279-
fetchPriorityToken,
280-
changeAssetAction,
281-
]);
282-
283262
const ButtonsSection = useMemo(() => {
284263
if (isLoading) {
285264
return (
@@ -293,45 +272,7 @@ const CardHome = () => {
293272
}
294273

295274
if (isBaanxLoginEnabled) {
296-
if (cardDetailsWarning === CardWarning.NoCard) {
297-
return (
298-
<Button
299-
variant={ButtonVariants.Primary}
300-
style={styles.defaultMarginTop}
301-
label={strings('card.card_home.enable_card_button_label')}
302-
size={ButtonSize.Lg}
303-
onPress={enableCardAction}
304-
width={ButtonWidthTypes.Full}
305-
disabled={
306-
isLoading ||
307-
isLoadingPollCardStatusUntilProvisioned ||
308-
isLoadingProvisionCard
309-
}
310-
loading={
311-
isLoading ||
312-
isLoadingPollCardStatusUntilProvisioned ||
313-
isLoadingProvisionCard
314-
}
315-
testID={CardHomeSelectors.ENABLE_CARD_BUTTON}
316-
/>
317-
);
318-
}
319-
320-
if (priorityTokenWarning === CardWarning.NeedDelegation) {
321-
return (
322-
<Button
323-
variant={ButtonVariants.Primary}
324-
style={styles.defaultMarginTop}
325-
label={strings('card.card_home.enable_assets_button_label')}
326-
size={ButtonSize.Lg}
327-
onPress={changeAssetAction}
328-
width={ButtonWidthTypes.Full}
329-
disabled={isLoading}
330-
loading={isLoading}
331-
testID={CardHomeSelectors.ENABLE_ASSETS_BUTTON}
332-
/>
333-
);
334-
}
275+
if (priorityTokenWarning === CardWarning.NeedDelegation) return null;
335276

336277
return (
337278
<View style={styles.buttonsContainer}>
@@ -439,7 +380,12 @@ const CardHome = () => {
439380
alwaysBounceVertical={false}
440381
contentContainerStyle={styles.contentContainer}
441382
>
442-
{cardDetailsWarning && <CardWarningBox warning={cardDetailsWarning} />}
383+
{priorityTokenWarning && (
384+
<CardWarningBox
385+
warning={priorityTokenWarning}
386+
onConfirm={addFundsAction}
387+
/>
388+
)}
443389
<View style={styles.cardBalanceContainer}>
444390
<View
445391
style={[
@@ -521,7 +467,6 @@ const CardHome = () => {
521467
) : (
522468
<CardImage
523469
type={cardDetails?.type ?? CardType.VIRTUAL}
524-
status={cardDetails?.status ?? CardStatus.ACTIVE}
525470
address={priorityToken?.walletAddress}
526471
/>
527472
)}

app/components/UI/Card/Views/CardHome/__snapshots__/CardHome.test.tsx.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ exports[`CardHome Component renders correctly and matches snapshot 1`] = `
520520
}
521521
}
522522
>
523-
Change asset
523+
card.card_home.change_asset
524524
</Text>
525525
</TouchableOpacity>
526526
</View>
@@ -578,7 +578,7 @@ exports[`CardHome Component renders correctly and matches snapshot 1`] = `
578578
}
579579
}
580580
>
581-
Manage spending limit
581+
card.card_home.manage_card_options.manage_spending_limit
582582
</Text>
583583
<Text
584584
accessibilityRole="text"
@@ -592,7 +592,7 @@ exports[`CardHome Component renders correctly and matches snapshot 1`] = `
592592
}
593593
}
594594
>
595-
Full spending access
595+
card.card_home.manage_card_options.manage_spending_limit_description_full
596596
</Text>
597597
</View>
598598
<View
@@ -1262,7 +1262,7 @@ exports[`CardHome Component renders correctly with privacy mode enabled 1`] = `
12621262
}
12631263
}
12641264
>
1265-
Change asset
1265+
card.card_home.change_asset
12661266
</Text>
12671267
</TouchableOpacity>
12681268
</View>
@@ -1320,7 +1320,7 @@ exports[`CardHome Component renders correctly with privacy mode enabled 1`] = `
13201320
}
13211321
}
13221322
>
1323-
Manage spending limit
1323+
card.card_home.manage_card_options.manage_spending_limit
13241324
</Text>
13251325
<Text
13261326
accessibilityRole="text"
@@ -1334,7 +1334,7 @@ exports[`CardHome Component renders correctly with privacy mode enabled 1`] = `
13341334
}
13351335
}
13361336
>
1337-
Full spending access
1337+
card.card_home.manage_card_options.manage_spending_limit_description_full
13381338
</Text>
13391339
</View>
13401340
<View
Lines changed: 29 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
import React from 'react';
22
import CardImage from './CardImage';
3-
import { CardType, CardStatus } from '../../types';
3+
import { CardType } from '../../types';
44
import { renderScreen } from '../../../../../util/test/renderWithProvider';
55
import { backgroundState } from '../../../../../util/test/initial-root-state';
66

7-
jest.mock('../../util/truncateAddress', () => ({
8-
truncateAddress: jest.fn(
9-
(address: string) => `${address.slice(0, 6)}...${address.slice(-4)}`,
10-
),
11-
}));
12-
137
function renderWithProvider(component: React.ComponentType) {
148
return renderScreen(
159
component,
@@ -27,144 +21,57 @@ function renderWithProvider(component: React.ComponentType) {
2721
}
2822

2923
describe('CardImage Component', () => {
30-
it('renders virtual card image for VIRTUAL type', () => {
31-
const { getByTestId } = renderWithProvider(() => (
32-
<CardImage
33-
type={CardType.VIRTUAL}
34-
status={CardStatus.ACTIVE}
35-
testID="virtual-card-image"
36-
/>
37-
));
38-
39-
expect(getByTestId('virtual-card-image')).toBeOnTheScreen();
40-
});
41-
42-
it('renders metal card image for PHYSICAL type', () => {
43-
const { getByTestId } = renderWithProvider(() => (
44-
<CardImage
45-
type={CardType.PHYSICAL}
46-
status={CardStatus.ACTIVE}
47-
testID="physical-card-image"
48-
/>
49-
));
50-
51-
expect(getByTestId('physical-card-image')).toBeOnTheScreen();
52-
});
53-
54-
it('renders metal card image for METAL type', () => {
55-
const { getByTestId } = renderWithProvider(() => (
56-
<CardImage
57-
type={CardType.METAL}
58-
status={CardStatus.ACTIVE}
59-
testID="metal-card-image"
60-
/>
61-
));
62-
63-
expect(getByTestId('metal-card-image')).toBeOnTheScreen();
64-
});
65-
66-
it('applies lower opacity when status is FROZEN', () => {
67-
const { getByTestId } = renderWithProvider(() => (
68-
<CardImage
69-
type={CardType.VIRTUAL}
70-
status={CardStatus.FROZEN}
71-
testID="frozen-card"
72-
/>
73-
));
74-
75-
expect(getByTestId('frozen-card')).toBeOnTheScreen();
76-
});
77-
78-
it('applies lower opacity when status is BLOCKED', () => {
79-
const { getByTestId } = renderWithProvider(() => (
80-
<CardImage
81-
type={CardType.VIRTUAL}
82-
status={CardStatus.BLOCKED}
83-
testID="blocked-card"
84-
/>
24+
it('renders virtual card image when type is VIRTUAL', () => {
25+
const { toJSON, getByTestId } = renderWithProvider(() => (
26+
<CardImage type={CardType.VIRTUAL} testID="virtual-card-image" />
8527
));
8628

87-
expect(getByTestId('blocked-card')).toBeOnTheScreen();
29+
expect(getByTestId('virtual-card-image')).toBeDefined();
30+
expect(toJSON()).toMatchSnapshot();
8831
});
8932

90-
it('renders with full opacity when status is ACTIVE', () => {
91-
const { getByTestId } = renderWithProvider(() => (
92-
<CardImage
93-
type={CardType.VIRTUAL}
94-
status={CardStatus.ACTIVE}
95-
testID="active-card"
96-
/>
33+
it('renders metal card image when type is PHYSICAL', () => {
34+
const { toJSON, getByTestId } = renderWithProvider(() => (
35+
<CardImage type={CardType.PHYSICAL} testID="physical-card-image" />
9736
));
9837

99-
expect(getByTestId('active-card')).toBeOnTheScreen();
38+
expect(getByTestId('physical-card-image')).toBeDefined();
39+
expect(toJSON()).toMatchSnapshot();
10040
});
10141

102-
it('renders with truncated address when address prop provided', () => {
103-
const { getByTestId } = renderWithProvider(() => (
104-
<CardImage
105-
type={CardType.VIRTUAL}
106-
status={CardStatus.ACTIVE}
107-
address="0x1234567890123456789012345678901234567890"
108-
testID="card-with-address"
109-
/>
42+
it('renders metal card image when type is METAL', () => {
43+
const { toJSON, getByTestId } = renderWithProvider(() => (
44+
<CardImage type={CardType.METAL} testID="metal-card-image" />
11045
));
11146

112-
expect(getByTestId('card-with-address')).toBeOnTheScreen();
47+
expect(getByTestId('metal-card-image')).toBeDefined();
48+
expect(toJSON()).toMatchSnapshot();
11349
});
11450

115-
it('renders without address when address prop not provided', () => {
116-
const { getByTestId } = renderWithProvider(() => (
51+
it('renders with custom SVG properties', () => {
52+
const { toJSON } = renderWithProvider(() => (
11753
<CardImage
11854
type={CardType.VIRTUAL}
119-
status={CardStatus.ACTIVE}
120-
testID="card-without-address"
55+
width={200}
56+
height={100}
57+
fill="red"
58+
stroke="blue"
59+
opacity={0.5}
60+
testID="custom-card-image"
12161
/>
12262
));
12363

124-
expect(getByTestId('card-without-address')).toBeOnTheScreen();
64+
expect(toJSON()).toMatchSnapshot();
12565
});
12666

12767
it.each([CardType.VIRTUAL, CardType.PHYSICAL, CardType.METAL] as const)(
128-
'renders %s card type with ACTIVE status',
68+
'renders %s card type without errors',
12969
(cardType) => {
130-
const { getByTestId } = renderWithProvider(() => (
131-
<CardImage
132-
type={cardType}
133-
status={CardStatus.ACTIVE}
134-
testID={`${cardType}-card`}
135-
/>
136-
));
137-
138-
expect(getByTestId(`${cardType}-card`)).toBeOnTheScreen();
139-
},
140-
);
141-
142-
it.each([CardStatus.ACTIVE, CardStatus.FROZEN, CardStatus.BLOCKED] as const)(
143-
'renders VIRTUAL card with %s status',
144-
(status) => {
145-
const { getByTestId } = renderWithProvider(() => (
146-
<CardImage
147-
type={CardType.VIRTUAL}
148-
status={status}
149-
testID={`card-${status}`}
150-
/>
70+
const { toJSON } = renderWithProvider(() => (
71+
<CardImage type={cardType} />
15172
));
15273

153-
expect(getByTestId(`card-${status}`)).toBeOnTheScreen();
74+
expect(toJSON()).toBeDefined();
15475
},
15576
);
156-
157-
it('renders with custom SVG properties', () => {
158-
const { getByTestId } = renderWithProvider(() => (
159-
<CardImage
160-
type={CardType.VIRTUAL}
161-
status={CardStatus.ACTIVE}
162-
width={200}
163-
height={100}
164-
testID="custom-card-image"
165-
/>
166-
));
167-
168-
expect(getByTestId('custom-card-image')).toBeOnTheScreen();
169-
});
17077
});

0 commit comments

Comments
 (0)