Skip to content

Commit a6411d6

Browse files
committed
feat(predict): add enableDepositWalletWithdraw flag to gate withdraw entry
1 parent 5070c06 commit a6411d6

5 files changed

Lines changed: 105 additions & 5 deletions

File tree

app/components/UI/Predict/components/PredictBalance/PredictBalance.test.tsx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,25 @@ const initialState = {
7676
},
7777
};
7878

79+
function stateWithDepositWalletWithdrawEnabled(enabled: boolean) {
80+
return {
81+
engine: {
82+
backgroundState: {
83+
...initialState.engine.backgroundState,
84+
RemoteFeatureFlagController: {
85+
...backgroundState.RemoteFeatureFlagController,
86+
remoteFeatureFlags: {
87+
...backgroundState.RemoteFeatureFlagController?.remoteFeatureFlags,
88+
confirmations_pay_extended: {
89+
enableDepositWalletWithdraw: enabled,
90+
},
91+
},
92+
},
93+
},
94+
},
95+
};
96+
}
97+
7998
describe('PredictBalance', () => {
8099
beforeEach(() => {
81100
jest.clearAllMocks();
@@ -387,6 +406,43 @@ describe('PredictBalance', () => {
387406
expect(mockExecuteGuardedAction).not.toHaveBeenCalled();
388407
});
389408

409+
it('calls withdraw for Deposit Wallet users when enableDepositWalletWithdraw flag is on', () => {
410+
// Arrange
411+
const mockWithdraw = jest.fn();
412+
const mockOnDepositWalletWithdrawPress = jest.fn();
413+
mockUsePredictBalance.mockReturnValue({
414+
data: 100,
415+
isLoading: false,
416+
});
417+
mockUsePredictAccountState.mockReturnValue({
418+
data: {
419+
address: '0x2222222222222222222222222222222222222222',
420+
isDeployed: true,
421+
walletType: 'deposit-wallet',
422+
},
423+
isLoading: false,
424+
});
425+
mockUsePredictWithdraw.mockReturnValue({
426+
withdraw: mockWithdraw,
427+
});
428+
429+
// Act
430+
const { getByText } = renderWithProvider(
431+
<PredictBalance
432+
onDepositWalletWithdrawPress={mockOnDepositWalletWithdrawPress}
433+
/>,
434+
{
435+
state: stateWithDepositWalletWithdrawEnabled(true),
436+
},
437+
);
438+
const withdrawButton = getByText(/Withdraw/i);
439+
fireEvent.press(withdrawButton);
440+
441+
// Assert
442+
expect(mockWithdraw).toHaveBeenCalledTimes(1);
443+
expect(mockOnDepositWalletWithdrawPress).not.toHaveBeenCalled();
444+
});
445+
390446
it('calls temporary unavailable handler instead of withdrawing for Deposit Wallet users', () => {
391447
// Arrange
392448
const mockWithdraw = jest.fn();

app/components/UI/Predict/components/PredictBalance/PredictBalance.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { PredictNavigationParamList } from '../../types/navigation';
4141
import { usePredictWithdraw } from '../../hooks/usePredictWithdraw';
4242
import { usePredictAccountState } from '../../hooks/usePredictAccountState';
4343
import { PredictEventValues } from '../../constants/eventNames';
44+
import { selectMetaMaskPayFlags } from '../../../../../selectors/featureFlagController/confirmations';
4445
import { PREDICT_BALANCE_TEST_IDS } from './PredictBalance.testIds';
4546

4647
// This is a temporary component that will be removed when the deposit flow is fully implemented
@@ -55,6 +56,7 @@ const PredictBalance: React.FC<PredictBalanceProps> = ({
5556
}) => {
5657
const tw = useTailwind();
5758
const privacyMode = useSelector(selectPrivacyMode);
59+
const { enableDepositWalletWithdraw } = useSelector(selectMetaMaskPayFlags);
5860

5961
const navigation =
6062
useNavigation<NavigationProp<PredictNavigationParamList>>();
@@ -103,15 +105,18 @@ const PredictBalance: React.FC<PredictBalanceProps> = ({
103105
return;
104106
}
105107

106-
// Temporary Deposit Wallet migration guard. Remove this branch and sheet
107-
// once Deposit Wallet withdrawals are implemented.
108-
if (walletType === 'deposit-wallet') {
108+
if (walletType === 'deposit-wallet' && !enableDepositWalletWithdraw) {
109109
onDepositWalletWithdrawPress?.();
110110
return;
111111
}
112112

113113
withdraw();
114-
}, [onDepositWalletWithdrawPress, walletType, withdraw]);
114+
}, [
115+
enableDepositWalletWithdraw,
116+
onDepositWalletWithdrawPress,
117+
walletType,
118+
withdraw,
119+
]);
115120

116121
if (isLoading) {
117122
return (

app/core/Engine/controllers/transaction-controller/transaction-controller-init.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ describe('Transaction Controller Init', () => {
235235
bufferSubsequent: 0.05,
236236
slippage: 0.005,
237237
stxDisabled: false,
238+
enableDepositWalletWithdraw: false,
238239
});
239240

240241
payHookClassMock.mockReturnValue({
@@ -454,6 +455,7 @@ describe('Transaction Controller Init', () => {
454455
bufferSubsequent: 0.05,
455456
slippage: 0.005,
456457
stxDisabled: true,
458+
enableDepositWalletWithdraw: false,
457459
});
458460

459461
const hooks = testConstructorOption('hooks');
@@ -471,6 +473,7 @@ describe('Transaction Controller Init', () => {
471473
bufferSubsequent: 0.05,
472474
slippage: 0.005,
473475
stxDisabled: false,
476+
enableDepositWalletWithdraw: false,
474477
});
475478

476479
const hooks = testConstructorOption('hooks');

app/selectors/featureFlagController/confirmations/index.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
PAY_FIAT_ENABLED_TRANSACTION_TYPES,
1717
PAY_FIAT_MAX_DELAY_MINUTES_FOR_PAYMENT_METHODS,
1818
selectMetaMaskPayHardwareFlags,
19+
PAY_ENABLE_DEPOSIT_WALLET_WITHDRAW_DEFAULT,
1920
PAY_HARDWARE_ENABLED_DEFAULT,
2021
PreferredToken,
2122
getPreferredTokensForTransactionType,
@@ -563,3 +564,23 @@ describe('selectMetaMaskPayHardwareFlags', () => {
563564
expect(selectMetaMaskPayHardwareFlags(state)).toEqual({ enabled: true });
564565
});
565566
});
567+
568+
describe('selectMetaMaskPayFlags extended flags', () => {
569+
it('returns default enableDepositWalletWithdraw when flag is absent', () => {
570+
expect(
571+
selectMetaMaskPayFlags(mockedEmptyFlagsState).enableDepositWalletWithdraw,
572+
).toEqual(PAY_ENABLE_DEPOSIT_WALLET_WITHDRAW_DEFAULT);
573+
});
574+
575+
it('returns enableDepositWalletWithdraw from flag value', () => {
576+
const state = cloneDeep(mockedEmptyFlagsState);
577+
state.engine.backgroundState.RemoteFeatureFlagController.remoteFeatureFlags =
578+
{
579+
confirmations_pay_extended: { enableDepositWalletWithdraw: true },
580+
};
581+
582+
expect(selectMetaMaskPayFlags(state).enableDepositWalletWithdraw).toEqual(
583+
true,
584+
);
585+
});
586+
});

app/selectors/featureFlagController/confirmations/index.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const BUFFER_SUBSEQUENT_DEFAULT = 0.05;
1111
export const PAY_FIAT_ENABLED_TRANSACTION_TYPES = [];
1212
export const PAY_FIAT_MAX_DELAY_MINUTES_FOR_PAYMENT_METHODS = 10;
1313
export const PAY_HARDWARE_ENABLED_DEFAULT = false;
14+
export const PAY_ENABLE_DEPOSIT_WALLET_WITHDRAW_DEFAULT = false;
1415
export const SLIPPAGE_DEFAULT = 0.005;
1516
export const STX_DISABLED_DEFAULT = false;
1617

@@ -49,6 +50,10 @@ export interface MetaMaskPayFlags {
4950
stxDisabled: boolean;
5051
}
5152

53+
export interface MetaMaskPayExtendedFlags {
54+
enableDepositWalletWithdraw: boolean;
55+
}
56+
5257
export interface MetaMaskPayTokensFlags {
5358
preferredTokens: PreferredTokensConfig;
5459
blockedTokens: BlockedTokensConfig;
@@ -88,11 +93,16 @@ export interface MetaMaskPayHardwareFlags {
8893

8994
export const selectMetaMaskPayFlags = createSelector(
9095
selectRemoteFeatureFlags,
91-
(featureFlags): MetaMaskPayFlags => {
96+
(featureFlags): MetaMaskPayFlags & MetaMaskPayExtendedFlags => {
9297
const metaMaskPayFlags = featureFlags?.confirmations_pay as
9398
| Record<string, Json>
9499
| undefined;
95100

101+
const metaMaskPayExtendedFlags =
102+
featureFlags?.confirmations_pay_extended as
103+
| Record<string, Json>
104+
| undefined;
105+
96106
const attemptsMax =
97107
(metaMaskPayFlags?.attemptsMax as number) ?? ATTEMPTS_MAX_DEFAULT;
98108

@@ -111,13 +121,18 @@ export const selectMetaMaskPayFlags = createSelector(
111121
const stxDisabled =
112122
(metaMaskPayFlags?.stxDisabled as boolean) ?? STX_DISABLED_DEFAULT;
113123

124+
const enableDepositWalletWithdraw =
125+
(metaMaskPayExtendedFlags?.enableDepositWalletWithdraw as boolean) ??
126+
PAY_ENABLE_DEPOSIT_WALLET_WITHDRAW_DEFAULT;
127+
114128
return {
115129
attemptsMax,
116130
bufferInitial,
117131
bufferStep,
118132
bufferSubsequent,
119133
slippage,
120134
stxDisabled,
135+
enableDepositWalletWithdraw,
121136
};
122137
},
123138
);

0 commit comments

Comments
 (0)