Skip to content

Commit e0c7e16

Browse files
authored
fix: update caching logic (#854)
1 parent 790da99 commit e0c7e16

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

packages/checkout/sdk/src/client/blockscout.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,10 @@ describe('Blockscout', () => {
110110
const token = BlockscoutTokenType.ERC20;
111111
const client = new Blockscout({ chainId: ChainId.IMTBL_ZKEVM_TESTNET });
112112

113-
await client.getTokensByWalletAddress({ walletAddress: '0x1234567890', tokenType: token });
114-
await client.getTokensByWalletAddress({ walletAddress: '0x1234567890', tokenType: token });
113+
const precache = await client.getTokensByWalletAddress({ walletAddress: '0x1234567890', tokenType: token });
114+
const cached = await client.getTokensByWalletAddress({ walletAddress: '0x1234567890', tokenType: token });
115+
116+
expect(cached).toEqual(precache);
115117

116118
expect(mockedAxios.get).toHaveBeenNthCalledWith(
117119
1,
@@ -278,8 +280,10 @@ describe('Blockscout', () => {
278280

279281
const client = new Blockscout({ chainId: ChainId.IMTBL_ZKEVM_TESTNET });
280282

281-
await client.getNativeTokenByWalletAddress({ walletAddress: '0x1234567890' });
282-
await client.getNativeTokenByWalletAddress({ walletAddress: '0x1234567890' });
283+
const precache = await client.getNativeTokenByWalletAddress({ walletAddress: '0x1234567890' });
284+
const cached = await client.getNativeTokenByWalletAddress({ walletAddress: '0x1234567890' });
285+
286+
expect(cached).toEqual(precache);
283287

284288
expect(mockedAxios.get).toHaveBeenNthCalledWith(
285289
1,

packages/checkout/sdk/src/client/blockscout.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ export class Blockscout {
100100
if (params.nextPage) url += `&${new URLSearchParams(params.nextPage as Record<string, string>)}`;
101101

102102
// Cache response data to prevent unnecessary requests
103-
const cached = this.getCache(url) as AxiosResponse;
104-
if (cached && cached.status < 400) return Promise.resolve(cached.data);
103+
const cached = this.getCache(url);
104+
if (cached) return Promise.resolve(cached);
105105

106106
const response = await Blockscout.makeHttpRequest(url);
107107
if (response.status >= 400) {
@@ -146,8 +146,8 @@ export class Blockscout {
146146
const url = `${this.url}/api/v2/addresses/${params.walletAddress}`;
147147

148148
// Cache response data to prevent unnecessary requests
149-
const cached = this.getCache(url) as AxiosResponse;
150-
if (cached && cached.status < 400) return Promise.resolve(cached.data);
149+
const cached = this.getCache(url);
150+
if (cached) return Promise.resolve(cached);
151151

152152
const response = await Blockscout.makeHttpRequest(url);
153153
if (response.status >= 400) {

0 commit comments

Comments
 (0)