-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add TxCard component and related (#37)
⭐ Closes FRO-471 ⭐ Closes FRO-472 ⭐ Closes FRO-473
- Loading branch information
1 parent
7906d92
commit 985fa0f
Showing
19 changed files
with
9,769 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import dayjs from 'dayjs'; | ||
import relativeTime from 'dayjs/plugin/relativeTime'; | ||
dayjs.extend(relativeTime); | ||
|
||
export function fromNow(timestamp: string) { | ||
return dayjs.unix(Number(timestamp)).fromNow(); | ||
} | ||
|
||
export function unixTimestamp(timestamp: number) { | ||
return dayjs(timestamp).unix().toString(); | ||
} | ||
|
||
export { dayjs }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/app/src/systems/Transaction/component/TxCard/TxCard.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { TX_CONTRACT_CALL_MOCK } from '../__mocks__/tx'; | ||
|
||
import { TxCard } from './TxCard'; | ||
|
||
const meta: Meta<typeof TxCard> = { | ||
title: 'Transaction/TxCard', | ||
component: TxCard, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof TxCard>; | ||
|
||
export const Usage: Story = { | ||
render: () => <TxCard tx={TX_CONTRACT_CALL_MOCK} css={{ maxW: 300 }} />, | ||
}; |
70 changes: 70 additions & 0 deletions
70
packages/app/src/systems/Transaction/component/TxCard/TxCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { cssObj } from '@fuel-ui/css'; | ||
import type { BaseProps } from '@fuel-ui/react'; | ||
import { Box, Card, Text } from '@fuel-ui/react'; | ||
import { bn } from 'fuels'; | ||
import { fromNow } from '~/systems/Core/utils/dayjs'; | ||
|
||
import type { TxItem } from '../../types'; | ||
import { TxTitle } from '../TxTitle/TxTitle'; | ||
|
||
type TxCardProps = BaseProps<{ | ||
tx: TxItem; | ||
}>; | ||
|
||
export function TxCard({ tx, css, ...props }: TxCardProps) { | ||
return ( | ||
<Card {...props} css={{ ...styles.root, ...css }}> | ||
<TxTitle | ||
type={tx.type} | ||
status={tx.status} | ||
txHash={tx.transaction.id} | ||
css={styles.title} | ||
/> | ||
<Box.VStack css={styles.body}> | ||
<Box.Flex justify="between"> | ||
<Text leftIcon="Users">4 accounts</Text> | ||
</Box.Flex> | ||
<Box.Flex justify="between" css={styles.row}> | ||
<Text leftIcon="Transfer">{tx.totalOperations} operations</Text> | ||
<Text leftIcon="ClockHour1" className="small"> | ||
{fromNow(tx.timestamp)} | ||
</Text> | ||
</Box.Flex> | ||
<Box.Flex justify="between" css={styles.row}> | ||
<Text leftIcon="Coins">{tx.totalAssets} assets</Text> | ||
<Text leftIcon="GasStation" className="small"> | ||
{bn(tx.gasUsed).format({ units: 3 })} ETH | ||
</Text> | ||
</Box.Flex> | ||
</Box.VStack> | ||
</Card> | ||
); | ||
} | ||
|
||
const styles = { | ||
root: cssObj({ | ||
transition: 'all 0.2s ease-out', | ||
|
||
'&:hover': { | ||
borderColor: '$borderHover', | ||
}, | ||
}), | ||
title: cssObj({ | ||
py: '$4', | ||
px: '$4', | ||
}), | ||
body: cssObj({ | ||
borderTop: '1px solid $cardBorder', | ||
py: '$4', | ||
px: '$4', | ||
}), | ||
row: cssObj({ | ||
'.fuel_Text:first-of-type': { | ||
flex: 1, | ||
}, | ||
'.small, .fuel_Icon': { | ||
fontSize: '$sm', | ||
color: '$textMuted', | ||
}, | ||
}), | ||
}; |
43 changes: 43 additions & 0 deletions
43
packages/app/src/systems/Transaction/component/TxIcon/TxIcon.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Box } from '@fuel-ui/react'; | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import type { TxStatus, TxType } from '../../types'; | ||
import { TX_STATUS, TX_TYPES } from '../../types'; | ||
|
||
import { TxIcon } from './TxIcon'; | ||
|
||
const meta: Meta<typeof TxIcon> = { | ||
title: 'Transaction/TxIcon', | ||
component: TxIcon, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof TxIcon>; | ||
|
||
export const Usage: Story = { | ||
render: () => ( | ||
<Box.VStack> | ||
{TX_TYPES.map((type) => ( | ||
<Box.HStack key={type}> | ||
{TX_STATUS.map((status) => ( | ||
<TxIcon | ||
key={status} | ||
type={type as TxType} | ||
status={status as TxStatus} | ||
/> | ||
))} | ||
</Box.HStack> | ||
))} | ||
</Box.VStack> | ||
), | ||
}; | ||
|
||
export const Sizes: Story = { | ||
render: () => ( | ||
<Box.HStack> | ||
<TxIcon type="contract-call" status="success" size="sm" /> | ||
<TxIcon type="contract-call" status="success" size="md" /> | ||
<TxIcon type="contract-call" status="success" size="lg" /> | ||
</Box.HStack> | ||
), | ||
}; |
73 changes: 73 additions & 0 deletions
73
packages/app/src/systems/Transaction/component/TxIcon/TxIcon.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import type { LayerIntent } from '@fuel-ui/css'; | ||
import { Badge, Icon } from '@fuel-ui/react'; | ||
|
||
import { type TxStatus, type TxType } from '../../types'; | ||
|
||
type TxIconProps = { | ||
type: TxType; | ||
status: TxStatus; | ||
size?: 'sm' | 'md' | 'lg'; | ||
}; | ||
|
||
const TX_ICON_MAP: Record<TxType, string> = { | ||
'contract-call': 'Code', | ||
mint: 'Coins', | ||
transfer: 'Transfer', | ||
burn: 'Flame', | ||
}; | ||
|
||
const TX_INTENT_MAP: Record<TxStatus, LayerIntent> = { | ||
success: 'success', | ||
error: 'error', | ||
pending: 'warning', | ||
idle: 'base', | ||
}; | ||
|
||
const TX_STATUS_MAP: Record<TxStatus, string> = { | ||
success: 'Success', | ||
error: 'Error', | ||
pending: 'Pending', | ||
idle: 'Idle', | ||
}; | ||
|
||
export function TxIcon({ type, status, size = 'md' }: TxIconProps) { | ||
const icon = <Icon icon={TX_ICON_MAP[type]} />; | ||
const label = TX_STATUS_MAP[status]; | ||
return ( | ||
<Badge | ||
variant="ghost" | ||
intent={TX_INTENT_MAP[status]} | ||
aria-label={label} | ||
css={styles.root} | ||
data-size={size} | ||
> | ||
{icon} | ||
</Badge> | ||
); | ||
} | ||
|
||
const styles = { | ||
root: { | ||
display: 'inline-flex', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
|
||
'&[data-size="sm"]': { | ||
width: '$8', | ||
height: '$8', | ||
}, | ||
'&[data-size="md"]': { | ||
width: '$10', | ||
height: '$10', | ||
}, | ||
'&[data-size="lg"]': { | ||
width: '$12', | ||
height: '$12', | ||
|
||
'.fuel_Icon svg': { | ||
width: '24px !important', | ||
height: '24px !important', | ||
}, | ||
}, | ||
}, | ||
}; |
39 changes: 39 additions & 0 deletions
39
packages/app/src/systems/Transaction/component/TxTitle/TxTitle.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Box } from '@fuel-ui/react'; | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { TX_TYPES, type TxType } from '../../types'; | ||
|
||
import { TxTitle } from './TxTitle'; | ||
|
||
const meta: Meta<typeof TxTitle> = { | ||
title: 'Transaction/TxTitle', | ||
component: TxTitle, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof TxTitle>; | ||
|
||
export const Usage: Story = { | ||
render: () => ( | ||
<TxTitle | ||
type="contract-call" | ||
status="success" | ||
txHash="0x78d13f111bf301324f34f2a7eaffc546d39598d156af38e7c4ef9fe61ea2c46a" | ||
/> | ||
), | ||
}; | ||
|
||
export const AllTypes: Story = { | ||
render: () => ( | ||
<Box.VStack> | ||
{TX_TYPES.map((type) => ( | ||
<TxTitle | ||
key={type} | ||
type={type as TxType} | ||
status="idle" | ||
txHash="0x78d13f111bf301324f34f2a7eaffc546d39598d156af38e7c4ef9fe61ea2c46a" | ||
/> | ||
))} | ||
</Box.VStack> | ||
), | ||
}; |
53 changes: 53 additions & 0 deletions
53
packages/app/src/systems/Transaction/component/TxTitle/TxTitle.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { cssObj } from '@fuel-ui/css'; | ||
import type { BaseProps } from '@fuel-ui/react'; | ||
import { Box, Copyable, Heading } from '@fuel-ui/react'; | ||
import { useMemo } from 'react'; | ||
import { shortAddress } from '~/systems/Core/utils/address'; | ||
|
||
import type { TxStatus, TxType } from '../../types'; | ||
import { TxIcon } from '../TxIcon/TxIcon'; | ||
|
||
const TITLE_MAP: Record<TxType, string> = { | ||
'contract-call': 'Contract Call', | ||
transfer: 'Transfer', | ||
mint: 'Mint', | ||
burn: 'Burn', | ||
}; | ||
|
||
type TxTitleProps = BaseProps<{ | ||
status: TxStatus; | ||
type: TxType; | ||
txHash: string; | ||
}>; | ||
|
||
export function TxTitle({ status, type, txHash, css, ...props }: TxTitleProps) { | ||
const title = useMemo(() => TITLE_MAP[type], [type]); | ||
return ( | ||
<Box.HStack {...props} css={{ ...styles.root, ...css }} gap="$3"> | ||
<TxIcon type={type} status={status} /> | ||
<Box> | ||
<Heading as="h4">{title}</Heading> | ||
<Copyable value={txHash}>{shortAddress(txHash)}</Copyable> | ||
</Box> | ||
</Box.HStack> | ||
); | ||
} | ||
|
||
const styles = { | ||
root: cssObj({ | ||
alignItems: 'center', | ||
|
||
'.fuel_Heading': { | ||
margin: '$0', | ||
lineHeight: '$tighter', | ||
fontSize: '$md', | ||
}, | ||
'.fuel_Copyable': { | ||
fontSize: '$sm', | ||
}, | ||
'.fuel_Copyable .fuel_Icon svg': { | ||
width: '14px !important', | ||
height: '14px !important', | ||
}, | ||
}), | ||
}; |
Oops, something went wrong.