Skip to content

Commit

Permalink
add copy of mock and custom tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
0xAleksaOpacic committed Mar 5, 2025
1 parent fc0c868 commit aa9fdfb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
33 changes: 27 additions & 6 deletions wallet-extension/src/features/components/wallet/home/TokenTab.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Hex } from "@nilfoundation/niljs";
import { Button, COLORS, HeadingMedium, ParagraphSmall } from "@nilfoundation/ui-kit";
import { Button, COLORS, CopyButton, HeadingMedium, ParagraphSmall } from "@nilfoundation/ui-kit";
import { useStore } from "effector-react";
import { useState } from "react";
import { useTranslation } from "react-i18next";
Expand All @@ -12,14 +12,21 @@ import {
$tokens,
getBalanceForToken,
} from "../../../store/model/token.ts";
import { convertWeiToEth, formatAddress, getTokenIcon, getTokens } from "../../../utils";
import {
convertWeiToEth,
formatAddress,
getTokenIcon,
getTokens,
isMockToken,
} from "../../../utils";
import { Box, Icon } from "../../shared";

export const TokenTab = () => {
const balance = useStore($balance);
const balanceToken = useStore($balanceToken);
const allTokens = useStore($tokens);
const [clicked, setClicked] = useState(false);
const [hoveredIndex, setHoveredIndex] = useState<number | null>(null);
const { t } = useTranslation("translation");
const navigate = useNavigate();
const availableTokens = getTokens(allTokens, true);
Expand All @@ -46,7 +53,7 @@ export const TokenTab = () => {
return {
icon: getTokenIcon(token.label),
title: token.label,
subtitle: token.label !== "" ? "Mock token" : formatAddress(token.address as Hex),
subtitle: isMockToken(token.label) ? "Mock token" : formatAddress(token.address as Hex),
subtitleColor: "gray",
rightText: `${amount.toString()} ${token.label}`,
rightTextColor: COLORS.gray50,
Expand Down Expand Up @@ -86,7 +93,12 @@ export const TokenTab = () => {
flexDirection: "row",
width: "100%",
padding: "5px",
cursor: "pointer",
backgroundColor: hoveredIndex === index ? COLORS.gray800 : "transparent",
transition: "background-color 0.3s",
}}
onMouseEnter={() => setHoveredIndex(index)}
onMouseLeave={() => setHoveredIndex(null)}
>
<Box
$align="center"
Expand Down Expand Up @@ -117,8 +129,8 @@ export const TokenTab = () => {
onClick={() => {
if (token.title === "") {
handleCopy(token.address);
setClicked(true); // Update state when clicked
setTimeout(() => setClicked(false), 2000); // Reset after 2 seconds
setClicked(true);
setTimeout(() => setClicked(false), 2000);
}
}}
$style={{
Expand All @@ -131,7 +143,16 @@ export const TokenTab = () => {
},
}}
>
{clicked && token.title === "" ? "Copied" : token.subtitle}
{hoveredIndex === index && token.address ? (
<>
{formatAddress(token.address as Hex)}
<CopyButton textToCopy={token.address} />
</>
) : clicked && token.title === "" ? (
"Copied"
) : (
token.subtitle
)}
</ParagraphSmall>
</Box>
</Box>
Expand Down
1 change: 1 addition & 0 deletions wallet-extension/src/features/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export {
convertWeiToEth,
getTokenIcon,
getTokens,
isMockToken,
} from "./token.ts";

export {
Expand Down
13 changes: 13 additions & 0 deletions wallet-extension/src/features/utils/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ export const getTokenIcon = (name: string) => {
}
};

// Return if token is mock or custom
export const isMockToken = (name: string): boolean => {
switch (name) {
case TokenNames.NIL:
case TokenNames.USDT:
case TokenNames.BTC:
case TokenNames.ETH:
return true;
default:
return false;
}
};

export function getTokens(
tokens: { name: string; address: string; show: boolean }[],
onlyActive: boolean,
Expand Down

0 comments on commit aa9fdfb

Please sign in to comment.