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

feat: APP-2795 - Implement AssetDataListItemStructure module component #128

Merged
merged 30 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
24c64b8
feat: implment DaoDataListItem
sepehr2github Mar 11, 2024
cc66327
tests added
sepehr2github Mar 12, 2024
b2205c0
add responsive support
sepehr2github Mar 12, 2024
7fc474d
fix: final cleanup
sepehr2github Mar 12, 2024
fbddc6a
chore: update CHANGELOG.MD
sepehr2github Mar 12, 2024
45d5073
Update CHANGELOG.md
sepehr2github Mar 12, 2024
5006ac3
Update src/modules/components/dao/daoDataListItem/index.ts
sepehr2github Mar 12, 2024
55b0102
Update src/modules/components/dao/daoDataListItem/daoDataListItem.tsx
sepehr2github Mar 12, 2024
aafac5e
fix: resolve comment
sepehr2github Mar 12, 2024
5c9e782
Merge branch 'f/app-2789' of https://github.com/aragon/ods into f/app…
sepehr2github Mar 12, 2024
ebf3330
fix: update file names
sepehr2github Mar 12, 2024
0b92344
resolve comments
sepehr2github Mar 13, 2024
eddc477
Merge branch 'main' into f/app-2789
sepehr2github Mar 13, 2024
783084b
fix: update classes
sepehr2github Mar 13, 2024
704482d
Update CHANGELOG.md
sepehr2github Mar 13, 2024
af7c4fb
Update src/modules/components/dao/daoDataListItem/daoDataListItemStru…
sepehr2github Mar 13, 2024
5267ae7
fix: update padding based on figma sizes
sepehr2github Mar 13, 2024
40a84d7
Merge branch 'main' into f/app-2789
sepehr2github Mar 13, 2024
95ef87d
update changelog
sepehr2github Mar 13, 2024
04a5a5a
Merge branch 'main' into f/app-2789
sepehr2github Mar 13, 2024
3b469f8
feature: added AssetDataListItem.Structure
sepehr2github Mar 15, 2024
e7ee172
chore: Merge branch 'main' into f/app-2795
sepehr2github Mar 15, 2024
234f6c1
fix: comments
sepehr2github Mar 15, 2024
fa2df21
Merge branch 'main' into f/app-2795
sepehr2github Mar 18, 2024
10505a5
fix: prettier
sepehr2github Mar 19, 2024
7791714
resolve comments
sepehr2github Mar 26, 2024
c6821e2
chore: merge main branch
sepehr2github Mar 26, 2024
c805883
chore: update tests
sepehr2github Mar 26, 2024
6b41b22
fix: remove logoSrc separator
sepehr2github Mar 26, 2024
4dd40e1
resolve round 2
sepehr2github Mar 27, 2024
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

### Added

- Implement `DaoDataListItem`, `ProposalDataListItem.Structure`, and `MemberDataListItem.Structure` module components
- Implement `DaoDataListItem`, `ProposalDataListItem.Structure`, `AssetDataListItem` and `MemberDataListItem.Structure` module components
sepehr2github marked this conversation as resolved.
Show resolved Hide resolved
sepehr2github marked this conversation as resolved.
Show resolved Hide resolved
- Implement `StatePingAnimation` core component

### Changed
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import type { Meta, StoryObj } from '@storybook/react';
import { DataList } from '../../../../../core/components/dataList';
sepehr2github marked this conversation as resolved.
Show resolved Hide resolved
import { AssetDataListItemStructure } from './assetDataListItemStructure';

const meta: Meta<typeof AssetDataListItemStructure> = {
title: 'Modules/Components/asset/AssetDataListItem/AssetDataListItem.Structure',
sepehr2github marked this conversation as resolved.
Show resolved Hide resolved
component: AssetDataListItemStructure,
tags: ['autodocs'],
parameters: {
design: {
type: 'figma',
url: 'https://www.figma.com/file/P0GeJKqILL7UXvaqu5Jj7V/v1.1.0?type=design&node-id=3259-11363&mode=dev',
sepehr2github marked this conversation as resolved.
Show resolved Hide resolved
},
},
};

type Story = StoryObj<typeof AssetDataListItemStructure>;

/**
* Default usage example of the AssetDataListItem component.
*/
export const Default: Story = {
args: {
logoSrc: 'https://assets.coingecko.com/coins/images/279/standard/ethereum.png?1696501628',
tokenName: 'Ethereum',
amount: 420.69,
symbol: 'ETH',
USDAmount: 1230000,
changedAmount: 420.69,
changedPercentage: 0.05,
},
render: (props) => (
<DataList.Root entityLabel="Assets">
<DataList.Container>
<AssetDataListItemStructure {...props} />
</DataList.Container>
</DataList.Root>
),
};

/**
* Usage of the AssetDataListItem without changedAmount and changedPercentage.
*/
export const Fallback: Story = {
args: {
logoSrc: 'https://assets.coingecko.com/coins/images/279/standard/ethereum.png?1696501628',
tokenName: 'Ethereum',
amount: 420.69,
symbol: 'ETH',
USDAmount: 1230000,
},
render: (props) => (
<DataList.Root entityLabel="Assets">
<DataList.Container>
<AssetDataListItemStructure {...props} />
</DataList.Container>
</DataList.Root>
),
};

export default meta;
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { render, screen } from '@testing-library/react';
import { DataList } from '../../../../../core';
import { AssetDataListItemStructure, type IAssetDataListItemStructureProps } from './assetDataListItemStructure';

describe('<AssetDataListItemStructure /> component', () => {
sepehr2github marked this conversation as resolved.
Show resolved Hide resolved
const createTestComponent = (props?: Partial<IAssetDataListItemStructureProps>) => {
return (
<DataList.Root entityLabel="Assets">
<DataList.Container>
<AssetDataListItemStructure {...props} />
</DataList.Container>
</DataList.Root>
);
};

it('renders tokenName, symbol, and the logoSrc', () => {
sepehr2github marked this conversation as resolved.
Show resolved Hide resolved
const props = {
logoSrc: 'https://assets.coingecko.com/coins/images/279/standard/ethereum.png?1696501628',
tokenName: 'Ethereum',
amount: 420.69,
symbol: 'ETH',
USDAmount: 1230000,
changedAmount: 420.69,
changedPercentage: 0.05,
sepehr2github marked this conversation as resolved.
Show resolved Hide resolved
};

render(createTestComponent(props));
expect(screen.getByText(props.tokenName)).toBeInTheDocument();
expect(screen.getByText(props.symbol)).toBeInTheDocument();
});

it('handles zero changedAmount and changedPercentage as neutral', () => {
const props = {
logoSrc: 'https://assets.coingecko.com/coins/images/279/standard/ethereum.png?1696501628',
tokenName: 'Ethereum',
amount: 420.69,
symbol: 'ETH',
USDAmount: 1230000,
changedAmount: 0,
changedPercentage: 0,
};

render(createTestComponent(props));
expect(screen.getByText('$0.00')).toBeInTheDocument(); // Assuming component shows '0' for zero changedAmount
expect(screen.getByText('0%')).toBeInTheDocument(); // Assuming Tag component renders '0%' for zero changedPercentage
});

it('handle not passing changedAmount and changedPercentage', async () => {
const props = {
logoSrc: 'https://assets.coingecko.com/coins/images/279/standard/ethereum.png?1696501628',
tokenName: 'Ethereum',
amount: 420.69,
symbol: 'ETH',
USDAmount: 1230000,
};

render(createTestComponent(props));
expect(screen.getByText('0%')).toBeInTheDocument();
const USDAmount = await screen.findByText(/1.23/);
expect(USDAmount).toHaveTextContent('$1.23M');
});

it('handle not passing changedPercentage', async () => {
const props = {
logoSrc: 'https://assets.coingecko.com/coins/images/279/standard/ethereum.png?1696501628',
tokenName: 'Ethereum',
amount: -420.69,
symbol: 'ETH',
USDAmount: 1230000,
changedAmount: 420.69,
changedPercentage: 0.05,
};

render(createTestComponent(props));
const tagElement = await screen.findByText(/\+ 5%/);
expect(tagElement).toHaveTextContent('+ 5%');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import classNames from 'classnames';
import type React from 'react';
import { Avatar, DataList, NumberFormat, Tag, formatterUtils, type IDataListItemProps } from '../../../../../core';

export interface IAssetDataListItemStructureProps extends IDataListItemProps {
/**
* The source of the logo for the token.
sepehr2github marked this conversation as resolved.
Show resolved Hide resolved
*/
logoSrc?: string;
/**
* The name of the Token.
*/
tokenName?: string;
sepehr2github marked this conversation as resolved.
Show resolved Hide resolved
/**
* The symbol of the Token.
*/
symbol?: string;
/**
* The amount of the Token.
*/
amount?: number | string;
/**
* The price of the Token.
*/
USDAmount?: number | string;
sepehr2github marked this conversation as resolved.
Show resolved Hide resolved
/**
* changed price amount (E.g. in last 24h).
*/
changedAmount?: number | string;
/**
* changed price amount ratio (E.g. in last 24h).
*/
changedPercentage?: number | string;
sepehr2github marked this conversation as resolved.
Show resolved Hide resolved
}

export const AssetDataListItemStructure: React.FC<IAssetDataListItemStructureProps> = (props) => {
const { logoSrc, tokenName, amount, symbol, USDAmount, changedAmount, changedPercentage, ...otherProps } = props;

const formattedChangedAmount = Number(Number(changedAmount).toFixed(2));
sepehr2github marked this conversation as resolved.
Show resolved Hide resolved
const formattedChangedPercentage = Number(Number(changedPercentage).toFixed(2));

const sign = (value: number) => (value > 0 ? '+' : value < 0 ? '-' : '');
sepehr2github marked this conversation as resolved.
Show resolved Hide resolved
const changedAmountSign = sign(formattedChangedAmount);
const changedPercentageSign = sign(formattedChangedPercentage);

const changedAmountClasses = classNames(
'text-sm font-normal leading-tight md:text-base',
{ 'text-success-800': formattedChangedAmount > 0 },
{ 'text-neutral-500': formattedChangedAmount === 0 },
{ 'text-critical-800': formattedChangedAmount < 0 },
);

return (
<DataList.Item {...otherProps}>
<div className="flex space-x-3 py-0 md:py-1.5">
<Avatar {...{ src: logoSrc }} size="md" />
sepehr2github marked this conversation as resolved.
Show resolved Hide resolved
<div className=" flex w-full justify-between">
<div className="flex flex-col space-y-0.5">
sepehr2github marked this conversation as resolved.
Show resolved Hide resolved
<span className="text-sm leading-tight text-neutral-800 md:text-base">{tokenName}</span>
sepehr2github marked this conversation as resolved.
Show resolved Hide resolved
<p className="text-sm leading-tight text-neutral-500 md:text-base">
<span>
{formatterUtils.formatNumber(amount, {
format: NumberFormat.TOKEN_AMOUNT_SHORT,
fallback: '',
})}{' '}
sepehr2github marked this conversation as resolved.
Show resolved Hide resolved
</span>
<span>{symbol}</span>
sepehr2github marked this conversation as resolved.
Show resolved Hide resolved
</p>
</div>
<div className="flex flex-col items-end space-y-0.5">
<span className="text-sm leading-tight text-neutral-800 md:text-base">
{formatterUtils.formatNumber(USDAmount, {
format: NumberFormat.FIAT_TOTAL_SHORT,
fallback: '-',
})}
</span>
<div className="flex items-center space-x-1">
<span className={changedAmountClasses}>
{changedAmountSign}
{formatterUtils.formatNumber(Math.abs(formattedChangedAmount || 0), {
sepehr2github marked this conversation as resolved.
Show resolved Hide resolved
format: NumberFormat.FIAT_TOTAL_SHORT,
})}
</span>
<Tag
label={`${changedPercentageSign} ${formatterUtils.formatNumber(
Math.abs(formattedChangedPercentage || 0),
{
format: NumberFormat.PERCENTAGE_SHORT,
},
)}`}
variant={
formattedChangedPercentage > 0
? 'success'
: formattedChangedPercentage < 0
? 'critical'
: 'neutral'
}
/>
</div>
</div>
</div>
</div>
</DataList.Item>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { AssetDataListItemStructure } from './assetDataListItemStructure';

export const AssetDataListItem = {
sepehr2github marked this conversation as resolved.
Show resolved Hide resolved
Structure: AssetDataListItemStructure,
};

export type { IAssetDataListItemStructureProps } from './assetDataListItemStructure';
sepehr2github marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions src/modules/components/asset/assetDataListItem/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './assetDataListItemStructure';
1 change: 1 addition & 0 deletions src/modules/components/asset/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './assetDataListItem';
sepehr2github marked this conversation as resolved.
Show resolved Hide resolved
Loading