Skip to content

Commit

Permalink
feat: add stake accounts select
Browse files Browse the repository at this point in the history
  • Loading branch information
icfor committed Apr 3, 2024
1 parent d535322 commit 4b9aa5e
Show file tree
Hide file tree
Showing 11 changed files with 280 additions and 132 deletions.
1 change: 1 addition & 0 deletions public/locales/en/staking.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
"unstakingModal": {
"amount": {
"label": "Unstake token amount",
"labelBase": "Amount",
"placeholder": "1,000"
},
"available": "Staked",
Expand Down
1 change: 1 addition & 0 deletions public/locales/zh-CN/staking.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
"unstakingModal": {
"amount": {
"label": "取消质押代币数量",
"labelBase": "Amount",
"placeholder": "1,000"
},
"available": "质押",
Expand Down
1 change: 1 addition & 0 deletions public/locales/zh-HK/staking.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
"unstakingModal": {
"amount": {
"label": "取消質押代幣數量",
"labelBase": "Amount",
"placeholder": "1,000"
},
"available": "質押",
Expand Down
12 changes: 12 additions & 0 deletions src/components/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.
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
@import "src/styles/sass.scss";

.singleItem,
.control {
border-radius: 8px;
box-shadow:
0 14px 64px -4px #0226e11f,
0 8px 22px -6px #0226e11f;
height: 80px;
margin: 0;
overflow: hidden;
width: 100%;
}

.logo {
border-radius: 200px;
box-shadow: $box-shadow-variant-3;
Expand All @@ -32,35 +20,6 @@
width: 100%;
}

.select {
height: 100%;
width: 100%;

:global(.MuiOutlinedInput-notchedOutline) {
background-color: transparent !important;
border: none;
outline-color: transparent !important;

&:hover {
background-color: transparent !important;
border: none !important;
border-color: transparent !important;
border-right-style: none !important;
box-shadow: none !important;
outline: none !important;
}
}

:global(.MuiSelect-select.MuiSelect-outlined.MuiInputBase-input) {
align-items: center;
align-self: stretch;
display: flex;
height: 100%;
justify-content: center;
padding: 0 !important;
}
}

.content {
display: flex;
flex: 1;
Expand Down Expand Up @@ -131,12 +90,3 @@
cursor: pointer;
}
}

.trigger {
cursor: pointer;
margin-right: 20px;

&.disabled {
cursor: not-allowed;
}
}
34 changes: 6 additions & 28 deletions src/screens/staking/components/staking_section/networks_select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import BigNumber from "bignumber.js";
import useTranslation from "next-translate/useTranslation";
import { useState } from "react";

import IconChevronDown from "@src/components/icons/icon_chevron_down.svg";
import { toastSuccess } from "@src/components/notification";
import { tooltipId } from "@src/components/tooltip";
import { useMiddleEllipsis } from "@src/hooks/use_middle_ellipsis";
Expand Down Expand Up @@ -32,28 +31,7 @@ import { walletsIcons } from "@src/screens/staking/lib/wallet_info";
import { getNetworkInfo } from "@src/utils/network_info";

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

const ITEM_HEIGHT = 48;
const ITEM_PADDING_TOP = 8;

const IconComponent = ({ className }: { className: string }) => (
<IconChevronDown
className={[
className,
styles.trigger,
className.includes("disabled") ? styles.disabled : "",
].join(" ")}
/>
);

const MenuProps = {
PaperProps: {
style: {
maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP,
width: 250,
},
},
};
import { IconComponent, MenuProps, selectStyles } from "./select_base";

type NetworkItemProps = {
denom: string;
Expand Down Expand Up @@ -187,7 +165,7 @@ const NetworksSelect = ({ disabled, variant }: Props) => {
);

return (
<div className={styles.singleItem}>
<div className={[styles.singleItem, selectStyles.control].join(" ")}>
<WalletItem
account={selectedAccount}
isOpened={false}
Expand All @@ -198,11 +176,11 @@ const NetworksSelect = ({ disabled, variant }: Props) => {
}

return (
<div className={styles.singleItem}>
<div className={[styles.singleItem, selectStyles.control].join(" ")}>
<Select
IconComponent={IconComponent}
MenuProps={MenuProps}
className={styles.select}
className={selectStyles.select}
disabled={disabled}
onChange={handleChange}
onClose={() => {
Expand Down Expand Up @@ -256,11 +234,11 @@ const NetworksSelect = ({ disabled, variant }: Props) => {
.sort(sortAccountsByNetworkName);

return (
<div className={styles.control}>
<div className={selectStyles.control}>
<Select
IconComponent={IconComponent}
MenuProps={MenuProps}
className={styles.select}
className={selectStyles.select}
disabled={disabled}
onChange={handleChange}
value={selectedItem}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
.control {
border-radius: 8px;
box-shadow:
0 14px 64px -4px #0226e11f,
0 8px 22px -6px #0226e11f;
height: 80px;
margin: 0;
overflow: hidden;
width: 100%;
}

.select {
height: 100%;
width: 100%;

:global(.MuiOutlinedInput-notchedOutline) {
background-color: transparent !important;
border: none;
outline-color: transparent !important;

&:hover {
background-color: transparent !important;
border: none !important;
border-color: transparent !important;
border-right-style: none !important;
box-shadow: none !important;
outline: none !important;
}
}

:global(.MuiSelect-select.MuiSelect-outlined.MuiInputBase-input) {
align-items: center;
align-self: stretch;
display: flex;
height: 100%;
justify-content: center;
padding: 0 !important;
}
}

.trigger {
cursor: pointer;
margin-right: 20px;

&.disabled {
cursor: not-allowed;
}
}
30 changes: 30 additions & 0 deletions src/screens/staking/components/staking_section/select_base.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import IconChevronDown from "@src/components/icons/icon_chevron_down.svg";

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

const ITEM_HEIGHT = 48;
const ITEM_PADDING_TOP = 8;

export const IconComponent = ({ className }: { className: string }) => (
<IconChevronDown
className={[
className,
styles.trigger,
className.includes("disabled") ? styles.disabled : "",
].join(" ")}
/>
);

export const MenuProps = {
PaperProps: {
style: {
maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP,
width: 250,
},
},
};

export const selectStyles = {
control: styles.control,
select: styles.select,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.row {
align-items: center;
display: flex;
flex: 1;
flex-direction: row;
font-size: 18px;
font-weight: 600;
gap: 20px;
justify-content: flex-start;
letter-spacing: 0.006em;
line-height: 21px;
min-height: 70px;
padding: 0 80px 0 16px;
width: 100%;
}

:global(.MuiMenuItem-root) .row {
&:hover {
background: linear-gradient(
286.17deg,
rgba(212, 49, 238, 0.24) 0%,
rgba(255, 66, 107, 0.24) 100%
);
}
}

.icon {
height: 24px;
width: 24px;
}

.address {
flex: 1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import MenuItem from "@mui/material/MenuItem";
import Select from "@mui/material/Select";

import { formatCoin } from "@src/screens/staking/lib/staking_sdk/formatters";
import type { StakeAccount } from "@src/screens/staking/lib/staking_sdk/staking_client_types";

import { IconComponent, MenuProps, selectStyles } from "./select_base";
import * as styles from "./stake_accounts_select.module.scss";

type Props = {
accounts: StakeAccount[];
disabled?: boolean;
onChange: (account: string) => void;
selectedAccount: null | string;
};

const StakeAccountsSelect = ({
accounts,
disabled,
onChange,
selectedAccount,
}: Props) => (
<div className={selectStyles.control}>
<Select
IconComponent={IconComponent}
MenuProps={MenuProps}
className={selectStyles.select}
disabled={disabled}
onChange={(e) => onChange(e.target.value as string)}
value={selectedAccount || accounts[0]?.address}
>
{accounts.map((account) => (
<MenuItem
key={account.address}
sx={{ padding: 0 }}
value={account.address}
>
<div className={styles.row}>
<img
alt=""
className={styles.icon}
src="/icons/stake_account.svg"
/>
<div
className={styles.address}
>{`${account.address.slice(0, 11)}...`}</div>
<div>
{formatCoin({
amount: account.amount,
denom: account.denom,
})}
</div>
</div>
</MenuItem>
))}
</Select>
</div>
);

export default StakeAccountsSelect;
Loading

0 comments on commit 4b9aa5e

Please sign in to comment.