Skip to content

Commit

Permalink
fix: show default validators on show less
Browse files Browse the repository at this point in the history
  • Loading branch information
qperrot committed Dec 18, 2024
1 parent b552a94 commit 3b553ee
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .changeset/eleven-planes-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@ledgerhq/coin-cardano": patch
"ledger-live-desktop": patch
---

Fix Cardano to show the default validators when clicking on Show Less
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ const ValidatorField = ({ account, delegation, onChangeValidator, selectedPoolId
useEffect(() => {
if (LEDGER_POOL_IDS.length) {
setLedgerPoolsLoading(true);
const delegationPoolId = delegation?.poolId ? [delegation.poolId] : [];
fetchPoolDetails(account.currency, delegationPoolId, LEDGER_POOL_IDS)
const delegationPoolId = delegation?.poolId
? [...[delegation.poolId], ...LEDGER_POOL_IDS]
: LEDGER_POOL_IDS;
fetchPoolDetails(account.currency, delegationPoolId)
.then((apiRes: { pools: Array<StakePool> }) => {
setCurrentPool(apiRes.pools);
const filteredLedgerPools = apiRes.pools.filter(
Expand All @@ -66,7 +68,13 @@ const ValidatorField = ({ account, delegation, onChangeValidator, selectedPoolId
useEffect(() => {
const selectedPool = pools.find(p => p.poolId === selectedPoolId);
if (selectedPool) {
setCurrentPool([selectedPool]);
const firstElement = currentPool[0];
const shouldRemoveFirst =
firstElement.poolId !== delegation?.poolId &&
!LEDGER_POOL_IDS.includes(firstElement.poolId);

const newPool = shouldRemoveFirst ? currentPool.slice(1) : currentPool;
setCurrentPool([selectedPool, ...newPool]);
onChangeValidator(selectedPool);
}

Expand Down
7 changes: 1 addition & 6 deletions libs/coin-modules/coin-cardano/src/api/getPools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,13 @@ export async function fetchPoolList(
export async function fetchPoolDetails(
currency: CryptoCurrency,
poolIds: Array<string>,
ledgerPoolIds?: Array<string>,
): Promise<APIGetPoolsDetail> {
const currentPoolIds = poolIds.length == 0 ? ledgerPoolIds : poolIds;
const { data } = await network<APIGetPoolsDetail>({
method: "GET",
url: isTestnet(currency)
? `${CARDANO_TESTNET_API_ENDPOINT}/v1/pool/detail`
: `${CARDANO_API_ENDPOINT}/v1/pool/detail`,
params: { poolIds: currentPoolIds },
params: { poolIds },
});
if (data.pools.length === 0 && ledgerPoolIds) {
return fetchPoolDetails(currency, ledgerPoolIds);
}
return data;
}

0 comments on commit 3b553ee

Please sign in to comment.