Skip to content

Commit

Permalink
exclude fields from token list fetch (#4235)
Browse files Browse the repository at this point in the history
## Explanation

Adds 2 query parameters when fetching token lists:
- `includeERC20Permit=false`
- `includeStorage=false`

The best I can tell, neither field is used by extension or mobile. So
we'll instead take the reduction in network usage (~5KB on mainnet) and
controller state.

## References

https://consensyssoftware.atlassian.net/browse/API-1186

## Changelog

### `@metamask/assets-controllers`

- **BREAKING**: `TokenListController` no longer includes the fields
`storage` and `erc20Permit` in its state.

## Checklist

- [ ] I've updated the test suite for new or updated code as appropriate
- [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [ ] I've highlighted breaking changes using the "BREAKING" category
above as appropriate
  • Loading branch information
bergeron authored May 31, 2024
1 parent 0b3ed43 commit 26d4fe4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1343,5 +1343,5 @@ describe('TokenListController', () => {
function getTokensPath(chainId: Hex) {
return `/tokens/${convertHexToDecimal(
chainId,
)}?occurrenceFloor=3&includeNativeAssets=false&includeDuplicateSymbolAssets=false&includeTokenFees=false&includeAssetType=false`;
)}?occurrenceFloor=3&includeNativeAssets=false&includeDuplicateSymbolAssets=false&includeTokenFees=false&includeAssetType=false&includeERC20Permit=false&includeStorage=false`;
}
12 changes: 6 additions & 6 deletions packages/assets-controllers/src/token-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ describe('Token service', () => {
const { signal } = new AbortController();
nock(TOKEN_END_POINT_API)
.get(
`/tokens/${sampleDecimalChainId}?occurrenceFloor=3&includeNativeAssets=false&includeDuplicateSymbolAssets=false&includeTokenFees=false&includeAssetType=false`,
`/tokens/${sampleDecimalChainId}?occurrenceFloor=3&includeNativeAssets=false&includeDuplicateSymbolAssets=false&includeTokenFees=false&includeAssetType=false&includeERC20Permit=false&includeStorage=false`,
)
.reply(200, sampleTokenList)
.persist();
Expand All @@ -260,7 +260,7 @@ describe('Token service', () => {

nock(TOKEN_END_POINT_API)
.get(
`/tokens/${lineaChainId}?occurrenceFloor=1&includeNativeAssets=false&includeDuplicateSymbolAssets=false&includeTokenFees=false&includeAssetType=false`,
`/tokens/${lineaChainId}?occurrenceFloor=1&includeNativeAssets=false&includeDuplicateSymbolAssets=false&includeTokenFees=false&includeAssetType=false&includeERC20Permit=false&includeStorage=false`,
)
.reply(200, sampleTokenListLinea)
.persist();
Expand All @@ -274,7 +274,7 @@ describe('Token service', () => {
const abortController = new AbortController();
nock(TOKEN_END_POINT_API)
.get(
`/tokens/${sampleDecimalChainId}?occurrenceFloor=3&includeNativeAssets=false&includeDuplicateSymbolAssets=false&includeTokenFees=false&includeAssetType=false`,
`/tokens/${sampleDecimalChainId}?occurrenceFloor=3&includeNativeAssets=false&includeDuplicateSymbolAssets=false&includeTokenFees=false&includeAssetType=false&includeERC20Permit=false&includeStorage=false`,
)
// well beyond time it will take to abort
.delay(ONE_SECOND_IN_MILLISECONDS)
Expand All @@ -294,7 +294,7 @@ describe('Token service', () => {
const { signal } = new AbortController();
nock(TOKEN_END_POINT_API)
.get(
`/tokens/${sampleDecimalChainId}?occurrenceFloor=3&includeNativeAssets=false&includeDuplicateSymbolAssets=false&includeTokenFees=false&includeAssetType=false`,
`/tokens/${sampleDecimalChainId}?occurrenceFloor=3&includeNativeAssets=false&includeDuplicateSymbolAssets=false&includeTokenFees=false&includeAssetType=false&includeERC20Permit=false&includeStorage=false`,
)
.replyWithError('Example network error')
.persist();
Expand All @@ -308,7 +308,7 @@ describe('Token service', () => {
const { signal } = new AbortController();
nock(TOKEN_END_POINT_API)
.get(
`/tokens/${sampleDecimalChainId}?occurrenceFloor=3&includeNativeAssets=false&includeDuplicateSymbolAssets=false&includeTokenFees=false&includeAssetType=false`,
`/tokens/${sampleDecimalChainId}?occurrenceFloor=3&includeNativeAssets=false&includeDuplicateSymbolAssets=false&includeTokenFees=false&includeAssetType=false&includeERC20Permit=false&includeStorage=false`,
)
.reply(500)
.persist();
Expand All @@ -322,7 +322,7 @@ describe('Token service', () => {
const { signal } = new AbortController();
nock(TOKEN_END_POINT_API)
.get(
`/tokens/${sampleDecimalChainId}?occurrenceFloor=3&includeNativeAssets=false&includeDuplicateSymbolAssets=false&includeTokenFees=false&includeAssetType=false`,
`/tokens/${sampleDecimalChainId}?occurrenceFloor=3&includeNativeAssets=false&includeDuplicateSymbolAssets=false&includeTokenFees=false&includeAssetType=false&includeERC20Permit=false&includeStorage=false`,
)
// well beyond timeout
.delay(ONE_SECOND_IN_MILLISECONDS)
Expand Down
2 changes: 1 addition & 1 deletion packages/assets-controllers/src/token-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function getTokensURL(chainId: Hex) {
const occurrenceFloor = chainId === ChainId['linea-mainnet'] ? 1 : 3;
return `${TOKEN_END_POINT_API}/tokens/${convertHexToDecimal(
chainId,
)}?occurrenceFloor=${occurrenceFloor}&includeNativeAssets=false&includeDuplicateSymbolAssets=false&includeTokenFees=false&includeAssetType=false`;
)}?occurrenceFloor=${occurrenceFloor}&includeNativeAssets=false&includeDuplicateSymbolAssets=false&includeTokenFees=false&includeAssetType=false&includeERC20Permit=false&includeStorage=false`;
}

/**
Expand Down

0 comments on commit 26d4fe4

Please sign in to comment.