Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: show default validators #8736

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/fuzzy-forks-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@ledgerhq/coin-cardano": patch
"ledger-live-desktop": patch
---

Show default validators for cardano
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Props = {

const ValidatorField = ({ account, delegation, onChangeValidator, selectedPoolId }: Props) => {
const [currentPool, setCurrentPool] = useState<Array<StakePool>>([]);
const [defaultPool, setDefaultPool] = useState<Array<StakePool>>([]);
const unit = useAccountUnit(account);
const [showAll, setShowAll] = useState(false);
const [ledgerPoolsLoading, setLedgerPoolsLoading] = useState(false);
Expand All @@ -45,12 +46,16 @@ 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);
setCurrentPool([apiRes.pools[0]]);
const filteredPools = apiRes.pools.filter(pool => LEDGER_POOL_IDS.includes(pool.poolId));
setDefaultPool(filteredPools);
const filteredLedgerPools = apiRes.pools.filter(
pool => pool.poolId !== delegation?.poolId,
pool => pool.poolId === delegation?.poolId,
);
if (filteredLedgerPools.length) {
onChangeValidator(filteredLedgerPools[0]);
Expand All @@ -64,10 +69,15 @@ const ValidatorField = ({ account, delegation, onChangeValidator, selectedPoolId
}, []);

useEffect(() => {
const selectedPool = pools.find(p => p.poolId === selectedPoolId);
const selectedPool =
pools.find(p => p.poolId === selectedPoolId) ||
defaultPool.find(pool => pool.poolId === selectedPoolId);

if (selectedPool) {
setCurrentPool([selectedPool]);
onChangeValidator(selectedPool);
if (pools.some(p => p.poolId === selectedPoolId)) {
onChangeValidator(selectedPool);
}
}

// eslint-disable-next-line react-hooks/exhaustive-deps
Expand All @@ -84,7 +94,10 @@ const ValidatorField = ({ account, delegation, onChangeValidator, selectedPoolId
key={validatorIdx + validator.poolId}
pool={validator}
unit={unit}
active={selectedPoolId === validator.poolId || validator.poolId === delegation?.poolId}
active={
selectedPoolId === validator.poolId ||
(validator.poolId === delegation?.poolId && validator.poolId === selectedPoolId)
}
onClick={onChangeValidator}
/>
);
Expand All @@ -107,6 +120,7 @@ const ValidatorField = ({ account, delegation, onChangeValidator, selectedPoolId
showAll
? [
currentPool[0],
...defaultPool.filter(p => p !== currentPool[0]),
...pools.filter(
p =>
p &&
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;
}
Loading