Skip to content

Commit

Permalink
Tom/fix prices (#1571)
Browse files Browse the repository at this point in the history
* api: refactor the market data api

* api: refactor the market data api

* api: refactor the market data api

* wip: add log

* wip: hardcode value to run against market data api

* wip: try setting asset name

* fix: casing

* chore: add vKSM ids

* fix: handle VDOT and VKSM

* typo: quotation marks

* chore: fix switch statement and remove console log

* fix: revert change

---------

Co-authored-by: ns212 <[email protected]>
  • Loading branch information
tomjeatt and ns212 authored Sep 27, 2023
1 parent 711bc4e commit c6a55d5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 4 additions & 1 deletion api/market_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const tickers = {
"Dai Stablecoin": "dai",
"Ether": "ethereum",
"USD Coin": "usd-coin",
"tBTC v2": "tbtc"
"tBTC v2": "tbtc",
"Voucher Dot": "voucher-dot",
"Voucher KSM": "voucher-ksm"
}

// Coingecko to Dia asset ids
Expand All @@ -22,6 +24,7 @@ const dia_assets = {
"karura": "/Bifrost/518",
"tether": "/Ethereum/0xdAC17F958D2ee523a2206206994597C13D831ec7",
"voucher-dot": "/Bifrost-polkadot/2304",
"voucher-ksm": "/Bifrost/260",
"binancecoin": "/Ethereum/0xB8c77482e45F1F44dE1745F52C74426C631bDD52",
"bnb": "/Ethereum/0xB8c77482e45F1F44dE1745F52C74426C631bDD52",
"tbtc": "/Ethereum/0x18084fbA666a33d37592fA2633fD49a74DD93a88",
Expand Down
13 changes: 12 additions & 1 deletion src/hooks/api/use-get-prices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,25 @@ import { useGetCurrencies } from './use-get-currencies';
// MEMO: Returns `undefined` for currencies without coingecko ID.
const getCoingeckoId = (currency: CurrencyExt) => {
if (isForeignAsset(currency)) {
return currency.foreignAsset.coingeckoId;
// TODO: This is a temporary fix to force V[DOT/KSM] prices. We need to refactor the lib to return an id
// even when a CoinGecko id doesn't exist. We also need to remove references to CoinGecko ids; this
// doesn't make sense/is very confusing now that we use DIA as our primary price source.
switch (currency.ticker) {
case 'VDOT':
return 'voucher-dot';
case 'VKSM':
return 'voucher-ksm';
default:
return currency.foreignAsset.coingeckoId;
}
}
return COINGECKO_ID_BY_CURRENCY_TICKER[currency.ticker];
};

const composeIds = (currencies: CurrencyExt[]): string =>
currencies.reduce((acc, currency) => {
const coingeckoId = getCoingeckoId(currency);
console.log('coingeckoId', coingeckoId);
if (!coingeckoId) {
return acc;
}
Expand Down

2 comments on commit c6a55d5

@vercel
Copy link

@vercel vercel bot commented on c6a55d5 Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on c6a55d5 Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.