1
1
import { useWallet } from '@terra-money/wallet-provider' ;
2
- import { getFinderUrl , truncateAddress } from '@terra-money/apps/utils' ;
2
+ import { assertDefined , getFinderUrl , getLast , truncateAddress } from '@terra-money/apps/utils' ;
3
3
import { TxEvent , TxResponse } from '@terra-money/apps/types' ;
4
4
import { Container } from '@terra-money/apps/components' ;
5
5
import { ExpandablePanel } from 'lib/ui/Panel/ExpandablePanel' ;
@@ -8,6 +8,17 @@ import { Text } from 'lib/ui/Text';
8
8
import { ShyTextButton } from 'lib/ui/buttons/ShyTextButton' ;
9
9
import { HStack } from 'lib/ui/Stack' ;
10
10
import { TimeAgo } from 'lib/ui/TimeAgo' ;
11
+ import {
12
+ createActionRuleSet ,
13
+ createLogMatcherForActions ,
14
+ getTxCanonicalMsgs ,
15
+ } from "@terra-money/log-finder-ruleset"
16
+ import { ErrorBoundary } from 'errors/components/ErrorBoundary' ;
17
+ import { useTheme } from 'styled-components' ;
18
+ import { Tag } from 'lib/ui/Tag' ;
19
+ import { capitalizeFirstLetter } from 'lib/shared/utils/capitalizeFirstLetter' ;
20
+ import { TxMessage } from './TxMessage' ;
21
+ import { useCurrentDao } from 'dao/components/CurrentDaoProvider' ;
11
22
12
23
interface TxItemProps {
13
24
tx : TxResponse ;
@@ -17,17 +28,54 @@ export const TxItem = (props: TxItemProps) => {
17
28
const { tx } = props ;
18
29
const { txhash, timestamp, logs } = tx ;
19
30
const { network } = useWallet ( ) ;
20
- console . log ( timestamp )
31
+
32
+ const { address } = useCurrentDao ( )
21
33
22
34
const events : TxEvent [ ] = logs ? logs [ 0 ] . events : [ ] ;
23
35
24
36
const attributes = events ?. flatMap ( event => event . attributes ) ;
25
37
38
+ const ruleset = createActionRuleSet ( network . name )
39
+ const logMatcher = createLogMatcherForActions ( ruleset )
40
+ const getCanonicalMsgs = ( txInfo : TxResponse ) => {
41
+ const matchedMsg = getTxCanonicalMsgs ( txInfo , logMatcher )
42
+ return matchedMsg
43
+ ? matchedMsg
44
+ . map ( ( matchedLog ) => matchedLog . map ( ( { transformed } ) => transformed ) )
45
+ . flat ( 2 )
46
+ : [ ]
47
+ }
48
+
49
+ const isSuccess = tx . code === 0
50
+
51
+ const { colors } = useTheme ( )
52
+
26
53
const header = (
27
54
< HStack fullWidth gap = { 20 } wrap = "wrap" justifyContent = "space-between" >
28
- < ExternalLink to = { getFinderUrl ( network . name , txhash ) } >
29
- < ShyTextButton as = "div" text = { truncateAddress ( txhash ) } />
30
- </ ExternalLink >
55
+ < HStack alignItems = "center" gap = { 16 } >
56
+ < ExternalLink to = { getFinderUrl ( network . name , txhash ) } >
57
+ < ShyTextButton as = "div" text = { truncateAddress ( txhash ) } />
58
+ </ ExternalLink >
59
+ < ErrorBoundary >
60
+ { getCanonicalMsgs ( tx ) . filter ( msg => msg ) . map (
61
+ ( msg , index ) => {
62
+ const { msgType, canonicalMsg } = assertDefined ( msg )
63
+ const type = getLast ( msgType . split ( "/" ) )
64
+
65
+ return (
66
+ < HStack alignItems = "center" gap = { 8 } >
67
+ < Tag color = { isSuccess ? colors . success : colors . alert } >
68
+ { capitalizeFirstLetter ( type ) }
69
+ </ Tag >
70
+ { canonicalMsg . map ( ( text , index ) => (
71
+ < TxMessage targetAddress = { address } text = { text } key = { index } />
72
+ ) ) }
73
+ </ HStack >
74
+ )
75
+ }
76
+ ) }
77
+ </ ErrorBoundary >
78
+ </ HStack >
31
79
< Text color = "supporting" size = { 14 } >
32
80
< TimeAgo value = { new Date ( timestamp ) } />
33
81
</ Text >
0 commit comments