Skip to content

Commit

Permalink
Adds gradient utils and matches assets card to account card color (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgjohn authored Sep 27, 2024
1 parent 2e34143 commit 9f2ce75
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 24 deletions.
10 changes: 9 additions & 1 deletion renderer/components/AccountAssets/AccountAssets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import { ShadowCard } from "@/ui/ShadowCard/ShadowCard";
import { ArrowReceive } from "@/ui/SVGs/ArrowReceive";
import { ArrowSend } from "@/ui/SVGs/ArrowSend";
import { CurrencyUtils } from "@/utils/currency";
import {
getAddressGradientColor,
getGradientObject,
} from "@/utils/gradientUtils";
import { formatOre } from "@/utils/ironUtils";

import { AccountSyncingProgress } from "../AccountSyncingProgress/AccountSyncingProgress";
Expand Down Expand Up @@ -71,13 +75,17 @@ export function AccountAssets({ accountName }: { accountName: string }) {
const isAccountSendEligible =
!accountData.status.viewOnly || accountData.isLedger;

const cardBg = getGradientObject(
getAddressGradientColor(accountData.address),
).to;

return (
<Box>
<LightMode>
<ShadowCard
contentContainerProps={{
p: 0,
bg: COLORS.VIOLET,
bg: cardBg,
}}
mb={10}
>
Expand Down
5 changes: 3 additions & 2 deletions renderer/components/AccountRow/AccountRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ import { trpcReact } from "@/providers/TRPCProvider";
import { ChakraLink } from "@/ui/ChakraLink/ChakraLink";
import { COLORS } from "@/ui/colors";
import { PillButton } from "@/ui/PillButton/PillButton";
import { ShadowCard, type GradientOptions } from "@/ui/ShadowCard/ShadowCard";
import { ShadowCard } from "@/ui/ShadowCard/ShadowCard";
import { ArrowReceive } from "@/ui/SVGs/ArrowReceive";
import { ArrowSend } from "@/ui/SVGs/ArrowSend";
import { LogoSm } from "@/ui/SVGs/LogoSm";
import type { GradientColors } from "@/utils/gradientUtils";
import { formatOre } from "@/utils/ironUtils";

import { AccountSyncingProgress } from "../AccountSyncingProgress/AccountSyncingProgress";
Expand All @@ -43,7 +44,7 @@ const messages = defineMessages({
});

type AccountRowProps = {
color: GradientOptions;
color: GradientColors;
name: string;
balance: string;
address: string;
Expand Down
10 changes: 2 additions & 8 deletions renderer/components/UserAccountsList/UserAccountsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useState } from "react";
import { defineMessages, useIntl } from "react-intl";

import { TRPCRouterOutputs, trpcReact } from "@/providers/TRPCProvider";
import { gradientOptions } from "@/ui/ShadowCard/ShadowCard";
import { getAddressGradientColor } from "@/utils/gradientUtils";
import { parseOre } from "@/utils/ironUtils";

import { AccountRow } from "../AccountRow/AccountRow";
Expand Down Expand Up @@ -80,12 +80,6 @@ const sortOptions: Array<SortOption> = [
},
];

function getGradientColor(address: string) {
const bigAddress = BigInt(`0x${address}`);
const bigLength = BigInt(gradientOptions.length);
return gradientOptions[Number(bigAddress % bigLength)];
}

export function UserAccountsList() {
const { formatMessage } = useIntl();
const [searchInput, setSearchInput] = useState("");
Expand Down Expand Up @@ -138,7 +132,7 @@ export function UserAccountsList() {
return (
<AccountRow
key={account.name}
color={getGradientColor(account.address)}
color={getAddressGradientColor(account.address)}
name={account.name}
balance={account.balances.iron.confirmed}
address={account.address}
Expand Down
17 changes: 4 additions & 13 deletions renderer/ui/ShadowCard/ShadowCard.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
import { Box, BoxProps } from "@chakra-ui/react";

import { COLORS, GRADIENTS } from "../colors";
import { makeGradient, type GradientColors } from "@/utils/gradientUtils";

import { COLORS } from "../colors";

const SHARED_PROPS = {
border: "1px solid black",
borderRadius: "4px",
};

export type GradientOptions = keyof typeof GRADIENTS;

export const gradientOptions = Object.keys(GRADIENTS) as Array<GradientOptions>;

function makeGradient(gradient: GradientOptions, isShadow?: boolean) {
const { from, to } = GRADIENTS[gradient];
return `linear-gradient(to right, ${
isShadow ? "white" : from
} 0%, ${to} 100%)`;
}

type Props = BoxProps & {
contentContainerProps?: BoxProps;
gradient?: GradientOptions;
gradient?: GradientColors;
hoverable?: boolean;
cardOffset?: string;
};
Expand Down
31 changes: 31 additions & 0 deletions renderer/utils/gradientUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { GRADIENTS } from "@/ui/colors";

export type GradientColors = keyof typeof GRADIENTS;

const gradientColors = Object.keys(GRADIENTS) as Array<GradientColors>;

/**
* Creates a CSS linear gradient string based on the provided gradient color.
*/
export function makeGradient(gradient: GradientColors, isShadow?: boolean) {
const { from, to } = GRADIENTS[gradient];
return `linear-gradient(to right, ${
isShadow ? "white" : from
} 0%, ${to} 100%)`;
}

/**
* Determines a gradient color based on an address.
*/
export function getAddressGradientColor(address: string) {
const bigAddress = BigInt(`0x${address}`);
const bigLength = BigInt(gradientColors.length);
return gradientColors[Number(bigAddress % bigLength)];
}

/**
* Retrieves the gradient object for a given gradient color.
*/
export function getGradientObject(gradient: GradientColors) {
return GRADIENTS[gradient];
}

0 comments on commit 9f2ce75

Please sign in to comment.