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

fix: remove value from price api call #4364

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions packages/assets-controllers/src/TokenRatesController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,6 @@ describe('TokenRatesController', () => {
priceChange1d: 0,
pricePercentChange1d: 0,
tokenAddress: '0x02',
value: 0.001,
allTimeHigh: 4000,
allTimeLow: 900,
circulatingSupply: 2000,
Expand All @@ -1476,7 +1475,6 @@ describe('TokenRatesController', () => {
priceChange1d: 0,
pricePercentChange1d: 0,
tokenAddress: '0x03',
value: 0.002,
allTimeHigh: 4000,
allTimeLow: 900,
circulatingSupply: 2000,
Expand Down Expand Up @@ -1560,7 +1558,6 @@ describe('TokenRatesController', () => {
// token price in LOL = (token price in ETH) * (ETH value in LOL)
'0x02': {
tokenAddress: '0x02',
value: 0.0005,
currency: 'ETH',
pricePercentChange1d: 0,
priceChange1d: 0,
Expand All @@ -1572,7 +1569,7 @@ describe('TokenRatesController', () => {
low1d: 100,
marketCap: 1000,
marketCapPercentChange1d: 100,
price: 0.001,
price: 0.0005,
pricePercentChange14d: 100,
pricePercentChange1h: 1,
pricePercentChange1y: 200,
Expand All @@ -1583,7 +1580,6 @@ describe('TokenRatesController', () => {
},
'0x03': {
tokenAddress: '0x03',
value: 0.001,
currency: 'ETH',
pricePercentChange1d: 0,
priceChange1d: 0,
Expand All @@ -1595,7 +1591,7 @@ describe('TokenRatesController', () => {
low1d: 100,
marketCap: 1000,
marketCapPercentChange1d: 100,
price: 0.002,
price: 0.001,
pricePercentChange14d: 100,
pricePercentChange1h: 1,
pricePercentChange1y: 200,
Expand Down Expand Up @@ -2066,12 +2062,12 @@ describe('TokenRatesController', () => {
[tokenAddresses[0]]: {
currency: 'ETH',
tokenAddress: tokenAddresses[0],
value: 0.001,
price: 0.001,
},
[tokenAddresses[1]]: {
currency: 'ETH',
tokenAddress: tokenAddresses[1],
value: 0.002,
price: 0.002,
},
}),
validateCurrencySupported: jest.fn().mockReturnValue(
Expand Down Expand Up @@ -2132,13 +2128,13 @@ describe('TokenRatesController', () => {
"0x89": Object {
"0x0000000000000000000000000000000000000001": Object {
"currency": "ETH",
"price": 0.0005,
"tokenAddress": "0x0000000000000000000000000000000000000001",
"value": 0.0005,
},
"0x0000000000000000000000000000000000000002": Object {
"currency": "ETH",
"price": 0.001,
"tokenAddress": "0x0000000000000000000000000000000000000002",
"value": 0.001,
},
},
},
Expand Down Expand Up @@ -2618,7 +2614,6 @@ async function fetchTokenPricesWithIncreasingPriceForEachToken<
>((obj, tokenAddress, i) => {
const tokenPrice: TokenPrice<TokenAddress, Currency> = {
tokenAddress,
value: (i + 1) / 1000,
currency,
pricePercentChange1d: 0,
priceChange1d: 0,
Expand Down
5 changes: 2 additions & 3 deletions packages/assets-controllers/src/TokenRatesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export interface ContractExchangeRates {

type MarketDataDetails = {
tokenAddress: `0x${string}`;
value: number;
currency: string;
allTimeHigh: number;
allTimeLow: number;
Expand Down Expand Up @@ -610,8 +609,8 @@ export class TokenRatesController extends StaticIntervalPollingControllerV1<
...acc,
[tokenAddress]: {
...token,
value: token.value
? token.value * fallbackCurrencyToNativeCurrencyConversionRate
price: token.price
? token.price * fallbackCurrencyToNativeCurrencyConversionRate
: undefined,
},
};
Expand Down
1 change: 0 additions & 1 deletion packages/assets-controllers/src/assetsUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,6 @@ describe('assetsUtil', () => {
jest.spyOn(mockPriceService, 'fetchTokenPrices').mockResolvedValue({
[testTokenAddress]: {
tokenAddress: testTokenAddress,
value: 0.0004588648479937523,
currency: testNativeCurrency,
allTimeHigh: 4000,
allTimeLow: 900,
Expand Down
2 changes: 1 addition & 1 deletion packages/assets-controllers/src/assetsUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ export async function fetchTokenContractExchangeRates({
(obj, [tokenAddress, tokenPrice]) => {
return {
...obj,
[toChecksumHexAddress(tokenAddress)]: tokenPrice?.value,
[toChecksumHexAddress(tokenAddress)]: tokenPrice?.price,
};
},
{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type { Hex } from '@metamask/utils';
*/
export type TokenPrice<TokenAddress extends Hex, Currency extends string> = {
tokenAddress: TokenAddress;
value: number;
currency: Currency;
allTimeHigh: number;
allTimeLow: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ describe('CodefiTokenPricesServiceV2', () => {
expect(marketDataTokensByAddress).toStrictEqual({
'0x0000000000000000000000000000000000000000': {
tokenAddress: '0x0000000000000000000000000000000000000000',
value: 14,
currency: 'ETH',
pricePercentChange1d: 1,
priceChange1d: 1,
Expand All @@ -142,7 +141,6 @@ describe('CodefiTokenPricesServiceV2', () => {
},
'0xAAA': {
tokenAddress: '0xAAA',
value: 148.17205755299946,
currency: 'ETH',
pricePercentChange1d: 1,
priceChange1d: 1,
Expand All @@ -165,7 +163,6 @@ describe('CodefiTokenPricesServiceV2', () => {
},
'0xBBB': {
tokenAddress: '0xBBB',
value: 33689.98134554716,
currency: 'ETH',
pricePercentChange1d: 1,
priceChange1d: 1,
Expand All @@ -188,7 +185,6 @@ describe('CodefiTokenPricesServiceV2', () => {
},
'0xCCC': {
tokenAddress: '0xCCC',
value: 148.1344197578456,
currency: 'ETH',
pricePercentChange1d: 1,
priceChange1d: 1,
Expand Down Expand Up @@ -295,7 +291,6 @@ describe('CodefiTokenPricesServiceV2', () => {
expect(result).toStrictEqual({
'0x0000000000000000000000000000000000000000': {
tokenAddress: '0x0000000000000000000000000000000000000000',
value: 14,
currency: 'ETH',
pricePercentChange1d: 1,
priceChange1d: 1,
Expand All @@ -318,7 +313,6 @@ describe('CodefiTokenPricesServiceV2', () => {
},
'0xBBB': {
tokenAddress: '0xBBB',
value: 33689.98134554716,
currency: 'ETH',
pricePercentChange1d: 1,
priceChange1d: 1,
Expand All @@ -341,7 +335,6 @@ describe('CodefiTokenPricesServiceV2', () => {
},
'0xCCC': {
tokenAddress: '0xCCC',
value: 148.1344197578456,
currency: 'ETH',
pricePercentChange1d: 1,
priceChange1d: 1,
Expand Down Expand Up @@ -428,11 +421,9 @@ describe('CodefiTokenPricesServiceV2', () => {
'0xAAA': {
currency: 'ETH',
tokenAddress: '0xAAA',
value: undefined,
},
'0xBBB': {
tokenAddress: '0xBBB',
value: 33689.98134554716,
currency: 'ETH',
pricePercentChange1d: 1,
priceChange1d: 1,
Expand All @@ -455,7 +446,6 @@ describe('CodefiTokenPricesServiceV2', () => {
},
'0xCCC': {
tokenAddress: '0xCCC',
value: 148.1344197578456,
currency: 'ETH',
pricePercentChange1d: 1,
priceChange1d: 1,
Expand Down Expand Up @@ -513,19 +503,16 @@ describe('CodefiTokenPricesServiceV2', () => {
expect(result).toStrictEqual({
'0x0000000000000000000000000000000000000000': {
tokenAddress: '0x0000000000000000000000000000000000000000',
value: 14,
currency: 'ETH',
price: 14,
},
'0xBBB': {
tokenAddress: '0xBBB',
value: 33689.98134554716,
currency: 'ETH',
price: 33689.98134554716,
},
'0xCCC': {
tokenAddress: '0xCCC',
value: 148.1344197578456,
currency: 'ETH',
price: 148.1344197578456,
},
Expand Down Expand Up @@ -695,7 +682,6 @@ describe('CodefiTokenPricesServiceV2', () => {
expect(marketDataTokensByAddress).toStrictEqual({
'0x0000000000000000000000000000000000000000': {
tokenAddress: '0x0000000000000000000000000000000000000000',
value: 14,
currency: 'ETH',
pricePercentChange1d: 1,
priceChange1d: 1,
Expand All @@ -718,7 +704,6 @@ describe('CodefiTokenPricesServiceV2', () => {
},
'0xAAA': {
tokenAddress: '0xAAA',
value: 148.17205755299946,
currency: 'ETH',
pricePercentChange1d: 1,
priceChange1d: 1,
Expand All @@ -741,7 +726,6 @@ describe('CodefiTokenPricesServiceV2', () => {
},
'0xBBB': {
tokenAddress: '0xBBB',
value: 33689.98134554716,
currency: 'ETH',
pricePercentChange1d: 1,
priceChange1d: 1,
Expand All @@ -764,7 +748,6 @@ describe('CodefiTokenPricesServiceV2', () => {
},
'0xCCC': {
tokenAddress: '0xCCC',
value: 148.1344197578456,
currency: 'ETH',
pricePercentChange1d: 1,
priceChange1d: 1,
Expand Down Expand Up @@ -1842,7 +1825,6 @@ describe('CodefiTokenPricesServiceV2', () => {
expect(marketDataTokensByAddress).toStrictEqual({
'0x0000000000000000000000000000000000000000': {
tokenAddress: '0x0000000000000000000000000000000000000000',
value: 14,
currency: 'ETH',
pricePercentChange1d: 1,
priceChange1d: 1,
Expand All @@ -1865,7 +1847,6 @@ describe('CodefiTokenPricesServiceV2', () => {
},
'0xAAA': {
tokenAddress: '0xAAA',
value: 148.17205755299946,
currency: 'ETH',
pricePercentChange1d: 1,
priceChange1d: 1,
Expand All @@ -1888,7 +1869,6 @@ describe('CodefiTokenPricesServiceV2', () => {
},
'0xBBB': {
tokenAddress: '0xBBB',
value: 33689.98134554716,
currency: 'ETH',
pricePercentChange1d: 1,
priceChange1d: 1,
Expand All @@ -1911,7 +1891,6 @@ describe('CodefiTokenPricesServiceV2', () => {
},
'0xCCC': {
tokenAddress: '0xCCC',
value: 148.1344197578456,
currency: 'ETH',
pricePercentChange1d: 1,
priceChange1d: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,8 @@ export class CodefiTokenPricesServiceV2
return obj;
}

const { price } = marketData;

const token: TokenPrice<Hex, SupportedCurrency> = {
tokenAddress,
value: price,
currency,
...marketData,
};
Expand Down
Loading