-
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.
- Loading branch information
1 parent
2ed0a23
commit 7def4cc
Showing
22 changed files
with
561 additions
and
255 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
50 changes: 50 additions & 0 deletions
50
packages/app-explorer/src/systems/Core/components/UtxoItem/UtxoItem.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,50 @@ | ||
import { Address, Box, useBreakpoints } from '@fuels/ui'; | ||
import { bn, toBytes, toHex } from 'fuels'; | ||
import NextLink from 'next/link'; | ||
import { useMemo } from 'react'; | ||
import { Routes } from '~/routes'; | ||
|
||
import { Amount } from '../Amount/Amount'; | ||
import { TX_ID_SIZE, UTXO_ID_SIZE } from './constants'; | ||
import { styles } from './styles'; | ||
import { UtxoItemProps } from './types'; | ||
|
||
export function UtxoItem({ item, style, assetId, index }: UtxoItemProps) { | ||
const { isMobile } = useBreakpoints(); | ||
|
||
const txId = useMemo<string | null>(() => { | ||
if (!item.utxoId) return null; | ||
const bytes = toBytes(item.utxoId, UTXO_ID_SIZE).slice(0, TX_ID_SIZE); | ||
return toHex(bytes, TX_ID_SIZE); | ||
}, []); | ||
|
||
if (!txId) return null; | ||
|
||
const trim = isMobile ? 8 : 16; | ||
const { item: itemStyle } = styles({ | ||
color: index % 2 !== 0 ? 'odd' : undefined, | ||
}); | ||
|
||
return ( | ||
<Box style={style} className={itemStyle()}> | ||
<Address | ||
prefix="ID:" | ||
value={item.utxoId} | ||
className="flex-col items-start gap-1 flex-1 tablet:flex-row tablet:items-center tablet:gap-4" | ||
addressOpts={{ trimLeft: trim, trimRight: trim }} | ||
linkProps={{ | ||
as: NextLink, | ||
href: Routes.txSimple(txId), | ||
}} | ||
/> | ||
<Amount | ||
hideSymbol | ||
hideIcon | ||
assetId={assetId} | ||
value={bn(item.amount)} | ||
className="text-xs" | ||
iconSize={14} | ||
/> | ||
</Box> | ||
); | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/app-explorer/src/systems/Core/components/UtxoItem/constants.ts
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,2 @@ | ||
export const UTXO_ID_SIZE = 34; | ||
export const TX_ID_SIZE = 32; |
19 changes: 19 additions & 0 deletions
19
packages/app-explorer/src/systems/Core/components/UtxoItem/styles.ts
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,19 @@ | ||
import { tv } from 'tailwind-variants'; | ||
|
||
export const styles = tv({ | ||
slots: { | ||
item: [ | ||
'flex flex-col p-2 px-4 gap-2', | ||
'tablet:flex-row', | ||
'last:rounded-b-sm', | ||
'fuel-[Address]:text-[0.8rem] fuel-[Address]:leading-none', | ||
], | ||
}, | ||
variants: { | ||
color: { | ||
odd: { | ||
item: 'bg-gray-4', | ||
}, | ||
}, | ||
}, | ||
}); |
9 changes: 9 additions & 0 deletions
9
packages/app-explorer/src/systems/Core/components/UtxoItem/types.ts
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,9 @@ | ||
import type { CSSProperties } from 'react'; | ||
import type { UtxoItemType } from '~/systems/Core/components/Utxos/types'; | ||
|
||
export type UtxoItemProps = { | ||
item: UtxoItemType; | ||
assetId?: string; | ||
style?: CSSProperties; | ||
index: number; | ||
}; |
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
8 changes: 8 additions & 0 deletions
8
packages/app-explorer/src/systems/Core/components/Utxos/types.ts
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,8 @@ | ||
import type { GQLUtxoItem as TUtxoItem } from '@fuel-explorer/graphql/sdk'; | ||
import type { BoxProps } from '@fuels/ui'; | ||
|
||
export type UtxoItemType = Partial<Omit<TUtxoItem, '__typename'>>; | ||
export type UtxosProps = BoxProps & { | ||
assetId?: string; | ||
items?: UtxoItemType[] | null; | ||
}; |
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
Oops, something went wrong.