Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Currency Component #1148

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ docker/namadillo.config.toml
debug/
target/
# misc
.notes
.DS_Store
.env.local
.env.development.local
Expand Down
6 changes: 4 additions & 2 deletions apps/extension/src/App/Common/NamCurrency.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ type NamCurrencyProps = Omit<
export const NamCurrency = ({ ...props }: NamCurrencyProps): JSX.Element => {
return (
<Currency
currency="nam"
currency={{
symbol: "NAM",
}}
currencyPosition="right"
spaceAroundSign={true}
spaceAroundSymbol={true}
{...props}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const AccountBalanceContainer = (): JSX.Element => {
<NamCurrency
amount={totalBalance}
className="text-4xl text-white font-medium"
currencySignClassName="text-xl ml-2"
currencySymbolClassName="text-xl ml-2"
/>
)}
</Stack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const NamBalanceListItem = ({
<NamCurrency
amount={amount}
className="text-lg pl-3.5"
currencySignClassName="hidden"
currencySymbolClassName="hidden"
/>
</li>
);
Expand All @@ -50,7 +50,7 @@ export const NamBalanceContainer = (): JSX.Element => {
} = useBalances();

return (
<div className="flex gap-4 text-white">
<div className="flex gap-4 text-white pl-4 pr-6 py-5">
<AtomErrorBoundary
result={[balanceQuery, stakeQuery]}
niceError="Unable to load balances"
Expand Down
2 changes: 1 addition & 1 deletion apps/namadillo/src/App/Common/BalanceChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const BalanceChart = ({
<NamCurrency
amount={balance}
className="text-2xl"
currencySignClassName="block mb-1 text-xs ml-1"
currencySymbolClassName="block mb-1 text-xs ml-1"
/>
</div>
);
Expand Down
51 changes: 0 additions & 51 deletions apps/namadillo/src/App/Common/CurrencySelector.tsx

This file was deleted.

28 changes: 0 additions & 28 deletions apps/namadillo/src/App/Common/FiatCurrency.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions apps/namadillo/src/App/Common/NamCurrency.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ type NamCurrencyProps = Omit<
export const NamCurrency = ({ ...props }: NamCurrencyProps): JSX.Element => {
return (
<Currency
currency="nam"
currency={{ symbol: "NAM" }}
currencyPosition="right"
spaceAroundSign={true}
spaceAroundSymbol={true}
hideBalances={false}
{...props}
/>
Expand Down
23 changes: 23 additions & 0 deletions apps/namadillo/src/App/Common/TokenCurrency.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Asset } from "@chain-registry/types";
import { Currency, CurrencyProps } from "@namada/components";

type TokenCurrencyProps = Omit<
CurrencyProps,
"currency" | "currencyPosition" | "spaceAroundSign"
> & { asset: Asset };

export const TokenCurrency = ({
asset,
...props
}: TokenCurrencyProps): JSX.Element => {
return (
<Currency
currency={{
symbol: asset.symbol,
}}
currencyPosition="right"
spaceAroundSymbol={true}
{...props}
/>
);
};
21 changes: 0 additions & 21 deletions apps/namadillo/src/App/Settings/CurrencySelector.tsx

This file was deleted.

35 changes: 0 additions & 35 deletions apps/namadillo/src/App/Settings/CurrencySelectorEntry.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion apps/namadillo/src/App/Staking/BondingAmountOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const BondingAmountOverview = ({
className={clsx("text-2xl", {
[updatedValueClassList]: hasUpdatedValue,
})}
currencySignClassName="text-lg"
currencySymbolClassName="text-lg"
/>
{amountToDelegate && amountToDelegate.gt(0) && (
<span className="text-success text-md font-light mt-1.5 ml-3">
Expand Down
2 changes: 1 addition & 1 deletion apps/namadillo/src/App/Staking/StakingRewardsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const StakingRewardsPanel = (): JSX.Element => {
<NamCurrency
amount={availableRewards}
className="block leading-none"
currencySignClassName="block mb-3 mt-0.5 text-sm"
currencySymbolClassName="block mb-3 mt-0.5 text-sm"
/>
}
callToAction={
Expand Down
2 changes: 1 addition & 1 deletion apps/namadillo/src/App/Staking/StakingSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const StakingSummary = (): JSX.Element => {
<NamCurrency
amount={availableAmount ?? 0}
className="block leading-none"
currencySignClassName="block mb-3 mt-0.5 text-sm"
currencySymbolClassName="block mb-3 mt-0.5 text-sm"
/>
}
callToAction={
Expand Down
19 changes: 7 additions & 12 deletions apps/namadillo/src/App/Transfer/AvailableAmountFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { ActionButton, Currency } from "@namada/components";
import { KnownCurrencies } from "@namada/utils";
import { Asset } from "@chain-registry/types";
import { ActionButton } from "@namada/components";
import { TokenCurrency } from "App/Common/TokenCurrency";
import BigNumber from "bignumber.js";
import clsx from "clsx";

type AvailableAmountFooterProps = {
availableAmount?: BigNumber;
currency?: keyof typeof KnownCurrencies;
asset?: Asset;
onClickMax?: () => void;
};

export const AvailableAmountFooter = ({
availableAmount,
currency,
asset,
onClickMax,
}: AvailableAmountFooterProps): JSX.Element => {
if (!currency || availableAmount === undefined) {
if (availableAmount === undefined || !asset) {
return <></>;
}

// TODO: Replace <Currency /> usage here
return (
<div
className={clsx(
Expand All @@ -27,12 +27,7 @@ export const AvailableAmountFooter = ({
>
<span className="flex gap-2">
Available:
<Currency
amount={availableAmount}
currency="nam"
spaceAroundSign={true}
currencyPosition="right"
/>
<TokenCurrency amount={availableAmount} asset={asset} />
</span>
<span>
{onClickMax && (
Expand Down
2 changes: 1 addition & 1 deletion apps/namadillo/src/App/Transfer/ShieldedNamBalance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const AsyncNamCurrency = ({
<NamCurrency
amount={amount}
className="block text-center text-3xl leading-none"
currencySignClassName="block text-xs mt-1"
currencySymbolClassName="block text-xs mt-1"
/>
);
};
Expand Down
2 changes: 1 addition & 1 deletion apps/namadillo/src/App/Transfer/TransferSource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ export const TransferSource = ({
{asset && availableAmount && (
<footer>
<AvailableAmountFooter
currency={asset?.symbol}
availableAmount={availableAmount}
asset={asset}
onClickMax={() => onChangeAmount && onChangeAmount(availableAmount)}
/>
</footer>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Asset } from "@chain-registry/types";
import { fireEvent, render, screen } from "@testing-library/react";
import { assetMock } from "App/Transfer/__mocks__/assets";
import BigNumber from "bignumber.js";
import { AvailableAmountFooter } from "../AvailableAmountFooter";

Expand All @@ -12,14 +14,14 @@ describe("Component: AvailableAmountFooter", () => {
const callback = jest.fn();
render(
<AvailableAmountFooter
currency="nam"
availableAmount={new BigNumber(1234.456)}
asset={assetMock as Asset}
onClickMax={callback}
/>
);
const amount = screen.getByText("1,234");
const button = screen.getByRole("button");
expect(amount.parentNode?.textContent).toContain("1,234.456 NAM");
expect(amount.parentNode?.textContent).toContain("1,234.456 ETH");
expect(button).toBeEnabled();
fireEvent.click(button);
expect(callback).toHaveBeenCalledTimes(1);
Expand All @@ -29,7 +31,7 @@ describe("Component: AvailableAmountFooter", () => {
render(
<AvailableAmountFooter
availableAmount={new BigNumber(100)}
currency="nam"
asset={assetMock as Asset}
/>
);
expect(screen.queryByRole("button")).not.toBeInTheDocument();
Expand All @@ -40,7 +42,7 @@ describe("Component: AvailableAmountFooter", () => {
render(
<AvailableAmountFooter
availableAmount={new BigNumber(0)}
currency="nam"
asset={assetMock as Asset}
onClickMax={callback}
/>
);
Expand Down
24 changes: 0 additions & 24 deletions apps/namadillo/src/atoms/exchangeRates.ts

This file was deleted.

Loading
Loading