Skip to content

Commit

Permalink
Merge pull request #8067 from LedgerHQ/hotfix/staking-modal-hide-empt…
Browse files Browse the repository at this point in the history
…y-filters

EARN: hide category filter when providers' list is empty
  • Loading branch information
KVNLS authored Oct 11, 2024
2 parents d0c2599 + bde70f9 commit 3cff5ae
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
7 changes: 7 additions & 0 deletions .changeset/beige-planes-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"live-mobile": patch
"@ledgerhq/native-ui": patch
---

On Earn's Staking Modal, it makes it so that a category filter will only show up if there's at least one provider of that category.
Small visual fix to the gap in the options' spacing
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,18 @@ export const StakeModal = ({ account, source }: Props) => {

const [selected, setSelected] = useState<Option>("all");

const filteredProviders = useMemo(() => (providers ?? []).filter(x => !x.disabled), [providers]);
const optionValues = useMemo(
() => OPTION_VALUES.filter(x => x === "all" || filteredProviders.some(y => y.category === x)),
[filteredProviders],
);

const formattedProviders = useMemo(
() =>
(providers ?? [])
.filter(x => !x.disabled && (selected === "all" || selected === x.category))
filteredProviders
.filter(x => selected === "all" || selected === x.category)
.sort(hasMinValidatorEth ? descending : ascending),
[providers, hasMinValidatorEth, selected],
[filteredProviders, hasMinValidatorEth, selected],
);

const scrollableContainerRef = useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -96,8 +102,8 @@ export const StakeModal = ({ account, source }: Props) => {
{t("ethereum.stake.title")}
</Text>
<Flex flexDirection="row" alignItems="center" height="24px" columnGap={2} mb={3}>
{OPTION_VALUES.map((x, i) => {
const checked = i === OPTION_VALUES.indexOf(selected);
{optionValues.map((x, i) => {
const checked = i === optionValues.indexOf(selected);
return (
<Button
borderRadius={2}
Expand Down
22 changes: 14 additions & 8 deletions apps/ledger-live-mobile/src/families/evm/StakingDrawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,26 @@ function Content({ accountId, has32Eth, providers }: Props) {
const { t } = useTranslation();
const { theme: themeName, colors } = useTheme();

const filteredProviders = useMemo(() => (providers ?? []).filter(x => !x.disabled), [providers]);
const optionValues = useMemo(
() => OPTION_VALUES.filter(x => x === "all" || filteredProviders.some(y => y.category === x)),
[filteredProviders],
);

const [selectedIndex, setSelectedIndex] = useState(0);
const selected = OPTION_VALUES[selectedIndex];
const selected = optionValues[selectedIndex];

const OPTION_LABELS = useMemo(
() => OPTION_VALUES.map(value => t(`stake.ethereum.category.${value}.name`)),
[t],
() => optionValues.map(value => t(`stake.ethereum.category.${value}.name`)),
[t, optionValues],
);

const listProvidersSorted: ListProvider[] = useMemo(
() =>
providers
filteredProviders
.sort(has32Eth ? descending : ascending)
.filter(x => !x.disabled && (selected === "all" || selected === x.category)),
[has32Eth, providers, selected],
.filter(x => selected === "all" || selected === x.category),
[has32Eth, filteredProviders, selected],
);

return (
Expand All @@ -88,13 +94,13 @@ function Content({ accountId, has32Eth, providers }: Props) {
activeBg={colors.primary.c80}
activeColor={colors.neutral.c00}
inactiveColor={colors.neutral.c100}
gap={4}
gap={8}
inactiveBg={colors.neutral.c40}
activeIndex={selectedIndex}
onChange={index => {
setSelectedIndex(index);
track(BUTTON_CLICKED_TRACK_EVENT, {
button: `filter_${OPTION_VALUES[index]}`,
button: `filter_${optionValues[index]}`,
});
}}
stretchItems={false}
Expand Down
2 changes: 1 addition & 1 deletion libs/ui/packages/native/src/components/Tabs/Chip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const TabBox = styled(TouchableOpacity)<
>`
text-align: center;
flex-grow: ${(p) => (p.stretchItems ? "1" : "0")};
margin: auto;
${(p) => (p.stretchItems ? "margin: auto;" : "margin: auto 0;")}
padding: ${(p) => p.theme.space[p.size === "small" ? 3 : 5]}px;
border-radius: 8px;
background-color: ${(p) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export const TabsContainer = styled(FlexBox)<{ stretchItems: boolean }>`
size: undefined;
flex-direction: row;
width: 100%;
align-items: ${(p) => (p.stretchItems ? "stretch" : "center")};
align-items: stretch;
${(p) => (p.stretchItems ? "" : "justify-content: center;")}
`;

const TemplateTabsGroup = ({
Expand Down

0 comments on commit 3cff5ae

Please sign in to comment.