Skip to content

Commit 3764d0a

Browse files
authored
fix: not fetching price
1 parent 7a0c779 commit 3764d0a

File tree

2 files changed

+31
-30
lines changed

2 files changed

+31
-30
lines changed

src/constants/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ export const CONTRACTS = {
88

99
// Time intervals (in ms)
1010
export const INTERVALS = {
11-
FETCH_DATA: 300000 as const, // 5 minutes
12-
BLOCK_RANGE: 8640 as const, // Number of blocks to look back
11+
FETCH_DATA: 120_000 as const, // 2 minutes
1312
} as const;
1413

1514
export const CACHE_DURATION = 5 * 60 * 1000; // 5 minutes in milliseconds

src/services/onchain-data.service.ts

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -230,37 +230,39 @@ export class OnchainDataService implements OnModuleInit {
230230
}
231231

232232
private async fetchToken(address: Address): Promise<IToken> {
233-
if (address in this.tokens) return this.tokens[address];
234-
235-
const tokenCalls = [
236-
{
237-
...this.getContract(address, erc20Abi),
238-
functionName: 'symbol',
239-
},
240-
{
241-
...this.getContract(address, erc20Abi),
242-
functionName: 'name',
243-
},
244-
{
245-
...this.getContract(address, erc20Abi),
246-
functionName: 'decimals',
247-
},
248-
];
249-
250-
const [symbolResult, nameResult, decimalsResult] = await this.publicClient.multicall({
251-
contracts: tokenCalls,
252-
});
253-
254-
const token: IToken = {
255-
name: nameResult.result as string,
256-
symbol: symbolResult.result as string,
233+
234+
const token = this.tokens[address];
235+
let symbolResult, nameResult, decimalsResult;
236+
if (!token) {
237+
const tokenCalls = [
238+
{
239+
...this.getContract(address, erc20Abi),
240+
functionName: 'symbol',
241+
},
242+
{
243+
...this.getContract(address, erc20Abi),
244+
functionName: 'name',
245+
},
246+
{
247+
...this.getContract(address, erc20Abi),
248+
functionName: 'decimals',
249+
},
250+
];
251+
[symbolResult, nameResult, decimalsResult] = await this.publicClient.multicall({
252+
contracts: tokenCalls,
253+
});
254+
}
255+
256+
const symbol = token ? token.symbol : symbolResult.result as string;
257+
this.tokens[address] = {
258+
name: token ? token.name : nameResult.result as string,
259+
symbol,
257260
contractAddress: address,
258-
usdPrice: await this.coingeckoService.getCoinPrice(symbolResult.result as string),
259-
decimals: decimalsResult.result as number,
261+
usdPrice: await this.coingeckoService.getCoinPrice(symbol),
262+
decimals: token ? token.decimals : decimalsResult.result as number,
260263
};
261264

262-
this.tokens[address] = token;
263-
return token;
265+
return this.tokens[address];
264266
}
265267

266268
public async onModuleInit(): Promise<void> {

0 commit comments

Comments
 (0)