Skip to content

Commit

Permalink
fix(ramp): reset intent asset after parsed (#12756)
Browse files Browse the repository at this point in the history
<!--
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**

Removes the address from the Ramp Intent after it has been correctly
parsed and selected.

## **Related issues**

Fixes: #12749 

## **Manual testing steps**

1. Use this URL Schema Deep Link:
metamask://buy?chainId=1&address=0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
2. Once the build quotes screen loads up, Change from USDC to LINK
3. LINK must selected

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->


https://github.com/user-attachments/assets/69049295-a9aa-4664-8862-ced6e47e28dc



## **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.
  • Loading branch information
wachunei authored Dec 18, 2024
1 parent 664cbb6 commit 25375aa
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
51 changes: 51 additions & 0 deletions app/components/UI/Ramp/hooks/useCryptoCurrencies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const mockuseRampSDKInitialValues: DeepPartial<RampSDK> = {
selectedFiatCurrencyId: 'test-fiat-currency-id',
selectedAsset: null,
setSelectedAsset: jest.fn(),
setIntent: jest.fn(),
selectedChainId: '1',
isBuy: true,
};
Expand Down Expand Up @@ -354,4 +355,54 @@ describe('useCryptoCurrencies', () => {
queryGetCryptoCurrencies: mockQueryGetCryptoCurrencies,
});
});

it('selects the crypto currency from intent if available and resets it', () => {
const mockQueryGetCryptoCurrencies = jest.fn();
(useSDKMethod as jest.Mock).mockReturnValue([
{
data: [
{ network: { chainId: '1' }, address: 'test-address-1' },
{ network: { chainId: '1' }, address: 'test-address-2' },
{ network: { chainId: '1' }, address: NATIVE_ADDRESS },
],
error: null,
isFetching: false,
},
mockQueryGetCryptoCurrencies,
]);

mockUseRampSDKValues.selectedAsset = {
network: { chainId: '1' },
address: 'test-address-3',
};

const mockedIntent = { address: 'test-address-2' };
mockUseRampSDKValues.intent = mockedIntent;

const { result } = renderHookWithProvider(() => useCryptoCurrencies());

expect(mockUseRampSDKValues.setSelectedAsset).toHaveBeenCalledWith({
network: { chainId: '1' },
address: 'test-address-2',
});
expect(result.current).toEqual({
cryptoCurrencies: [
{ network: { chainId: '1' }, address: 'test-address-1' },
{ network: { chainId: '1' }, address: 'test-address-2' },
{ network: { chainId: '1' }, address: NATIVE_ADDRESS },
],
errorCryptoCurrencies: null,
isFetchingCryptoCurrencies: false,
queryGetCryptoCurrencies: mockQueryGetCryptoCurrencies,
});

expect(mockUseRampSDKValues.setIntent).toHaveBeenCalledWith(
expect.any(Function),
);
const setIntentFunction = (mockUseRampSDKValues.setIntent as jest.Mock).mock
.calls[0][0];
expect(setIntentFunction(mockedIntent)).toEqual({
address: undefined,
});
});
});
3 changes: 3 additions & 0 deletions app/components/UI/Ramp/hooks/useCryptoCurrencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default function useCryptoCurrencies() {
selectedChainId,
isBuy,
intent,
setIntent,
} = useRampSDK();

const [
Expand Down Expand Up @@ -62,6 +63,7 @@ export default function useCryptoCurrencies() {
);
if (intentAsset) {
setSelectedAsset(intentAsset);
setIntent((prevIntent) => ({ ...prevIntent, address: undefined }));
return;
}
}
Expand All @@ -85,6 +87,7 @@ export default function useCryptoCurrencies() {
selectedAsset,
selectedChainId,
setSelectedAsset,
setIntent,
]);

return {
Expand Down

0 comments on commit 25375aa

Please sign in to comment.