Skip to content

Commit

Permalink
Fix CacheDir for token prices (#823)
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorgomezv committed Nov 2, 2023
1 parent d98ea80 commit 9b612ca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/datasources/cache/cache.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ export class CacheRouter {
fiatCode: string;
}): CacheDir {
return new CacheDir(
`${args.nativeCoinId}_${CacheRouter.NATIVE_COIN_PRICE_KEY}`,
args.fiatCode,
`${args.nativeCoinId}_${CacheRouter.NATIVE_COIN_PRICE_KEY}_${args.fiatCode}`,
'',
);
}

Expand All @@ -449,8 +449,8 @@ export class CacheRouter {
tokenAddress: string;
}): CacheDir {
return new CacheDir(
`${args.chainName}_${CacheRouter.TOKEN_PRICE_KEY}`,
`${args.tokenAddress}_${args.fiatCode}`,
`${args.chainName}_${CacheRouter.TOKEN_PRICE_KEY}_${args.tokenAddress}_${args.fiatCode}`,
'',
);
}

Expand Down
18 changes: 12 additions & 6 deletions src/datasources/prices-api/coingecko-api.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ describe('CoingeckoAPI', () => {
expect(assetPrice).toBe(expectedAssetPrice);
expect(mockCacheFirstDataSource.get).toBeCalledWith({
cacheDir: new CacheDir(
`${chainName}_token_price`,
`${tokenAddress}_${fiatCode}`,
`${chainName}_token_price_${tokenAddress}_${fiatCode}`,
'',
),
networkRequest: {
headers: {
Expand Down Expand Up @@ -146,8 +146,8 @@ describe('CoingeckoAPI', () => {
expect(assetPrice).toBe(expectedAssetPrice);
expect(mockCacheFirstDataSource.get).toBeCalledWith({
cacheDir: new CacheDir(
`${chainName}_token_price`,
`${tokenAddress}_${fiatCode}`,
`${chainName}_token_price_${tokenAddress}_${fiatCode}`,
'',
),
networkRequest: {
params: {
Expand All @@ -170,7 +170,10 @@ describe('CoingeckoAPI', () => {
await service.getNativeCoinPrice({ nativeCoinId, fiatCode });

expect(mockCacheFirstDataSource.get).toBeCalledWith({
cacheDir: new CacheDir(`${nativeCoinId}_native_coin_price`, fiatCode),
cacheDir: new CacheDir(
`${nativeCoinId}_native_coin_price_${fiatCode}`,
'',
),
url: `${coingeckoBaseUri}/simple/price`,
networkRequest: {
headers: {
Expand Down Expand Up @@ -200,7 +203,10 @@ describe('CoingeckoAPI', () => {
await service.getNativeCoinPrice({ nativeCoinId, fiatCode });

expect(mockCacheFirstDataSource.get).toBeCalledWith({
cacheDir: new CacheDir(`${nativeCoinId}_native_coin_price`, fiatCode),
cacheDir: new CacheDir(
`${nativeCoinId}_native_coin_price_${fiatCode}`,
'',
),
url: `${coingeckoBaseUri}/simple/price`,
networkRequest: {
params: {
Expand Down

0 comments on commit 9b612ca

Please sign in to comment.