@xyo-network/react-chain-boundwitness 1.5.13 → 1.5.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/browser/index.mjs +293 -131
  2. package/dist/browser/index.mjs.map +1 -1
  3. package/dist/types/components/block/BlockBoundWitnessDetails.d.ts.map +1 -1
  4. package/dist/types/components/block/card/Card.d.ts +9 -0
  5. package/dist/types/components/block/card/Card.d.ts.map +1 -0
  6. package/dist/types/components/block/card/CardHeader.d.ts +9 -0
  7. package/dist/types/components/block/card/CardHeader.d.ts.map +1 -0
  8. package/dist/types/components/block/card/hooks/index.d.ts +2 -0
  9. package/dist/types/components/block/card/hooks/index.d.ts.map +1 -0
  10. package/dist/types/components/block/card/hooks/useDetails.d.ts +16 -0
  11. package/dist/types/components/block/card/hooks/useDetails.d.ts.map +1 -0
  12. package/dist/types/components/block/card/index.d.ts +2 -0
  13. package/dist/types/components/block/card/index.d.ts.map +1 -0
  14. package/dist/types/components/transactions/card/Card.d.ts +1 -0
  15. package/dist/types/components/transactions/card/Card.d.ts.map +1 -1
  16. package/dist/types/components/transactions/card/hooks/index.d.ts +2 -0
  17. package/dist/types/components/transactions/card/hooks/index.d.ts.map +1 -0
  18. package/dist/types/components/transactions/card/hooks/useDetails.d.ts +16 -0
  19. package/dist/types/components/transactions/card/hooks/useDetails.d.ts.map +1 -0
  20. package/dist/types/lib/formatFees.d.ts +2 -0
  21. package/dist/types/lib/formatFees.d.ts.map +1 -0
  22. package/dist/types/lib/formatResults.d.ts +5 -0
  23. package/dist/types/lib/formatResults.d.ts.map +1 -0
  24. package/dist/types/lib/index.d.ts +2 -0
  25. package/dist/types/lib/index.d.ts.map +1 -1
  26. package/package.json +12 -11
  27. package/src/components/block/BlockBoundWitnessDetails.tsx +10 -2
  28. package/src/components/block/card/Card.tsx +62 -0
  29. package/src/components/block/card/CardHeader.tsx +49 -0
  30. package/src/components/block/card/hooks/index.ts +1 -0
  31. package/src/components/block/card/hooks/useDetails.ts +44 -0
  32. package/src/components/block/card/index.ts +1 -0
  33. package/src/components/transactions/card/Card.tsx +40 -77
  34. package/src/components/transactions/card/hooks/index.ts +1 -0
  35. package/src/components/transactions/card/hooks/useDetails.ts +41 -0
  36. package/src/lib/formatFees.ts +9 -0
  37. package/src/lib/formatResults.ts +8 -0
  38. package/src/lib/index.ts +2 -0
@@ -1,101 +1,64 @@
1
1
  import type { CardProps } from '@mui/material'
2
2
  import {
3
- Card, CardContent, Grid, Stack, Tooltip, Typography,
3
+ Card, CardContent, CardHeader, Grid, Link, Tooltip, Typography,
4
4
  } from '@mui/material'
5
- import { isUndefined } from '@xylabs/typeof'
6
- import { bigIntToFixedPointString } from '@xyo-network/chain-utils'
7
5
  import { BlockiesAvatarAddress } from '@xyo-network/react-chain-blockies'
8
6
  import { DetailsStack, LabelValueStack } from '@xyo-network/react-chain-shared'
7
+ import { useEvent } from '@xyo-network/react-event'
9
8
  import type { SignedHydratedTransactionInstance } from '@xyo-network/xl1-protocol-sdk'
10
- import React, { useMemo } from 'react'
9
+ import React from 'react'
11
10
  import { GiReceiveMoney, GiSandsOfTime } from 'react-icons/gi'
12
11
  import { IoStatsChartOutline } from 'react-icons/io5'
13
12
 
14
- const formatFee = (fee?: bigint) => {
15
- if (isUndefined(fee)) return
16
- const stringValue = bigIntToFixedPointString(fee, 12)
17
- if (stringValue === '0') return '0.0'
18
- return stringValue
19
- }
13
+ import { useTransactionDetails } from './hooks/index.ts'
20
14
 
21
15
  export interface TransactionBoundWitnessCardProps extends CardProps {
16
+ linkedAddress?: boolean
22
17
  wrapper?: SignedHydratedTransactionInstance
23
18
  }
24
19
 
25
- export const TransactionBoundWitnessCard: React.FC<TransactionBoundWitnessCardProps> = ({ wrapper, ...props }) => {
20
+ export const TransactionBoundWitnessCard: React.FC<TransactionBoundWitnessCardProps> = ({
21
+ linkedAddress = true, wrapper, ...props
22
+ }) => {
26
23
  if (!wrapper) return null
27
24
 
28
- const stats = useMemo(() => {
29
- const labels = [
30
- 'Reward',
31
- 'Elevated Payloads',
32
- 'Total Payloads',
33
- 'Signatures',
34
- ]
35
-
36
- const values: (string | undefined)[] = [
37
- wrapper.reward().toLocaleString(navigator.language ?? 'en-US'),
38
- wrapper.elevatedPayloadCount.toLocaleString(navigator.language ?? 'en-US'),
39
- wrapper.payloadCount.toLocaleString(navigator.language ?? 'en-US'),
40
- wrapper.signatureCount.toLocaleString(navigator.language ?? 'en-US'),,
41
- ]
42
-
43
- return { labels, values } as const
44
- }, [wrapper])
45
-
46
- const fees = useMemo(() => {
47
- const labels = [
48
- 'Base',
49
- 'Gas',
50
- 'Priority',
51
- 'Gas Limit',
52
- ]
53
- const values = [
54
- formatFee(wrapper.fees.base),
55
- formatFee(wrapper.fees.gasPrice),
56
- formatFee(wrapper.fees.priority),
57
- formatFee(wrapper.fees.gasLimit),
58
- ]
59
-
60
- return { labels, values } as const
61
- }, [wrapper])
25
+ const {
26
+ stats, fees, blockDuration,
27
+ } = useTransactionDetails(wrapper)
62
28
 
63
- const blockDuration = useMemo(() => {
64
- const labels = [
65
- 'Expiration',
66
- 'Not Before',
67
- ]
68
-
69
- const values = [
70
- wrapper.boundWitness.exp.toLocaleString(navigator.language ?? 'en-US'),
71
- wrapper.boundWitness.nbf.toLocaleString(navigator.language ?? 'en-US'),
72
- ]
73
-
74
- return { labels, values } as const
75
- }, [wrapper])
29
+ const [ref, dispatch] = useEvent<HTMLDivElement>()
76
30
 
77
31
  return (
78
- <Card {...props}>
32
+ <Card ref={ref} {...props}>
33
+ <CardHeader
34
+ title={(
35
+ <Typography
36
+ onClick={() => linkedAddress && dispatch('address', 'click', wrapper.boundWitness.from)}
37
+ variant="body2"
38
+ sx={{
39
+ maxWidth: '100%', textOverflow: 'ellipsis', overflow: 'hidden', fontFamily: 'monospace',
40
+ }}
41
+ >
42
+ {linkedAddress
43
+ ? (
44
+ <Link sx={{ cursor: 'pointer' }}>{wrapper?.boundWitness.from}</Link>
45
+ )
46
+ : wrapper?.boundWitness.from}
47
+ </Typography>
48
+ )}
49
+ avatar={(
50
+ <Tooltip title={`From Address - ${wrapper?.boundWitness.from}`}>
51
+ <BlockiesAvatarAddress
52
+ address={wrapper?.boundWitness.from}
53
+ onClick={() => dispatch('address', 'click', wrapper.boundWitness.from)}
54
+ size={21}
55
+ sx={{ cursor: 'pointer' }}
56
+ />
57
+ </Tooltip>
58
+ )}
59
+ />
79
60
  <CardContent>
80
61
  <Grid container spacing={6} sx={{ width: '100%' }}>
81
- <Grid size={{ xs: 12 }}>
82
- <Stack direction="row" alignItems="center" gap={1} sx={{ maxWidth: '100%' }}>
83
- <Tooltip title={`From Address - ${wrapper?.boundWitness.from}`}>
84
- <BlockiesAvatarAddress
85
- address={wrapper?.boundWitness.from}
86
- size={21}
87
- />
88
- </Tooltip>
89
- <Typography
90
- variant="body2"
91
- sx={{
92
- maxWidth: '100%', textOverflow: 'ellipsis', overflow: 'hidden', fontFamily: 'monospace',
93
- }}
94
- >
95
- {wrapper?.boundWitness.from}
96
- </Typography>
97
- </Stack>
98
- </Grid>
99
62
  <Grid size={{
100
63
  xs: 12, sm: 6, md: 4,
101
64
  }}
@@ -0,0 +1 @@
1
+ export * from './useDetails.ts'
@@ -0,0 +1,41 @@
1
+ import type { SignedHydratedTransactionInstance } from '@xyo-network/xl1-protocol-sdk'
2
+ import { useMemo } from 'react'
3
+
4
+ import { formatFee, formatResults } from '../../../../lib/index.ts'
5
+
6
+ export const useTransactionDetails = (wrapper: SignedHydratedTransactionInstance) => {
7
+ const stats = useMemo(() => {
8
+ const stats = {
9
+ 'Reward': wrapper.reward().toLocaleString(navigator.language ?? 'en-US'),
10
+ 'Elevated Payloads': wrapper.elevatedPayloadCount.toLocaleString(navigator.language ?? 'en-US'),
11
+ 'Total Payloads': wrapper.payloadCount.toLocaleString(navigator.language ?? 'en-US'),
12
+ 'Signatures': wrapper.signatureCount.toLocaleString(navigator.language ?? 'en-US'),
13
+ }
14
+
15
+ return formatResults(stats)
16
+ }, [wrapper])
17
+
18
+ const fees = useMemo(() => {
19
+ const fees = {
20
+ 'Base': formatFee(wrapper.fees.base),
21
+ 'Gas': formatFee(wrapper.fees.gasPrice),
22
+ 'Priority': formatFee(wrapper.fees.priority),
23
+ 'Gas Limit': formatFee(wrapper.fees.gasLimit),
24
+ }
25
+
26
+ return formatResults(fees)
27
+ }, [wrapper])
28
+
29
+ const blockDuration = useMemo(() => {
30
+ const blockDuration = {
31
+ 'Expiration': wrapper.boundWitness.exp.toLocaleString(navigator.language ?? 'en-US'),
32
+ 'Not Before': wrapper.boundWitness.nbf.toLocaleString(navigator.language ?? 'en-US'),
33
+ }
34
+
35
+ return formatResults(blockDuration)
36
+ }, [wrapper])
37
+
38
+ return {
39
+ stats, fees, blockDuration,
40
+ }
41
+ }
@@ -0,0 +1,9 @@
1
+ import { isUndefined } from '@xylabs/typeof'
2
+ import { bigIntToFixedPointString } from '@xyo-network/chain-utils'
3
+
4
+ export const formatFee = (fee?: bigint) => {
5
+ if (isUndefined(fee)) return 'N/A'
6
+ const stringValue = bigIntToFixedPointString(fee, 12)
7
+ if (stringValue === '0') return stringValue
8
+ return stringValue
9
+ }
@@ -0,0 +1,8 @@
1
+ export const formatResults = (results: Record<string, string>) => {
2
+ const result = { labels: [] as string[], values: [] as string[] }
3
+ for (const [label, value] of Object.entries(results)) {
4
+ result.labels.push(label)
5
+ result.values.push(value)
6
+ }
7
+ return result
8
+ }
package/src/lib/index.ts CHANGED
@@ -1 +1,3 @@
1
+ export * from './formatFees.ts'
1
2
  export * from './formatPayloadsForTable.ts'
3
+ export * from './formatResults.ts'