Skip to content

Commit

Permalink
fix: changeset and move logic in getPools
Browse files Browse the repository at this point in the history
  • Loading branch information
qperrot committed Dec 11, 2024
1 parent d99c3e9 commit ca721e3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
"@ledgerhq/coin-cardano": minor
"ledger-live-desktop": minor
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,10 @@ const ValidatorField = ({ account, delegation, onChangeValidator, selectedPoolId
useEffect(() => {
if (LEDGER_POOL_IDS.length) {
setLedgerPoolsLoading(true);
fetchPoolDetails(account.currency, LEDGER_POOL_IDS)
const delegationPoolId = delegation?.poolId ? [delegation.poolId] : [];
fetchPoolDetails(account.currency, delegationPoolId, LEDGER_POOL_IDS)
.then((apiRes: { pools: Array<StakePool> }) => {
const filteredPool = apiRes.pools.filter(pool => pool.poolId === delegation?.poolId);
const firstFilteredPool = filteredPool.at(0);
const firstApiResPool = apiRes.pools.at(0);
if (firstFilteredPool) {
setCurrentPool([firstFilteredPool]);
} else if (firstApiResPool) {
setCurrentPool([firstApiResPool]);
} else {
setCurrentPool([]);
}
setCurrentPool(apiRes.pools);
const filteredLedgerPools = apiRes.pools.filter(
pool => pool.poolId !== delegation?.poolId,
);
Expand All @@ -70,6 +62,17 @@ const ValidatorField = ({ account, delegation, onChangeValidator, selectedPoolId
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

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

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedPoolId]);

const onSearch = useCallback(
(evt: React.ChangeEvent<HTMLInputElement>) => setSearchQuery(evt.target.value),
[setSearchQuery],
Expand Down Expand Up @@ -102,14 +105,16 @@ const ValidatorField = ({ account, delegation, onChangeValidator, selectedPoolId
<ScrollLoadingList
data={
showAll
? pools.filter(p => p && !poolIdsToFilterFromAllPools.includes(p.poolId))
: pools.filter(
p => p?.poolId === selectedPoolId || p?.poolId === delegation?.poolId,
).length > 0
? pools.filter(
p => p?.poolId === selectedPoolId || p?.poolId === delegation?.poolId,
)
: currentPool
? [
currentPool[0],
...pools.filter(
p =>
p &&
!poolIdsToFilterFromAllPools.includes(p.poolId) &&
p !== currentPool[0],
),
]
: currentPool
}
style={{
flex: showAll ? "1 0 256px" : "1 0 64px",
Expand Down
14 changes: 13 additions & 1 deletion libs/coin-modules/coin-cardano/src/api/getPools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,25 @@ 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 res = await network({
method: "GET",
url: isTestnet(currency)
? `${CARDANO_TESTNET_API_ENDPOINT}/v1/pool/detail`
: `${CARDANO_API_ENDPOINT}/v1/pool/detail`,
params: { poolIds },
params: { poolIds: currentPoolIds },
});
if (!res || (res.data as APIGetPoolsDetail).pools.length === 0) {
const newRes = await network({
method: "GET",
url: isTestnet(currency)
? `${CARDANO_TESTNET_API_ENDPOINT}/v1/pool/detail`
: `${CARDANO_API_ENDPOINT}/v1/pool/detail`,
params: { poolIds: ledgerPoolIds },
});
return newRes && (newRes.data as APIGetPoolsDetail);
}
return res && (res.data as APIGetPoolsDetail);
}

0 comments on commit ca721e3

Please sign in to comment.