-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
+206
−18
Closed
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6195a9e
feat: upgrades ramp-sdk to v2.0.3
georgeweiler 750bf40
chore: add carrot to ramp-sdk version
georgeweiler bc76792
Merge branch 'main' into feat/ramp-sdk-2.0.3
georgeweiler ed80a29
chore: updates yarn lockfile
georgeweiler 9d669fc
Merge branch 'feat/ramp-sdk-2.0.3' of github.com:MetaMask/metamask-mo…
georgeweiler 519535c
refactor: updates usequote hook interface and write test
georgeweiler b505bc1
chore: fixes yarn lock issues
georgeweiler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
import { RampSDK } from '../sdk'; | ||
import useSDKMethod from './useSDKMethod'; | ||
import { renderHookWithProvider } from '../../../../util/test/renderWithProvider'; | ||
import useQuotes from './useQuotes'; | ||
|
||
type DeepPartial<BaseType> = { | ||
[key in keyof BaseType]?: DeepPartial<BaseType[key]>; | ||
}; | ||
|
||
const mockuseRampSDKInitialValues: DeepPartial<RampSDK> = { | ||
selectedRegion: { id: 'test-region-id' }, | ||
selectedPaymentMethodId: 'test-payment-method-id', | ||
selectedAsset: { id: 'test-crypto-id' }, | ||
selectedFiatCurrencyId: 'test-fiat-currency-id-1', | ||
selectedAddress: 'test-address', | ||
isBuy: true, | ||
}; | ||
|
||
let mockUseRampSDKValues: DeepPartial<RampSDK> = { | ||
...mockuseRampSDKInitialValues, | ||
}; | ||
|
||
jest.mock('../sdk', () => ({ | ||
useRampSDK: () => mockUseRampSDKValues, | ||
})); | ||
|
||
jest.mock('./useSDKMethod'); | ||
|
||
describe('useQuotes', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mockUseRampSDKValues = { | ||
...mockuseRampSDKInitialValues, | ||
}; | ||
}); | ||
|
||
it('calls useSDKMethod with the correct parameters for buy', () => { | ||
(useSDKMethod as jest.Mock).mockReturnValue([ | ||
{ | ||
data: { quotes: [] }, | ||
error: null, | ||
isFetching: false, | ||
}, | ||
jest.fn(), | ||
]); | ||
renderHookWithProvider(() => useQuotes(100)); | ||
|
||
expect(useSDKMethod).toHaveBeenCalledWith( | ||
'getQuotes', | ||
'test-region-id', | ||
'test-payment-method-id', | ||
'test-crypto-id', | ||
'test-fiat-currency-id-1', | ||
100, | ||
'test-address', | ||
); | ||
}); | ||
|
||
it('calls useSDKMethod with the correct parameters for sell', () => { | ||
mockUseRampSDKValues.isBuy = false; | ||
(useSDKMethod as jest.Mock).mockReturnValue([ | ||
{ | ||
data: { quotes: [] }, | ||
error: null, | ||
isFetching: false, | ||
}, | ||
jest.fn(), | ||
]); | ||
renderHookWithProvider(() => useQuotes(100)); | ||
|
||
expect(useSDKMethod).toHaveBeenCalledWith( | ||
'getSellQuotes', | ||
'test-region-id', | ||
'test-payment-method-id', | ||
'test-crypto-id', | ||
'test-fiat-currency-id-1', | ||
100, | ||
'test-address', | ||
); | ||
}); | ||
|
||
it('returns loading state if fetching quotes', () => { | ||
const mockQuery = jest.fn(); | ||
(useSDKMethod as jest.Mock).mockReturnValue([ | ||
{ | ||
data: null, | ||
error: null, | ||
isFetching: true, | ||
}, | ||
mockQuery, | ||
]); | ||
const { result } = renderHookWithProvider(() => useQuotes(100)); | ||
expect(result.current).toEqual({ | ||
quotes: null, | ||
isFetching: true, | ||
error: null, | ||
query: mockQuery, | ||
}); | ||
}); | ||
|
||
it('returns error state if there is an error fetching quotes', () => { | ||
const mockQuery = jest.fn(); | ||
(useSDKMethod as jest.Mock).mockReturnValue([ | ||
{ | ||
data: null, | ||
error: 'error-fetching-quotes', | ||
isFetching: false, | ||
}, | ||
mockQuery, | ||
]); | ||
const { result } = renderHookWithProvider(() => useQuotes(100)); | ||
expect(result.current).toEqual({ | ||
quotes: null, | ||
isFetching: false, | ||
error: 'error-fetching-quotes', | ||
query: mockQuery, | ||
}); | ||
}); | ||
|
||
it('returns quotes if fetching is successful', () => { | ||
const mockQuery = jest.fn(); | ||
(useSDKMethod as jest.Mock).mockReturnValue([ | ||
{ | ||
data: { quotes: [{ id: 'quote-1' }, { id: 'quote-2' }] }, | ||
error: null, | ||
isFetching: false, | ||
}, | ||
mockQuery, | ||
]); | ||
const { result } = renderHookWithProvider(() => useQuotes(100)); | ||
expect(result.current).toEqual({ | ||
quotes: [{ id: 'quote-1' }, { id: 'quote-2' }], | ||
isFetching: false, | ||
error: null, | ||
query: mockQuery, | ||
}); | ||
}); | ||
|
||
it('handles different amount types (string and number)', () => { | ||
const mockQuery = jest.fn(); | ||
(useSDKMethod as jest.Mock).mockReturnValue([ | ||
{ | ||
data: { quotes: [{ id: 'quote-1' }] }, | ||
error: null, | ||
isFetching: false, | ||
}, | ||
mockQuery, | ||
]); | ||
|
||
const { result: resultNumber } = renderHookWithProvider(() => | ||
useQuotes(100), | ||
); | ||
expect(resultNumber.current.quotes).toEqual([{ id: 'quote-1' }]); | ||
|
||
const { result: resultString } = renderHookWithProvider(() => | ||
useQuotes('100'), | ||
); | ||
expect(resultString.current.quotes).toEqual([{ id: 'quote-1' }]); | ||
}); | ||
|
||
it('updates correctly when parameters change', () => { | ||
const mockQuery = jest.fn(); | ||
(useSDKMethod as jest.Mock).mockReturnValue([ | ||
{ | ||
data: { quotes: [{ id: 'quote-1' }] }, | ||
error: null, | ||
isFetching: false, | ||
}, | ||
mockQuery, | ||
]); | ||
|
||
const { result, rerender } = renderHookWithProvider(() => useQuotes(100)); | ||
expect(result.current.quotes).toEqual([{ id: 'quote-1' }]); | ||
|
||
(useSDKMethod as jest.Mock).mockReturnValue([ | ||
{ | ||
data: { quotes: [{ id: 'quote-2' }] }, | ||
error: null, | ||
isFetching: false, | ||
}, | ||
mockQuery, | ||
]); | ||
rerender(() => useQuotes(200)); | ||
expect(result.current.quotes).toEqual([{ id: 'quote-2' }]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
And make sure
data.quotes
is correctly typed asdata
was before ((QuoteResponse | QuoteError)[] | (QuoteError | SellQuoteResponse)[] | null
)There was a problem hiding this comment.
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 beThere was a problem hiding this comment.
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 thedata
object and become this?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:
There was a problem hiding this comment.
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.
This is enough along with the package.json bump.
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