Skip to content

Commit

Permalink
CVS live-countervalues performance evolutions (#6771)
Browse files Browse the repository at this point in the history
* chore(countervalues): Add live-config fields

- refresh rate
- marketcap batching

* chore(countervalues): switch refreshRate to 1min default (remote conf)

* chore(countervalues): introduce hybrid batch fetching mecanism

LIVE-11864

* chore(countervalues): switch to /v3/supported/crypto

* chore: changeset

* chore(cvs): upgrade to v3 API for fetchSupportedFiatsTokens()

* chore: remove useless log

* chore: add all missing fiats (and apply fixes from currency changes)

* chore: fix tests

* chore: fix fiat loading logic to handle new coins that aren't in local list
  • Loading branch information
gre committed May 6, 2024
1 parent d9ddfcd commit 6c35cc5
Show file tree
Hide file tree
Showing 23 changed files with 365 additions and 110 deletions.
12 changes: 12 additions & 0 deletions .changeset/beige-starfishes-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@ledgerhq/cryptoassets": patch
"@ledgerhq/live-countervalues-react": patch
"ledger-live-desktop": patch
"live-mobile": patch
"@ledgerhq/live-common": patch
"@ledgerhq/live-countervalues": patch
"@ledgerhq/coin-framework": patch
"@ledgerhq/live-cli": patch
---

LL's preferred countervalues will now have all the possible fiats that our CVS api supports.
8 changes: 8 additions & 0 deletions .changeset/green-bags-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@ledgerhq/live-countervalues-react": patch
"ledger-live-desktop": patch
"@ledgerhq/live-countervalues": patch
"@ledgerhq/coin-framework": patch
---

Countervalues API: upgrade to v3 for fetching supported fiats
10 changes: 10 additions & 0 deletions .changeset/swift-penguins-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@ledgerhq/live-countervalues-react": patch
"ledger-live-desktop": patch
"live-mobile": patch
"@ledgerhq/live-common": patch
"@ledgerhq/live-countervalues": patch
"@ledgerhq/live-cli": patch
---

Countervalues performance evolutions. (8min -> 1min refresh rate, more efficient http calls caching,..)
2 changes: 2 additions & 0 deletions apps/cli/src/commands/blockchain/botTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ export default {
const countervaluesState = await loadCountervalues(initialState, {
trackingPairs: inferTrackingPairForAccounts(accounts, countervalue),
autofillGaps: true,
refreshRate: 60000,
marketCapBatchingAfterRank: 20,
});

await promiseAllBatched(CONCURRENT, accounts, async account => {
Expand Down
2 changes: 2 additions & 0 deletions apps/cli/src/commands/live/countervalues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ export default {
})),
),
autofillGaps: !opts.disableAutofillGaps,
refreshRate: 60000,
marketCapBatchingAfterRank: 20,
});
// eslint-disable-next-line no-console
if (opts.verbose) console.log(cvs);
Expand Down
2 changes: 2 additions & 0 deletions apps/cli/src/commands/live/portfolio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export default {
loadCountervalues(initialState, {
trackingPairs: inferTrackingPairForAccounts(accounts, countervalue as Currency),
autofillGaps: !opts.disableAutofillGaps,
refreshRate: 60000,
marketCapBatchingAfterRank: 20,
}),
).pipe(
map(state => {
Expand Down
5 changes: 5 additions & 0 deletions apps/ledger-live-desktop/src/renderer/actions/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
import { resolveTrackingPairs } from "@ledgerhq/live-countervalues/logic";
import { useExtraSessionTrackingPair } from "./deprecated/ondemand-countervalues";
import { useMarketPerformanceTrackingPairs } from "./marketperformance";
import { LiveConfig } from "@ledgerhq/live-config/LiveConfig";

// provide redux states via custom hook wrapper

Expand Down Expand Up @@ -130,6 +131,10 @@ export function useCalculateCountervaluesUserSettings(): CountervaluesSettings {
() => ({
trackingPairs,
autofillGaps: true,
refreshRate: LiveConfig.getValueByKey("countervalues_refreshRate"),
marketCapBatchingAfterRank: LiveConfig.getValueByKey(
"countervalues_marketCapBatchingAfterRank",
),
}),
[trackingPairs],
);
Expand Down
124 changes: 62 additions & 62 deletions apps/ledger-live-desktop/tests/specs/market/market.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,71 +52,71 @@ test("Market", async ({ page }) => {
await expect.soft(page).toHaveScreenshot("market-page-no-scrollbar.png", maskItems);
});

await page.route(`${getEnv("LEDGER_COUNTERVALUES_API")}/v2/supported-to`, async route => {
await page.route(`${getEnv("LEDGER_COUNTERVALUES_API")}/v3/supported/fiat`, async route => {
route.fulfill({
headers: { teststatus: "mocked" },
body: JSON.stringify([
"aed",
"ars",
"aud",
"bch",
"bdt",
"bhd",
"bits",
"bmd",
"bnb",
"brl",
"btc",
"cad",
"chf",
"clp",
"cny",
"czk",
"dkk",
"dot",
"eos",
"eth",
"eur",
"gbp",
"hkd",
"huf",
"idr",
"ils",
"inr",
"jpy",
"krw",
"kwd",
"link",
"lkr",
"ltc",
"mmk",
"mxn",
"myr",
"ngn",
"nok",
"nzd",
"php",
"pkr",
"pln",
"rub",
"sar",
"sats",
"sek",
"sgd",
"thb",
"try",
"twd",
"uah",
"usd",
"vef",
"vnd",
"xag",
"xau",
"xdr",
"xlm",
"xrp",
"yfi",
"zar",
"AED",
"ARS",
"AUD",
"BCH",
"BDT",
"BHD",
"BITS",
"BMD",
"BNB",
"BRL",
"BTC",
"CAD",
"CHF",
"CLP",
"CNY",
"CZK",
"DKK",
"DOT",
"EOS",
"ETH",
"EUR",
"GBP",
"HKD",
"HUF",
"IDR",
"ILS",
"INR",
"JPY",
"KRW",
"KWD",
"LINK",
"LKR",
"LTC",
"MMK",
"MXN",
"MYR",
"NGN",
"NOK",
"NZD",
"PHP",
"PKR",
"PLN",
"RUB",
"SAR",
"SATS",
"SEK",
"SGD",
"THB",
"TRY",
"TWD",
"UAH",
"USD",
"VEF",
"VND",
"XAG",
"XAU",
"XDR",
"XLM",
"XRP",
"YFI",
"ZAR",
]),
});
});
Expand Down
5 changes: 5 additions & 0 deletions apps/ledger-live-mobile/src/actions/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { accountsSelector } from "../reducers/accounts";
import { counterValueCurrencySelector, orderAccountsSelector } from "../reducers/settings";
import { clearBridgeCache } from "../bridge/cache";
import { flushAll } from "../components/DBSave";
import { LiveConfig } from "@ledgerhq/live-config/LiveConfig";

const extraSessionTrackingPairsChanges: BehaviorSubject<TrackingPair[]> = new BehaviorSubject<
TrackingPair[]
Expand Down Expand Up @@ -102,6 +103,10 @@ export function useUserSettings() {
() => ({
trackingPairs,
autofillGaps: true,
refreshRate: LiveConfig.getValueByKey("countervalues_refreshRate"),
marketCapBatchingAfterRank: LiveConfig.getValueByKey(
"countervalues_marketCapBatchingAfterRank",
),
}),
[trackingPairs],
);
Expand Down
12 changes: 5 additions & 7 deletions libs/coin-framework/src/currencies/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
getFiatCurrencyByTicker,
getCryptoCurrencyById,
hasCryptoCurrencyId,
hasFiatCurrencyTicker,
} from "@ledgerhq/cryptoassets";
import { CryptoCurrency, CryptoCurrencyId, FiatCurrency } from "@ledgerhq/types-cryptoassets";
import { getEnv } from "@ledgerhq/live-env";
Expand Down Expand Up @@ -56,23 +57,20 @@ async function initializeUserSupportedFiats() {
let supportedTokens = [] as string[];

if (remoteSupportedTokens.length !== 0) {
remoteSupportedTokens.forEach(id => {
const token = id.toUpperCase();
if (locallySupportedFiats.includes(token)) {
remoteSupportedTokens.forEach(token => {
if (hasFiatCurrencyTicker(token)) {
supportedTokens.push(token);
}
});
} else {
supportedTokens = locallySupportedFiats;
}
userSupportedFiats = supportedTokens.map(id => {
return getFiatCurrencyByTicker(id);
});
userSupportedFiats = supportedTokens.map(getFiatCurrencyByTicker);
}

export async function fetchSupportedFiatsTokens(): Promise<string[]> {
try {
const response = await fetch(`${getEnv("LEDGER_COUNTERVALUES_API")}/v2/supported-to`, {
const response = await fetch(`${getEnv("LEDGER_COUNTERVALUES_API")}/v3/supported/fiat`, {
method: "GET",
headers: {
accept: "application/json",
Expand Down
2 changes: 2 additions & 0 deletions libs/ledger-live-common/src/__tests__/csvExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ test("export CSV", async () => {
startDate: new Date(Date.now() - 200 * 24 * 60 * 60 * 1000),
})),
autofillGaps: false,
refreshRate: 60000,
marketCapBatchingAfterRank: 20,
});
const accounts = currencies.map(currency =>
genAccount(`${currency.id}_export`, {
Expand Down
2 changes: 2 additions & 0 deletions libs/ledger-live-common/src/bot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ export async function bot({ disabled, filter }: Arg = {}): Promise<void> {
const countervaluesState = await loadCountervalues(initialState, {
trackingPairs: inferTrackingPairForAccounts(allAccountsAfter, usd),
autofillGaps: true,
refreshRate: 60000,
marketCapBatchingAfterRank: 20,
}).catch(e => {
if (process.env.CI) console.error(e);
countervaluesError = e;
Expand Down
12 changes: 12 additions & 0 deletions libs/ledger-live-common/src/config/sharedConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,23 @@ import { tronConfig } from "../families/tron/config";
import { vechainConfig } from "../families/vechain/config";
import { appConfig } from "../apps/config";

const countervaluesConfig: ConfigSchema = {
countervalues_refreshRate: {
type: "number",
default: 60 * 1000,
},
countervalues_marketCapBatchingAfterRank: {
type: "number",
default: 20,
},
};

const liveCommonConfig: ConfigSchema = {
...appConfig,
};

export const liveConfig: ConfigSchema = {
...countervaluesConfig,
...liveCommonConfig,
...algorandConfig,
...bitcoinConfig,
Expand Down
Loading

0 comments on commit 6c35cc5

Please sign in to comment.