Skip to content

Commit

Permalink
Merge pull request #309 from bnb-chain/wenty/aggregator
Browse files Browse the repository at this point in the history
fix: Fix token price issue
  • Loading branch information
wenty22 authored Feb 7, 2025
2 parents d06b210 + 8d94386 commit 23e1081
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .release/.changeset/big-candles-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bnb-chain/canonical-bridge-widget": patch
---

Clear input if timeout
1 change: 1 addition & 0 deletions .release/.changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"@bnb-chain/canonical-bridge-widget": "0.5.18"
},
"changesets": [
"big-candles-breathe",
"blue-goats-shave",
"brown-suits-matter",
"curvy-dingos-end",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,6 @@ export class TokenService {
tokenAddress,
);

this.logger.log(
`[token price] ${chainId} ${tokenAddress} ${tokenSymbol}, cmc platform: ${cmcPlatform}, llama platform: ${llamaPlatform}`,
);

const reqArr: Promise<any>[] = [];
if (cmcToken) {
reqArr.push(this.web3Service.getCryptoCurrencyQuotes(cmcToken.id.toString()));
Expand All @@ -191,25 +187,22 @@ export class TokenService {
const [cmcRes, llamaRes] = await Promise.allSettled(reqArr);
if (cmcRes.status === 'fulfilled') {
const price = cmcRes.value?.[0]?.quote?.USD?.price;
this.logger.log(`[cmc price] ${price}`);
if (price !== undefined) {
return Number(price);
}
}
if (llamaRes.status === 'fulfilled' && llamaRes.value?.coins) {
const price = Object.values<ICoinPrice>(llamaRes.value.coins ?? {})?.[0]?.price;
this.logger.log(`[llama price] ${price}`);
if (price !== undefined) {
return Number(price);
}
}

const cmcPrices = await this.cache.get(`${CACHE_KEY.CMC_CONFIG_V2}`);
const llamaPrices = await this.cache.get(`${CACHE_KEY.CMC_CONFIG_V2}`);
const llamaPrices = await this.cache.get(`${CACHE_KEY.LLAMA_CONFIG_V2}`);
const key = `1:${tokenSymbol?.toLowerCase()}`;

const price = cmcPrices?.[key]?.price ?? llamaPrices?.[key]?.price;
this.logger.log(`[cache price] ${price}`);
return price;
}
}
6 changes: 6 additions & 0 deletions packages/canonical-bridge-widget/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @bnb-chain/canonical-bridge-widget

## 0.6.0-alpha.20

### Patch Changes

- Clear input if timeout

## 0.6.0-alpha.19

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/canonical-bridge-widget/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bnb-chain/canonical-bridge-widget",
"version": "0.6.0-alpha.19",
"version": "0.6.0-alpha.20",
"description": "canonical bridge widget",
"author": "bnb-chain",
"private": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import { MIN_SOL_TO_ENABLED_TX } from '@/core/constants';
import { FailedToGetQuoteModal } from '@/modules/transfer/components/Modal/FailedToGetQuoteModal';
import { FeeTimeoutModal } from '@/modules/transfer/components/Modal/FeeTimeoutModal';
import { useFailGetQuoteModal } from '@/modules/transfer/hooks/modal/useFailGetQuoteModal';
import { useAppDispatch, useAppSelector } from '@/modules/store/StoreProvider';
import { useAppSelector } from '@/modules/store/StoreProvider';
import { useSummaryModal } from '@/modules/transfer/hooks/modal/useSummaryModal';
import { useFeeLoadTimeout } from '@/modules/transfer/hooks/modal/useFeeLoadTimeout';
import { setSendValue } from '@/modules/transfer/action';

export const TransferButtonGroup = () => {
const [hash, setHash] = useState<string | null>(null);
Expand All @@ -29,8 +28,6 @@ export const TransferButtonGroup = () => {
const isFeeTimeoutModalOpen = useAppSelector((state) => state.transfer.isFeeTimeoutModalOpen);
const isSummaryModalOpen = useAppSelector((state) => state.transfer.isSummaryModalOpen);

const dispatch = useAppDispatch();

const {
isOpen: isSubmittedModalOpen,
onOpen: onOpenSubmittedModal,
Expand Down Expand Up @@ -106,13 +103,7 @@ export const TransferButtonGroup = () => {
isOpen={isFailedGetQuoteModalOpen}
onClose={onCloseFailedGetQuoteModal}
/>
<FeeTimeoutModal
isOpen={isFeeTimeoutModalOpen}
onClose={() => {
dispatch(setSendValue(''));
onCloseFeeTimeoutModal();
}}
/>
<FeeTimeoutModal isOpen={isFeeTimeoutModalOpen} onClose={onCloseFeeTimeoutModal} />
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useCallback } from 'react';

import { useAppDispatch } from '@/modules/store/StoreProvider';
import { setIsFeeTimeoutModalOpen } from '@/modules/transfer/action';
import { setSendValue } from '@/modules/transfer/action';

export const useFeeLoadTimeout = () => {
const dispatch = useAppDispatch();
Expand All @@ -12,6 +13,7 @@ export const useFeeLoadTimeout = () => {

const onCloseFeeTimeoutModal = useCallback(() => {
dispatch(setIsFeeTimeoutModalOpen(false));
dispatch(setSendValue(''));
}, [dispatch]);
return {
onOpenFeeTimeoutModal,
Expand Down

0 comments on commit 23e1081

Please sign in to comment.