Skip to content

Commit

Permalink
feat: add styling to stake accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
icfor committed Mar 27, 2024
1 parent 0299f29 commit e1331b7
Show file tree
Hide file tree
Showing 9 changed files with 315 additions and 60 deletions.
11 changes: 11 additions & 0 deletions public/icons/stake_account.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions public/locales/en/staking.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"accounts": "Accounts",
"addressCopied": "Address copied",
"apy": "Annual Percentage Yield",
"benefits bullet 1": "Earn your staking rewards, it allows you to earn rewards for securing the network with your contribution",
Expand Down Expand Up @@ -107,6 +108,13 @@
"stake desc": "As a token holder, you can utilize our infrastructure by staking your tokens with us",
"stake with us!": "Stake with us!",
"stake_now": "Stake Now",
"stakeAccount": {
"status": {
"activating": "Active",
"active": "Active",
"deactivating": "Deactivating"
}
},
"stakeAccounts": "Accounts",
"staked by forbole": "Staked by Forbole",
"staking": {
Expand Down
8 changes: 8 additions & 0 deletions public/locales/zh-CN/staking.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"accounts": "Accounts",
"addressCopied": "地址已复制",
"apy": "年收益率",
"benefits bullet 1": "赚取您的质押奖励,它可以让您通过贡献来获得保护网络的奖励",
Expand Down Expand Up @@ -106,6 +107,13 @@
"stake desc": "作为通证持有人,你可以安心在我们的基础建设上委托质押原生通证",
"stake with us!": "与我们一起赌注!",
"stake_now": "立即质押",
"stakeAccount": {
"status": {
"activating": "Active",
"active": "Active",
"deactivating": "Deactivating"
}
},
"stakeAccounts": "Accounts",
"staked by forbole": "Forbole 质押",
"staking": {
Expand Down
8 changes: 8 additions & 0 deletions public/locales/zh-HK/staking.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"accounts": "Accounts",
"addressCopied": "地址已複製",
"apy": "年報酬率",
"benefits bullet 1": "賺取您的質押獎勵,它可以讓您透過貢獻來獲得保護網路的獎勵",
Expand Down Expand Up @@ -106,6 +107,13 @@
"stake desc": "作為通證持有人,你可以安心在我們的基礎建設上委託質押原生通證",
"stake with us!": "與我們一起賭注!",
"stake_now": "立即質押",
"stakeAccount": {
"status": {
"activating": "Active",
"active": "Active",
"deactivating": "Deactivating"
}
},
"stakeAccounts": "Accounts",
"staked by forbole": "Forbole 質押",
"staking": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ const PopOver = ({
fetchCoinPriceForNetwork(stakingRef.current, stakingNetworkId);
}, [stakingRef, stakingNetworkId]);

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

const accountsWithDelegations = accounts?.filter(accountHasDelegations);
const accountsWithRewards = accounts?.filter(accountHasRewards);

Expand All @@ -158,6 +161,13 @@ const PopOver = ({
onClickCapture={() => setShowPopover("")}
/>
<div>{networkImage}</div>
<button
onClick={() => {
rerender((prev) => prev + 1);
}}
>
Rerender
</button>
{network.name && <div className={styles.name}>{network.name}</div>}
<StakingDataBox network={network} />
{!!networkSummary && (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
@import "src/styles/sass.scss";

.statusActivating {
background: #007fff;
}

.statusActive {
background: #1ec490;
}

.statusDeactivating {
background: #e4a11e;
}

.statusActivating,
.statusActive,
.statusDeactivating {
align-items: flex-start;
border-radius: 4px;
color: #fff;
display: inline-block;
font-size: 12px;
gap: 10px;
padding: 2px 4px;
}

.stakeAccount {
align-items: center;
background: rgba(255, 255, 255, 0.34);
box-shadow:
0 6px 14px -6px rgba(2, 38, 225, 0.12),
0 10px 32px -4px rgba(2, 38, 225, 0.1);
display: flex;
flex-direction: row;
justify-content: space-between;
padding: 12px;
width: 100%;
}

.external {
img {
height: 20px;
width: 20px;
}
}

.stakeIcon {
height: 20px;
width: 20px;
}

.title {
align-items: center;
display: flex;
flex-direction: row;
gap: 4px;
justify-content: flex-start;

span {
color: #25282d;
font-size: 12px;
font-weight: 600;
line-height: 16px;
text-shadow:
0 8px 22px rgba(2, 38, 225, 0.12),
0 14px 64px rgba(2, 38, 225, 0.12);
}
}

.left {
display: flex;
flex-direction: column;
gap: 4px;
}

.status {
display: flex;
justify-content: flex-start;
}

.value {
color: #25282d;
font-size: 16px;
font-weight: 600;
letter-spacing: 0.032px;
line-height: 20px;
text-align: right;
text-shadow:
0 8px 22px rgba(2, 38, 225, 0.12),
0 14px 64px rgba(2, 38, 225, 0.12);
}

.numbers {
align-items: flex-end;
display: flex;
flex-direction: column;
gap: 4px;
justify-content: space-between;
}

.extra {
color: #059c78;
font-size: 14px;
font-weight: 400;
letter-spacing: 0.308px;
line-height: 20px;
text-align: right;
text-shadow:
0 8px 22px rgba(2, 38, 225, 0.12),
0 14px 64px rgba(2, 38, 225, 0.12);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import useTranslation from "next-translate/useTranslation";
import { useEffect, useMemo } from "react";

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";
import {
getClaimableRewardsForNetwork,
getStakeAccountsForNetwork,
getStakedDataForNetwork,
getUnbondingTokensForNetwork,
} from "@src/screens/staking/lib/staking_sdk/context/selectors";
import { networkKeyToNetworkId } from "@src/screens/staking/lib/staking_sdk/core";
import type { Coin } from "@src/screens/staking/lib/staking_sdk/core/base";
import { WalletId } from "@src/screens/staking/lib/staking_sdk/core/base";
import { formatCoin } from "@src/screens/staking/lib/staking_sdk/formatters";
import type { StakeAccount } from "@src/screens/staking/lib/staking_sdk/staking_client_types";
import { getExplorerLink } from "@src/screens/staking/lib/staking_sdk/utils/accounts";
import type { Network, NetworkKey } from "@src/utils/network_info";

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

type Props = {
network: Network;
onClose: () => void;
};

const StakeAccounts = ({ network, onClose }: Props) => {
const stakingNetworkId = networkKeyToNetworkId[network.key as NetworkKey];

const stakingRef = useStakingRef();

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

const { stakeAccounts } = useMemo(() => {
const wallet = WalletId.Keplr;

const result = {
claimableRewards: null as NetworkClaimableRewards | null,
stakeAccounts: null as null | StakeAccount[],
stakedData: null as Coin | null,
unbondingTokens: null as { period: string; text: string } | null,
};

if (!!stakingNetworkId && !!wallet) {
result.stakeAccounts = getStakeAccountsForNetwork(
stakingRef.current.state,
stakingNetworkId,
);

result.stakedData = getStakedDataForNetwork(
stakingRef.current.state,
stakingNetworkId,
);

result.claimableRewards =
getClaimableRewardsForNetwork(
stakingRef.current.state,
stakingNetworkId,
) || null;

const unbonding = getUnbondingTokensForNetwork(
stakingRef.current.state,
stakingNetworkId,
);

if (unbonding) {
result.unbondingTokens = {
period: unbonding.period
? new Date(Number(unbonding.period) * 1000).toLocaleString()
: "",
text: formatCoin(unbonding.coin, { decimals: 4 }),
};
}
}

return result;
}, [stakingNetworkId, stakingRef]);

useEffect(() => {
fetchCoinPriceForNetwork(stakingRef.current, stakingNetworkId);
}, [stakingRef, stakingNetworkId]);

return (
<div>
<div>
<button onClick={onClose}>{"<"}</button> {t("accounts")}{" "}
{stakeAccounts?.length}
</div>
<div>
{stakeAccounts?.map((account) => {
const shortenedAddress = `${account.address.slice(0, 8)}...`;

const explorerLink = getExplorerLink(
account.address,
stakingNetworkId,
);

const statusLabel =
{
activating: t("stakeAccount.status.activating"),
active: t("stakeAccount.status.active"),
deactivating: t("stakeAccount.status.deactivating"),
}[account.status] || account.status;

const statusStyle =
{
activating: styles.statusActivating,
active: styles.statusActive,
deactivating: styles.statusDeactivating,
}[account.status] || null;

return (
<div className={styles.stakeAccount} key={account.address}>
<div className={styles.left}>
<div className={styles.title}>
<img
alt=""
className={styles.stakeIcon}
src="/icons/stake_account.svg"
/>
<span>{shortenedAddress}</span>
{!!explorerLink && (
<>
{" "}
<a
className={styles.external}
href={explorerLink}
target="_blank"
>
<img alt="" src="/icons/external.svg" />
</a>
</>
)}
</div>
<div className={styles.status}>
{!!statusStyle && (
<span className={statusStyle}>{statusLabel}</span>
)}
</div>
</div>
<div className={styles.numbers}>
<div className={styles.value}>{formatCoin(account)}</div>
<div className={styles.extra}>+123</div>
</div>
</div>
);
})}
</div>
</div>
);
};

export default StakeAccounts;
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,3 @@
text-shadow: $box-shadow-variant-3;
}
}

.stakeAccount {
align-items: center;
display: flex;
flex-direction: row;
justify-content: space-between;
width: 100%;
}

.external {
height: 20px;
width: 20px;
}
Loading

0 comments on commit e1331b7

Please sign in to comment.