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

chore(ramp): upgrade sdk to v2.0.3 #13257

Closed
wants to merge 7 commits into from
Closed

Conversation

georgeweiler
Copy link
Contributor

@georgeweiler georgeweiler commented Jan 29, 2025

Description

This upgrades @consensys/on-ramp-sdk to 2.0.3, which is a major version change that updates the getQuotes and getSellQuotes interfaces.

Related issues

Manual testing steps

  1. Go to ramps experience and click "get quotes"
  2. confirm that quotes are loading without any issues

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.

@georgeweiler georgeweiler added the team-ramp issues related to Ramp features label Jan 29, 2025
@georgeweiler georgeweiler requested review from a team as code owners January 29, 2025 18:53
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.

@metamaskbot metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label Jan 29, 2025
Copy link

socket-security bot commented Jan 29, 2025

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

Package New capabilities Transitives Size Publisher
npm/@consensys/[email protected] 🔁 npm/@consensys/[email protected] None 0 417 kB consensys-npm

View full report↗︎

@georgeweiler georgeweiler removed the INVALID-PR-TEMPLATE PR's body doesn't match template label Jan 29, 2025
Comment on lines 137 to 149
let quotes = null;

const {
data: quotes,
data,
isFetching: isFetchingQuotes,
error: ErrorFetchingQuotes,
query: fetchQuotes,
} = useQuotes(params.amount);

if (data) {
quotes = data.quotes;
}

Copy link
Member

Choose a reason for hiding this comment

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

Do this reassignment inside useQuotes, the hook must be reusable and to use it the consumer should not be aware of the data.quotes assignment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

would you suggest that additional metadata properties are extracted, then? This change was made in anticipation of accessing properties like data.sorted. We could do it the way I've done, or something like this:

  const {
    quotes,
    sorted,
    isFetching: isFetchingQuotes,
    error: ErrorFetchingQuotes,
    query: fetchQuotes,
  } = useQuotes(params.amount);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

or perhaps we could do something like:

 const {
    data: { quotes,  sorted },
    isFetching: isFetchingQuotes,
    error: ErrorFetchingQuotes,
    query: fetchQuotes,
  } = useQuotes(params.amount);

but we would have to change the interface of data which can be null, currently

Copy link
Member

Choose a reason for hiding this comment

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

Like your first comment 👌

@wachunei wachunei changed the title feat: upgrades ramp-sdk to v2.0.3 chore(ramp): upgrade sdk to v2.0.3 Jan 30, 2025
Comment on lines +24 to +27
const quotes = useMemo(() => data?.quotes || null, [data]);

return {
data,
quotes,
Copy link
Member

Choose a reason for hiding this comment

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

useMemo is not needed,

for now the only change needed is

  return {
    data: data?.quotes,

And make sure data.quotes is correctly typed as data was before ((QuoteResponse | QuoteError)[] | (QuoteError | SellQuoteResponse)[] | null)

Copy link
Member

Choose a reason for hiding this comment

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

I noticed the type changed to (QuoteResponse | QuoteError)[] | (QuoteError | SellQuoteResponse)[] | undefined

@AxelGes what is the reason for that? it should be just nesting the type in a quotes property 🤔

The only change needed in app/components/UI/Ramp/Views/Quotes/Quotes.test.tsx would be

  it('calls setOptions when rendering', async () => {
    mockUseQuotesValues = {
      ...mockUseQuotesInitialValues,
      isFetching: true,
-      data: null,
+      data: undefined,
    };
    render(Quotes);
    expect(mockSetOptions).toBeCalledTimes(1);
  });

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm a little confused with the suggestion. 😅 Maybe I misunderstood, but didn't we decide in an earlier comment that the useQuotes interface should now spread the data object and become this?

 return {
    quotes,
    // sorted,
    // otherMetadataInTheFuture,
    isFetching,
    error,
    query,
  };

If we want to keep it as data for now, that's fine but I just updated it to be the other way, so looking for some clarification.

If we only updated it to be this:

return {
    data: data?.quotes,
     isFetching,
    error,
    query,
}
  1. it's not spreading the data obj like we decided
  2. It's risking data to be undefined and not null

Copy link
Member

@wachunei wachunei Jan 30, 2025

Choose a reason for hiding this comment

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

Sorry, later I noticed this step is the backwards compatible one and the other data is not there yet, so to minimize changes we only need these from my last comment.

diff --git a/app/components/UI/Ramp/Views/Quotes/Quotes.test.tsx b/app/components/UI/Ramp/Views/Quotes/Quotes.test.tsx
index 22c84f9f7a..d7ea969ad8 100644
--- a/app/components/UI/Ramp/Views/Quotes/Quotes.test.tsx
+++ b/app/components/UI/Ramp/Views/Quotes/Quotes.test.tsx
@@ -159,7 +159,7 @@ describe('Quotes', () => {
     mockUseQuotesValues = {
       ...mockUseQuotesInitialValues,
       isFetching: true,
-      data: null,
+      data: undefined,
     };
     render(Quotes);
     expect(mockSetOptions).toBeCalledTimes(1);
@@ -200,7 +200,7 @@ describe('Quotes', () => {
     mockUseQuotesValues = {
       ...mockUseQuotesInitialValues,
       isFetching: true,
-      data: null,
+      data: undefined,
     };
     render(Quotes);
     const fetchingQuotesText = screen.getByText('Fetching quotes');
diff --git a/app/components/UI/Ramp/hooks/useQuotes.ts b/app/components/UI/Ramp/hooks/useQuotes.ts
index eea4950794..070ad16d9d 100644
--- a/app/components/UI/Ramp/hooks/useQuotes.ts
+++ b/app/components/UI/Ramp/hooks/useQuotes.ts
@@ -21,7 +21,7 @@ function useQuotes(amount: number | string) {
   );
 
   return {
-    data,
+    data: data?.quotes,
     isFetching,
     error,
     query,

This is enough along with the package.json bump.

It's risking data to be undefined and not null

Yeah not sure about this type change, it is coming from the SDK, however for mobile it would work either way since it checks for null-ish values and not specifically null

@wachunei
Copy link
Member

wachunei commented Feb 4, 2025

Superseded by #13318

@wachunei wachunei closed this Feb 4, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Feb 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
team-ramp issues related to Ramp features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants