Skip to content

Commit

Permalink
feat: improve stake accounts ui
Browse files Browse the repository at this point in the history
  • Loading branch information
icfor committed Mar 28, 2024
1 parent e1331b7 commit e111c8c
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const PopOver = ({
const networkNetworkId = networkKeyToNetworkId[network.key as NetworkKey];
const stakingNetworkId = networkKeyToNetworkId[network.key as NetworkKey];
const nodeRef = useRef<HTMLDivElement | null>(null);
const [isContentFocused, setIsContentFocused] = useState(false);

const stakingRef = useStakingRef();

Expand Down Expand Up @@ -142,7 +143,7 @@ const PopOver = ({
}, [stakingRef, stakingNetworkId]);

// @TODO: Remove
const [, rerender] = useState(0);
const [rerenderKey, rerender] = useState(0);

const accountsWithDelegations = accounts?.filter(accountHasDelegations);
const accountsWithRewards = accounts?.filter(accountHasRewards);
Expand All @@ -169,8 +170,12 @@ const PopOver = ({
Rerender
</button>
{network.name && <div className={styles.name}>{network.name}</div>}
<StakingDataBox network={network} />
{!!networkSummary && (
<StakingDataBox
key={rerenderKey}
network={network}
onFocusContent={setIsContentFocused}
/>
{!!networkSummary && !isContentFocused && (
<div className={styles.dataBox}>
{(() => {
const votingPower = (() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,41 @@
0 8px 22px rgba(2, 38, 225, 0.12),
0 14px 64px rgba(2, 38, 225, 0.12);
}

.header {
display: flex;
flex-direction: row;
justify-content: space-between;
padding: 8px 12px;
}

.nav {
background: transparent;
border: none;
transform: rotate(90deg);
}

.headerCopy {
align-items: center;
display: flex;
flex-direction: row;
font-size: 16px;
font-weight: 600;
gap: 4px;
letter-spacing: 0.002em;
line-height: 20px;
text-align: left;
transform: translateX(-8px);
}

.stakeAccountsNum {
align-items: center;
background: #8484ea;
border-radius: 50%;
color: #fff;
display: flex;
justify-content: center;
min-height: 30px;
min-width: 30px;
padding: 2px;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import useTranslation from "next-translate/useTranslation";
import type { PropsWithChildren } from "react";
import { useEffect, useMemo } from "react";

import IconChevron from "@src/components/icons/icon_chevron.svg";
import { useStakingRef } from "@src/screens/staking/lib/staking_sdk/context";
import { fetchCoinPriceForNetwork } from "@src/screens/staking/lib/staking_sdk/context/actions";
import type { NetworkClaimableRewards } from "@src/screens/staking/lib/staking_sdk/context/selectors";
Expand All @@ -20,6 +22,10 @@ import type { Network, NetworkKey } from "@src/utils/network_info";

import * as styles from "./stake_accounts.module.scss";

export const StakeAccountsNum = ({ children }: PropsWithChildren) => (
<div className={styles.stakeAccountsNum}>{children}</div>
);

type Props = {
network: Network;
onClose: () => void;
Expand Down Expand Up @@ -83,9 +89,14 @@ const StakeAccounts = ({ network, onClose }: Props) => {

return (
<div>
<div>
<button onClick={onClose}>{"<"}</button> {t("accounts")}{" "}
{stakeAccounts?.length}
<div className={styles.header}>
<span className={styles.headerCopy}>
<button className={styles.nav} onClick={onClose}>
<IconChevron />
</button>{" "}
{t("accounts")}
</span>
<StakeAccountsNum>{stakeAccounts?.length}</StakeAccountsNum>
</div>
<div>
{stakeAccounts?.map((account) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
padding: 12px 16px;
width: 100%;

.stakeAccounts,
.unbonding,
.rewards,
.total {
Expand Down Expand Up @@ -63,3 +64,15 @@
text-shadow: $box-shadow-variant-3;
}
}

.nav {
background: transparent;
border: none;
transform: rotate(-90deg);
}

.navWrapper {
align-items: center;
display: flex;
flex-direction: row;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import useTranslation from "next-translate/useTranslation";
import { useEffect, useMemo, useState } from "react";

import IconChevron from "@src/components/icons/icon_chevron.svg";
import { tooltipId } from "@src/components/tooltip";
import { useStakingRef } from "@src/screens/staking/lib/staking_sdk/context";
import { fetchCoinPriceForNetwork } from "@src/screens/staking/lib/staking_sdk/context/actions";
Expand All @@ -22,14 +23,15 @@ import {
import type { StakeAccount } from "@src/screens/staking/lib/staking_sdk/staking_client_types";
import type { Network, NetworkKey } from "@src/utils/network_info";

import StakeAccounts from "./stake_accounts";
import StakeAccounts, { StakeAccountsNum } from "./stake_accounts";
import * as styles from "./staking_data_box.module.scss";

type PopOverProps = {
network: Network;
onFocusContent: (isFocused: boolean) => void;
};

const StakingDataBox = ({ network }: PopOverProps) => {
const StakingDataBox = ({ network, onFocusContent }: PopOverProps) => {
const stakingNetworkId = networkKeyToNetworkId[network.key as NetworkKey];

const [isDisplayingStakeAccounts, setIsDisplayingStakeAccounts] =
Expand All @@ -39,6 +41,11 @@ const StakingDataBox = ({ network }: PopOverProps) => {

const { t } = useTranslation("staking");

const setStakeAccountsDisplay = (isDisplayed: boolean) => {
setIsDisplayingStakeAccounts(isDisplayed);
onFocusContent(isDisplayed);
};

const { claimableRewards, stakeAccounts, stakedData, unbondingTokens } =
useMemo(() => {
const wallet = WalletId.Keplr;
Expand Down Expand Up @@ -124,7 +131,7 @@ const StakingDataBox = ({ network }: PopOverProps) => {
return (
<StakeAccounts
network={network}
onClose={() => setIsDisplayingStakeAccounts(false)}
onClose={() => setStakeAccountsDisplay(false)}
/>
);
}
Expand Down Expand Up @@ -172,16 +179,17 @@ const StakingDataBox = ({ network }: PopOverProps) => {
</div>
)}
{!!stakeAccounts?.length && (
<div className={styles.unbonding}>
<div className={styles.stakeAccounts}>
<div>{t("stakeAccounts")}</div>
<div>
{stakeAccounts.length}{" "}
<div className={styles.navWrapper}>
<StakeAccountsNum>{stakeAccounts.length}</StakeAccountsNum>{" "}
<button
className={styles.nav}
onClick={() => {
setIsDisplayingStakeAccounts(true);
setStakeAccountsDisplay(true);
}}
>
{">"}
<IconChevron />
</button>
</div>
</div>
Expand Down

0 comments on commit e111c8c

Please sign in to comment.