Skip to content

Commit 57c4a64

Browse files
AxelGeswachunei
andauthored
feat(deposit): webview modal component (#17036)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** This adds a WebView component inside a bottom sheet, so it slides up from the bottom for a more native feel in the deposit flow. <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> https://github.com/user-attachments/assets/209724cf-fc58-4650-8cf5-036803a45073 ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: Pedro Pablo Aste Kompen <wachunei@gmail.com>
1 parent 46137a4 commit 57c4a64

32 files changed

+2109
-3803
lines changed

app/components/UI/Ramp/Deposit/Views/BuildQuote/BuildQuote.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,10 @@ const BuildQuote = () => {
9090
useState<DepositFiatCurrency>(USD_CURRENCY);
9191
const [amount, setAmount] = useState<string>('0');
9292
const [amountAsNumber, setAmountAsNumber] = useState<number>(0);
93-
const { isAuthenticated, selectedWalletAddress, selectedRegion } =
94-
useDepositSDK();
93+
const { isAuthenticated, selectedRegion } = useDepositSDK();
9594
const [error, setError] = useState<string | null>();
9695

9796
const { routeAfterAuthentication } = useDepositRouting({
98-
selectedWalletAddress,
9997
cryptoCurrencyChainId: cryptoCurrency.chainId,
10098
paymentMethodId: paymentMethod.id,
10199
});
@@ -124,7 +122,11 @@ const BuildQuote = () => {
124122

125123
useEffect(() => {
126124
navigation.setOptions(
127-
getDepositNavbarOptions(navigation, { title: 'Build Quote' }, theme),
125+
getDepositNavbarOptions(
126+
navigation,
127+
{ title: strings('deposit.buildQuote.title') },
128+
theme,
129+
),
128130
);
129131
}, [navigation, theme]);
130132

app/components/UI/Ramp/Deposit/Views/BuildQuote/__snapshots__/BuildQuote.test.tsx.snap

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ exports[`BuildQuote Component Continue button functionality displays error when
174174
}
175175
}
176176
>
177-
Build Quote
177+
Deposit
178178
</Text>
179179
</TouchableOpacity>
180180
</View>
@@ -1986,7 +1986,7 @@ exports[`BuildQuote Component Continue button functionality displays error when
19861986
}
19871987
}
19881988
>
1989-
Build Quote
1989+
Deposit
19901990
</Text>
19911991
</TouchableOpacity>
19921992
</View>
@@ -3798,7 +3798,7 @@ exports[`BuildQuote Component Continue button functionality displays error when
37983798
}
37993799
}
38003800
>
3801-
Build Quote
3801+
Deposit
38023802
</Text>
38033803
</TouchableOpacity>
38043804
</View>
@@ -5610,7 +5610,7 @@ exports[`BuildQuote Component Keypad Functionality displays converted token amou
56105610
}
56115611
}
56125612
>
5613-
Build Quote
5613+
Deposit
56145614
</Text>
56155615
</TouchableOpacity>
56165616
</View>
@@ -7403,7 +7403,7 @@ exports[`BuildQuote Component Keypad Functionality updates amount when keypad is
74037403
}
74047404
}
74057405
>
7406-
Build Quote
7406+
Deposit
74077407
</Text>
74087408
</TouchableOpacity>
74097409
</View>
@@ -9195,7 +9195,7 @@ exports[`BuildQuote Component Region Selection displays EUR currency when select
91959195
}
91969196
}
91979197
>
9198-
Build Quote
9198+
Deposit
91999199
</Text>
92009200
</TouchableOpacity>
92019201
</View>
@@ -10988,7 +10988,7 @@ exports[`BuildQuote Component Region Selection displays default US region on ini
1098810988
}
1098910989
}
1099010990
>
10991-
Build Quote
10991+
Deposit
1099210992
</Text>
1099310993
</TouchableOpacity>
1099410994
</View>
@@ -12781,7 +12781,7 @@ exports[`BuildQuote Component render matches snapshot 1`] = `
1278112781
}
1278212782
}
1278312783
>
12784-
Build Quote
12784+
Deposit
1278512785
</Text>
1278612786
</TouchableOpacity>
1278712787
</View>

app/components/UI/Ramp/Deposit/Views/EnterAddress/EnterAddress.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import DepositProgressBar from '../../components/DepositProgressBar';
1818
import { BasicInfoFormData } from '../BasicInfo/BasicInfo';
1919
import { useDepositSdkMethod } from '../../hooks/useDepositSdkMethod';
2020
import { createKycProcessingNavDetails } from '../KycProcessing/KycProcessing';
21-
import { createKycWebviewNavDetails } from '../KycWebview/KycWebview';
2221
import { BuyQuote } from '@consensys/native-ramps-sdk';
2322
import PoweredByTransak from '../../components/PoweredByTransak';
2423
import Button, {
@@ -27,6 +26,8 @@ import Button, {
2726
ButtonWidthTypes,
2827
} from '../../../../../../component-library/components/Buttons/Button';
2928
import PrivacySection from '../../components/PrivacySection';
29+
import { useDepositRouting } from '../../hooks/useDepositRouting';
30+
import { getCryptoCurrencyFromTransakId } from '../../utils';
3031

3132
export interface EnterAddressParams {
3233
formData: BasicInfoFormData;
@@ -55,6 +56,13 @@ const EnterAddress = (): JSX.Element => {
5556
kycUrl,
5657
} = useParams<EnterAddressParams>();
5758

59+
const cryptoCurrency = getCryptoCurrencyFromTransakId(quote.cryptoCurrency);
60+
61+
const { navigateToKycWebview } = useDepositRouting({
62+
cryptoCurrencyChainId: cryptoCurrency?.chainId || '',
63+
paymentMethodId: quote.paymentMethod,
64+
});
65+
5866
const initialFormData: AddressFormData = {
5967
addressLine1: '',
6068
addressLine2: '',
@@ -165,7 +173,7 @@ const EnterAddress = (): JSX.Element => {
165173
}
166174

167175
if (kycUrl) {
168-
navigation.navigate(...createKycWebviewNavDetails({ quote, kycUrl }));
176+
navigateToKycWebview(quote, kycUrl);
169177
} else {
170178
navigation.navigate(...createKycProcessingNavDetails({ quote }));
171179
}
@@ -180,9 +188,10 @@ const EnterAddress = (): JSX.Element => {
180188
kycError,
181189
submitPurpose,
182190
purposeError,
183-
navigation,
184-
quote,
185191
kycUrl,
192+
navigateToKycWebview,
193+
quote,
194+
navigation,
186195
submitSsnDetails,
187196
ssnError,
188197
]);

app/components/UI/Ramp/Deposit/Views/KycProcessing/KycProcessing.test.tsx

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import React from 'react';
2-
import { screen } from '@testing-library/react-native';
2+
import { screen, fireEvent, waitFor } from '@testing-library/react-native';
33
import KycProcessing from './KycProcessing';
44
import Routes from '../../../../../../constants/navigation/Routes';
55
import renderDepositTestComponent from '../../utils/renderDepositTestComponent';
6-
import { KycStatus } from '../../hooks/useUserDetailsPolling';
6+
import { KycStatus } from '../../constants';
77

88
const mockNavigate = jest.fn();
99
const mockGoBack = jest.fn();
1010
const mockSetNavigationOptions = jest.fn();
1111
const mockStopPolling = jest.fn();
1212
const mockStartPolling = jest.fn();
13+
const mockHandleApprovedKycFlow = jest.fn();
1314

1415
const mockKycForms = { forms: [] };
1516
const mockQuote = {
@@ -71,6 +72,12 @@ jest.mock('../../../../../UI/Navbar', () => ({
7172
}),
7273
}));
7374

75+
jest.mock('../../hooks/useDepositRouting', () => ({
76+
useDepositRouting: jest.fn(() => ({
77+
handleApprovedKycFlow: mockHandleApprovedKycFlow,
78+
})),
79+
}));
80+
7481
function render(Component: React.ComponentType) {
7582
return renderDepositTestComponent(Component, Routes.DEPOSIT.KYC_PROCESSING);
7683
}
@@ -84,6 +91,7 @@ describe('KycProcessing Component', () => {
8491
mockUseUserDetailsPolling.userDetails = null;
8592
mockUseUserDetailsPolling.loading = false;
8693
mockUseUserDetailsPolling.error = null;
94+
mockHandleApprovedKycFlow.mockClear();
8795
});
8896

8997
it('render matches snapshot', () => {
@@ -135,4 +143,24 @@ describe('KycProcessing Component', () => {
135143
render(KycProcessing);
136144
expect(screen.toJSON()).toMatchSnapshot();
137145
});
146+
147+
describe('handleContinue button behavior', () => {
148+
beforeEach(() => {
149+
mockUseUserDetailsPolling.userDetails = {
150+
kyc: { l1: { status: KycStatus.APPROVED } },
151+
};
152+
});
153+
154+
it('calls handleApprovedKycFlow when continue button is pressed', async () => {
155+
mockHandleApprovedKycFlow.mockResolvedValueOnce(undefined);
156+
render(KycProcessing);
157+
158+
const continueButton = screen.getByText('Complete your order');
159+
fireEvent.press(continueButton);
160+
161+
await waitFor(() => {
162+
expect(mockHandleApprovedKycFlow).toHaveBeenCalledWith(mockQuote);
163+
});
164+
});
165+
});
138166
});

app/components/UI/Ramp/Deposit/Views/KycProcessing/KycProcessing.tsx

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import { ActivityIndicator, View } from 'react-native';
33
import styleSheet from './KycProcessing.styles';
44
import { useNavigation } from '@react-navigation/native';
55
import DepositProgressBar from '../../components/DepositProgressBar';
6-
import useUserDetailsPolling, {
7-
KycStatus,
8-
} from '../../hooks/useUserDetailsPolling';
6+
import useUserDetailsPolling from '../../hooks/useUserDetailsPolling';
97
import {
108
createNavigationDetails,
119
useParams,
@@ -24,7 +22,6 @@ import Icon, {
2422
IconColor,
2523
} from '../../../../../../component-library/components/Icons/Icon';
2624
import { createVerifyIdentityNavDetails } from '../VerifyIdentity/VerifyIdentity';
27-
import { createProviderWebviewNavDetails } from '../ProviderWebview/ProviderWebview';
2825
import { BuyQuote } from '@consensys/native-ramps-sdk';
2926
import { useDepositSdkMethod } from '../../hooks/useDepositSdkMethod';
3027
import Button, {
@@ -33,6 +30,10 @@ import Button, {
3330
ButtonWidthTypes,
3431
} from '../../../../../../component-library/components/Buttons/Button';
3532
import PoweredByTransak from '../../components/PoweredByTransak';
33+
import { useDepositRouting } from '../../hooks/useDepositRouting';
34+
import { getCryptoCurrencyFromTransakId } from '../../utils';
35+
import { KycStatus } from '../../constants';
36+
import Logger from '../../../../../../util/Logger';
3637

3738
export interface KycProcessingParams {
3839
quote: BuyQuote;
@@ -46,6 +47,13 @@ const KycProcessing = () => {
4647
const { styles, theme } = useStyles(styleSheet, {});
4748
const { quote } = useParams<KycProcessingParams>();
4849

50+
const cryptoCurrency = getCryptoCurrencyFromTransakId(quote.cryptoCurrency);
51+
52+
const { handleApprovedKycFlow } = useDepositRouting({
53+
cryptoCurrencyChainId: cryptoCurrency?.chainId || '',
54+
paymentMethodId: quote.paymentMethod,
55+
});
56+
4957
const [{ data: kycForms, error: kycFormsError }] = useDepositSdkMethod(
5058
{
5159
method: 'getKYCForms',
@@ -83,9 +91,16 @@ const KycProcessing = () => {
8391
navigation.navigate(...createVerifyIdentityNavDetails({ quote }));
8492
}, [navigation, quote]);
8593

86-
const handleContinue = useCallback(() => {
87-
navigation.navigate(...createProviderWebviewNavDetails({ quote }));
88-
}, [navigation, quote]);
94+
const handleContinue = useCallback(async () => {
95+
try {
96+
await handleApprovedKycFlow(quote);
97+
} catch (error) {
98+
Logger.error(error as Error, {
99+
message: 'KycProcessing::handleContinue error',
100+
quote,
101+
});
102+
}
103+
}, [handleApprovedKycFlow, quote]);
89104

90105
const error = userDetailsError || kycFormsError;
91106
const hasPendingForms = kycForms && kycForms.forms.length > 0;

app/components/UI/Ramp/Deposit/Views/KycWebview/KycWebview.styles.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)