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: Assets page #166

Merged
merged 9 commits into from
Aug 5, 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
19 changes: 19 additions & 0 deletions app/assets/svg/NoResult.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions app/assets/svg/Plus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions app/assets/svg/Search.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 0 additions & 22 deletions app/assets/svg/assets/DOT.svg

This file was deleted.

12 changes: 0 additions & 12 deletions app/assets/svg/assets/KSM.svg

This file was deleted.

6 changes: 0 additions & 6 deletions app/assets/svg/assets/USDT.svg

This file was deleted.

12 changes: 0 additions & 12 deletions app/assets/svg/assets/WND.svg

This file was deleted.

25 changes: 21 additions & 4 deletions app/common/utils/chains.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
export const POLKADOT = '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3';
export const KUSAMA = '0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe';
export const POLKADOT_ASSET_HUB = '0x68d56f15f85d3136970ec16946040bc1752654e906147f7e43e9d539d7c3de2f';
export const WESTEND = '0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e';

export const DEFAULT_CONNECTED_CHAINS: Record<ChainId, AssetId[]> = {
'0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3': [0], // POLKADOT
'0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe': [0], // KUSAMA
'0x68d56f15f85d3136970ec16946040bc1752654e906147f7e43e9d539d7c3de2f': [1], // DOT_ASSET_HUB
'0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e': [0], // WESTEND
[POLKADOT]: [0],
[KUSAMA]: [0],
[POLKADOT_ASSET_HUB]: [1],
[WESTEND]: [0],
};

export const DEFAULT_CHAINS_ORDER: Record<ChainId, Record<AssetId, number>> = {
[POLKADOT]: {
0: 0, // DOT - index_0
},
[KUSAMA]: {
0: 1, // KSM - index_1
},
[POLKADOT_ASSET_HUB]: {
1: 2, // USDT - index_2
},
};
5 changes: 2 additions & 3 deletions app/components/Address/TruncateAddress.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// @ts-expect-error no types
import MiddleEllipsis from 'react-middle-ellipsis';

import { TextBase } from '@/components';
import { TextBase } from '../Typography';

type Props = {
address?: string;
className?: string;
};

const TruncateAddress = ({ address, className }: Props) => {
export const TruncateAddress = ({ address, className }: Props) => {
return (
<span className={className}>
<MiddleEllipsis>
Expand All @@ -19,4 +19,3 @@ const TruncateAddress = ({ address, className }: Props) => {
</span>
);
};
export default TruncateAddress;
13 changes: 8 additions & 5 deletions app/components/AmountDetails/AmountDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import { type PropsWithChildren } from 'react';

import { Input } from '@nextui-org/react';

import { BodyText, Icon, LargeTitleText, TokenPrice } from '@/components';
import { type IconNames } from '@/components/Icon/types';
import { Icon } from '../Icon/Icon';
import { TokenPrice } from '../Price/TokenPrice';
import { BodyText, LargeTitleText } from '../Typography';

import { AssetIcon } from '@/components';
import { type Asset } from '@/types/substrate';

//TODO: Change layout mobile text
Expand Down Expand Up @@ -33,13 +36,13 @@ export const AmountDetails = ({

return (
<>
<div className="mb-6 mt-5 grid grid-cols-[40px,1fr,auto] gap-2 h-[40px] items-center">
<Icon name={asset.symbol as IconNames} className="w-10 h-10" />
<div className="flex gap-x-2 items-center mb-6 mt-5 -ml-1.5">
<AssetIcon src={asset.icon} size={46} />
<LargeTitleText>{asset.symbol}</LargeTitleText>
<Input
fullWidth={false}
variant="underlined"
className="mt-2.5 font-manrope h-full"
className="font-manrope w-max ml-auto mt-2.5 "
classNames={{ input: ['text-right !text-large-title max-w-[7ch]'] }}
value={amount}
isInvalid={!isAmountValid}
Expand Down
16 changes: 9 additions & 7 deletions app/components/Assets/AssetBalance.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { Icon } from '../Icon/Icon';
import { TokenPrice } from '../Price/TokenPrice';
import { MediumTitle } from '../Typography';

import { cnTw } from '@/common/utils/twMerge';
import { AssetIcon, Icon, MediumTitle, TokenPrice } from '@/components';
import { type Asset } from '@/types/substrate';

import Balance from './Balance';
import { AssetIcon } from './AssetIcon';
import { Balance } from './Balance';

type Props = {
asset: Asset;
Expand All @@ -14,12 +18,12 @@ type Props = {
animate?: boolean;
};

const AssetBalance = ({ balance, asset, className, showPrice, showArrow, animate }: Props) => {
export const AssetBalance = ({ balance, asset, className, showPrice, showArrow, animate }: Props) => {
const { icon, precision, symbol, priceId } = asset;

return (
<div className={cnTw('grid grid-cols-[40px,1fr,auto] items-center gap-x-3 grid-rows-[1fr,auto]', className)}>
<AssetIcon src={icon} size={40} className="row-span-2" />
<div className={cnTw('grid grid-cols-[48px,1fr,auto] items-center gap-x-3 grid-rows-[1fr,auto]', className)}>
<AssetIcon src={icon} size={48} className="row-span-2" />
<MediumTitle>{symbol}</MediumTitle>
<MediumTitle className="flex items-center justify-self-end">
<Balance balance={balance} precision={precision} animate={animate} />
Expand All @@ -29,5 +33,3 @@ const AssetBalance = ({ balance, asset, className, showPrice, showArrow, animate
</div>
);
};

export default AssetBalance;
42 changes: 25 additions & 17 deletions app/components/Assets/AssetIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
import { useEffect } from 'react';

import { Shimmering } from '../Shimmering/Shimmering';

import { cnTw } from '@/common/utils';
import { useToggle } from '@/common/utils/hooks';
import { Shimmering } from '@/components';

type Props = {
src?: string;
src: string;
size?: number;
className?: string;
};

const AssetIcon = ({ src, size = 32, className }: Props) => {
export const AssetIcon = ({ src, size = 32, className }: Props) => {
const [isImgLoaded, toggleImgLoaded] = useToggle();

return (
<div className={cnTw('rounded-full', isImgLoaded && 'bg-icon-on-neutral', className)}>
{!isImgLoaded && <Shimmering circle width={size} height={size} className={className} />}
<img
alt=""
src={src}
className={cnTw(!isImgLoaded && 'opacity-0')}
style={{ width: size, height: size }}
onLoad={toggleImgLoaded}
/>
</div>
);
};
useEffect(() => {
const image = new Image();
image.src = src;
image.onload = toggleImgLoaded;
}, []);

export default AssetIcon;
if (!isImgLoaded) {
return (
// Asset SVG icon has empty space between border and real icon
<div
className={cnTw('flex items-center justify-center', className)}
style={{ width: `${size}px`, height: `${size}px` }}
>
<Shimmering circle width={Math.round(size * 0.75)} />
</div>
);
}

return <img alt="" src={src} className={className} style={{ width: size, height: size }} />;
};
Loading