Skip to content

Commit

Permalink
fix: delegation showless
Browse files Browse the repository at this point in the history
  • Loading branch information
qperrot committed Dec 20, 2024
1 parent a69bfc0 commit 37bd39a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/hungry-ravens-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ledger-live-desktop": patch
---

Choosing a new provider outside the ledger one is now displayed in the modal
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useValidators } from "@ledgerhq/live-common/families/solana/react";
import { ValidatorsAppValidator } from "@ledgerhq/live-common/families/solana/staking";
import { SolanaAccount } from "@ledgerhq/live-common/families/solana/types";

import React, { useState, useCallback } from "react";
import React, { useState, useCallback, useEffect } from "react";
import { Trans } from "react-i18next";
import styled from "styled-components";
import Box from "~/renderer/components/Box";
Expand All @@ -23,6 +23,8 @@ type Props = {
const ValidatorField = ({ account, onChangeValidator, chosenVoteAccAddr }: Props) => {
const [search, setSearch] = useState("");
const [showAll, setShowAll] = useState(false);
const [currentValidator, setCurrentValidator] = useState<ValidatorsAppValidator[]>([]);

const unit = useAccountUnit(account);
const validators = useValidators(account.currency, search);

Expand All @@ -31,6 +33,21 @@ const ValidatorField = ({ account, onChangeValidator, chosenVoteAccAddr }: Props
[setSearch],
);

useEffect(() => {
const selectedVoteAccAddr = validators.find(p => p.voteAccount === chosenVoteAccAddr);
if (selectedVoteAccAddr) {
const isDefault = validators.slice(0, 2).includes(selectedVoteAccAddr);
if (isDefault) {
setCurrentValidator([selectedVoteAccAddr]);
}
setCurrentValidator([
selectedVoteAccAddr,
...validators.slice(0, 2).filter(v => v !== selectedVoteAccAddr),
]);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [chosenVoteAccAddr]);

const renderItem = (validator: ValidatorsAppValidator) => {
return (
<ValidatorRow
Expand All @@ -49,7 +66,13 @@ const ValidatorField = ({ account, onChangeValidator, chosenVoteAccAddr }: Props
<ValidatorsFieldContainer>
<Box p={1} data-testid="validator-list">
<ScrollLoadingList
data={showAll ? validators : validators.slice(0, 2)}
data={
showAll
? validators
: currentValidator.length > 0
? currentValidator
: validators.slice(0, 2)
}
style={{
flex: showAll ? "1 0 240px" : "1 0 126px",
marginBottom: 0,
Expand Down

0 comments on commit 37bd39a

Please sign in to comment.