Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tokens search discovery controller #13111

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

Bigshmow
Copy link

@Bigshmow Bigshmow commented Jan 22, 2025

Description

This PR introduces the @metamask/token-search-discovery-controller to mobile. The package provides token search functionality via the Portfolio API & Moralis, which will enable the front end to implement a token search view.

We have created a factory function to introduce the class into Engine context, and redux selectors and a custom hook were added as well as some tests.

See MMPD-1504 MMPD-1526 in Jira for added context.

Related issues

Fixes:

Manual testing steps

  1. This change introduces a dependency and the functionality to implement the search tokens feature but does not implement it herein, so I don't think there is a need for manual testing steps.

Screenshots/Recordings

Before

After

Pre-merge author checklist

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.

Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@Bigshmow Bigshmow changed the title Add tokens search discovery controller feat: add tokens search discovery controller Jan 22, 2025
@Bigshmow Bigshmow added the Run Smoke E2E Triggers smoke e2e on Bitrise label Jan 22, 2025
Copy link
Contributor

github-actions bot commented Jan 22, 2025

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: 02b04ed
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/372d049b-9ead-4aaa-b2b1-4227411aa4c0

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Tip

  • Check the documentation if you have any doubts on how to understand the failure on bitrise

Copy link

socket-security bot commented Jan 22, 2025

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@metamask/[email protected] network 0 55.3 kB metamaskbot

View full report↗︎

Copy link

socket-security bot commented Jan 22, 2025

👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

Ignoring: npm/@metamask/[email protected]

View full report↗︎

Next steps

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of ecosystem/package-name@version specifiers. e.g. @SocketSecurity ignore npm/[email protected] or ignore all packages with @SocketSecurity ignore-all

@Bigshmow Bigshmow added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Jan 22, 2025
Copy link
Contributor

github-actions bot commented Jan 22, 2025

https://bitrise.io/ Bitrise

✅✅✅ pr_smoke_e2e_pipeline passed on Bitrise! ✅✅✅

Commit hash: ab3aa5b
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/56b818a8-f0ba-4d4f-81b4-d34834eeb739

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

@Bigshmow
Copy link
Author

@SocketSecurity ignore npm/@metamask/[email protected]

@Bigshmow Bigshmow marked this pull request as ready for review January 22, 2025 19:26
@Bigshmow Bigshmow requested review from a team as code owners January 22, 2025 19:26
Bigshmow added a commit to MetaMask/core that referenced this pull request Jan 28, 2025
…s path (#5195)

## Explanation

<!--
Thanks for your contribution! Take a moment to answer these questions so
that reviewers have the information they need to properly understand
your changes:

* What is the current state of things and why does it need to change?
* What is the solution your changes offer and how does it work?
* Are there any changes whose purpose might not obvious to those
unfamiliar with the domain?
* If your primary goal was to update one package but you found you had
to update another one along the way, why did you do so?
* If you had to upgrade a dependency, why did you do so?
-->

The `/tokens-search/name` endpoint has changed to `/tokens-search` to
better reflect it's usecase in
[PR-75](consensys-vertical-apps/va-mmcx-portfolio-api#75)
in the portfolio api. The endpoint searches by both name and address of
tokens from Moralis. Simply "/name" was misleading.

We also updated the param "name" to "query" to better reflect the nature
of the request.

## References

<!--
Are there any issues that this pull request is tied to?
Are there other links that reviewers should consult to understand these
changes better?
Are there client or consumer pull requests to adopt any breaking
changes?

For example:

* Fixes #12345
* Related to #67890
-->

## Changelog

<!--
If you're making any consumer-facing changes, list those changes here as
if you were updating a changelog, using the template below as a guide.

(CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or
FIXED. For security-related issues, follow the Security Advisory
process.)

Please take care to name the exact pieces of the API you've added or
changed (e.g. types, interfaces, functions, or methods).

If there are any breaking changes, make sure to offer a solution for
consumers to follow once they upgrade to the changes.

Finally, if you're only making changes to development scripts or tests,
you may replace the template below with "None".
-->

### `@metamask/token-search-discover-controller`

- **Added**: The logoUrl is now exposed in TokenSearchResponseItem via
`searchTokens`
- **Breaking**:
- Update the TokenSearchApiService to use the updated URL for
`searchTokens`
    - The URL is now `/tokens-search` instead of `/tokens-search/name`
  - Changed the "name" parameter to "query" in the `searchTokens` method
- These updates align with the Portfolio API's `/tokens-search` endpoint
- The old endpoint `/tokens-search/name` will remain in a deprecated
state until parity across apps is achieved which for now is the
portfolio-api and core repos. The mobile
[PR-13111](MetaMask/metamask-mobile#13111) is
not yet merged.

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've highlighted breaking changes using the "BREAKING" category
above as appropriate
- [x] I've prepared draft pull requests for clients and consumer
packages to resolve any breaking changes
@Bigshmow Bigshmow added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Jan 28, 2025
Copy link
Contributor

github-actions bot commented Jan 28, 2025

https://bitrise.io/ Bitrise

✅✅✅ pr_smoke_e2e_pipeline passed on Bitrise! ✅✅✅

Commit hash: 9d394d4
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/ed4831b0-1243-4b2e-973f-715c69d62f3c

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

@Bigshmow Bigshmow added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Jan 28, 2025
Copy link
Contributor

github-actions bot commented Jan 28, 2025

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: d8019b7
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/c408a38f-6572-4a9c-866c-44e38b03a52e

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Tip

  • Check the documentation if you have any doubts on how to understand the failure on bitrise

@Bigshmow Bigshmow added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Jan 28, 2025
Copy link
Contributor

github-actions bot commented Jan 28, 2025

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: 69421f1
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/e6ced72e-377e-42a9-96a2-a39d11ccd2d2

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Tip

  • Check the documentation if you have any doubts on how to understand the failure on bitrise

@Bigshmow Bigshmow added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Jan 28, 2025
Copy link
Contributor

github-actions bot commented Jan 28, 2025

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: b767d50
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/3b85f843-23ce-4671-9284-0f96b66991cd

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Tip

  • Check the documentation if you have any doubts on how to understand the failure on bitrise

@Bigshmow Bigshmow added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Jan 28, 2025
@salimtb salimtb added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Jan 29, 2025
@Bigshmow Bigshmow added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Jan 29, 2025
Copy link
Contributor

github-actions bot commented Jan 29, 2025

https://bitrise.io/ Bitrise

✅✅✅ pr_smoke_e2e_pipeline passed on Bitrise! ✅✅✅

Commit hash: 35f5cab
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/19e05089-41c9-407e-97f6-664ebbd54250

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

import { selectRecentTokenSearches } from '../../../selectors/tokenSearchDiscoveryController';
import { TokenSearchParams } from '@metamask/token-search-discovery-controller/dist/types.cjs';

export const useTokenSearchDiscovery = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One important consideration: If the searchTokens hook is triggered with every change to the search parameters (e.g., when TokenSearchParams contains a search string and the user rapidly types "testToken"), would this execute the search logic individually for each character input?

If this is the intended behavior, I recommend implementing debouncing. However, let's first confirm whether each keystroke indeed triggers a separated call, as this would help determine if the debounce optimization is necessary to prevent excessive execution during rapid input.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope to keep the controller itself as close to single responsibility as we can so as to not confuse callers let's agree to introduce that debounce here in the consuming app. It's a good idea, thanks; however I'm not sure on exact implementation yet (re: each key press). Either way I see a useDebouncedValue hook that might help here, is that what you suggest?
Something like:

const SEARCH_DEBOUNCE_DELAY = 300;

const searchTokens = useCallback(async (params: TokenSearchParams) => {
    const debouncedParams = useDebouncedValue(params, SEARCH_DEBOUNCE_DELAY);
    const { TokenSearchDiscoveryController } = Engine.context;
    return await TokenSearchDiscoveryController.searchTokens(debouncedParams);
  }, []);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Run Smoke E2E Triggers smoke e2e on Bitrise team-portfolio
Projects
Status: Needs dev review
Development

Successfully merging this pull request may close these issues.

3 participants