Skip to content

Commit

Permalink
fix: reported bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
paeeglee committed Oct 14, 2024
1 parent 62f780c commit 8eb4be6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
13 changes: 12 additions & 1 deletion packages/api/src/server/storage/quote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class QuoteStorage {

private async addQuotes(): Promise<void> {
const { assets, assetsMapById, QuotesMock } = await getAssetsMaps();
if (isDevMode) {
if (!isDevMode) {
await this.addMockQuotes(QuotesMock);
return;
}
Expand Down Expand Up @@ -121,6 +121,17 @@ export class QuoteStorage {
return Array.from(quotes);
}

public async getActiveQuotes(): Promise<Record<string, number>> {
const result = await RedisReadClient.scan(`${PREFIX}-*`);
const quotes = {};

result.forEach((value, key) => {
quotes[key.replace(`${PREFIX}-`, '')] = Number(value);
});

return quotes;
}

static start() {
const _this = new QuoteStorage();
_this.addQuotes();
Expand Down
9 changes: 8 additions & 1 deletion packages/api/src/utils/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,20 @@ const calculateBalanceUSD = async (
let balanceUSD = 0;
const { fuelUnitAssets } = await getAssetsMaps();

const quotes = await App.getInstance()._quoteCache.getActiveQuotes();

balances?.forEach(async balance => {
let priceUSD = 0;

const units = fuelUnitAssets(chainId, balance.assetId);
const formattedAmount = balance.amount.format({
units,
});

const priceUSD = await App.getInstance()._quoteCache.getQuote(balance.assetId);
if (quotes[balance.assetId]) {
priceUSD = quotes[balance.assetId];
}

balanceUSD += parseFloat(formattedAmount) * priceUSD;
});

Expand Down

0 comments on commit 8eb4be6

Please sign in to comment.