@@ -2,7 +2,7 @@ import { InformationCircleIcon } from "@heroicons/react/24/solid";
2
2
import ReactTooltip from "react-tooltip" ;
3
3
import { Link } from "react-router-dom" ;
4
4
import { TransactionButton } from "./TransactionButton" ;
5
- import { getChainById , getTokenByChainIdAndAddress , stringToBlobUrl } from "common" ;
5
+ import { getChainById , getTokenByChainIdAndAddress , getTxBlockExplorerLink , stringToBlobUrl } from "common" ;
6
6
import { Hex , formatUnits } from "viem" ;
7
7
import { Contribution } from "data-layer" ;
8
8
import {
@@ -14,24 +14,62 @@ import {
14
14
} from "@chakra-ui/react" ;
15
15
import { useState } from "react" ;
16
16
import moment from "moment" ;
17
+ import { ArrowTopRightOnSquareIcon } from "@heroicons/react/20/solid" ;
17
18
18
19
export function DonationsTable ( props : {
19
20
contributions : Contribution [ ] ;
20
21
activeRound : boolean ;
21
22
} ) {
23
+
24
+ console . log ( "CONTRIBUTIONS" , props . contributions ) ;
25
+
26
+ function groupByTransactionHash ( contributions : Contribution [ ] ) : Record < string , Contribution [ ] > {
27
+ return contributions . reduce ( ( grouped : Record < string , Contribution [ ] > , donation : Contribution ) => {
28
+ const { transactionHash } = donation ;
29
+ if ( ! grouped [ transactionHash ] ) {
30
+ grouped [ transactionHash ] = [ ] ;
31
+ }
32
+ grouped [ transactionHash ] . push ( donation ) ;
33
+ return grouped ;
34
+ } , { } ) ;
35
+ }
36
+
37
+ const groupedContributionsByTxHash = groupByTransactionHash ( props . contributions ) ;
38
+
39
+ console . log ( "groupedContributionsByTxHash" , groupedContributionsByTxHash ) ;
40
+
22
41
return (
23
42
< >
24
43
{ props . contributions . length === 0 ? (
25
- < div className = "text-md text-center my-6 " >
44
+ < div className = "text-md text-center my-12 " >
26
45
No Donations found
27
46
</ div >
28
47
) : (
29
48
< >
30
- < TableHeader />
31
- < RoundsTableWithAccordian
32
- activeRound = { props . activeRound }
33
- contributions = { props . contributions }
34
- />
49
+ { Object . keys ( groupedContributionsByTxHash ) . map ( ( txHash ) => (
50
+ < div key = { txHash } >
51
+
52
+ < div className = "bg-grey-75 rounded-lg px-3 py-4" >
53
+ < h1 className = "font-medium font-mono text-xl" >
54
+ < a
55
+ target = { "_blank" }
56
+ href = { getTxBlockExplorerLink (
57
+ groupedContributionsByTxHash [ txHash ] [ 0 ] . chainId ,
58
+ txHash
59
+ ) }
60
+ >
61
+ Transaction #{ txHash . slice ( 0 , 5 ) + ".." + txHash . slice ( - 5 ) }
62
+ < ArrowTopRightOnSquareIcon className = "mb-1 h-5 inline ml-2" />
63
+ </ a >
64
+ </ h1 >
65
+ </ div >
66
+ < TableHeader />
67
+ < RoundsTableWithAccordian
68
+ activeRound = { props . activeRound }
69
+ contributions = { groupedContributionsByTxHash [ txHash ] }
70
+ />
71
+ </ div >
72
+ ) ) }
35
73
</ >
36
74
) }
37
75
</ >
@@ -42,96 +80,84 @@ function RoundsTableWithAccordian(props: {
42
80
contributions : Contribution [ ] ;
43
81
activeRound : boolean ;
44
82
} ) {
45
- const nestedContributionsForRound = props . contributions . reduce (
46
- ( acc : Record < string , Contribution [ ] > , contribution ) => {
47
- const roundId = contribution . roundId ;
48
83
49
- if ( ! acc [ roundId ] ) {
50
- acc [ roundId ] = [ ] ;
51
- }
52
- acc [ roundId ] . push ( contribution ) ;
53
- return acc ;
54
- } ,
55
- { }
56
- ) ;
84
+ const contributions = props . contributions ;
57
85
58
86
const [ defaultIndex , setDefaultIndex ] = useState <
59
87
number | number [ ] | undefined
60
88
> ( undefined ) ;
61
89
62
- for ( const key in nestedContributionsForRound ) {
63
- return (
64
- < div className = "pb-8" >
65
- { Object . entries ( nestedContributionsForRound ) . map (
66
- ( [ _roundId , contributionsForRound ] , _index ) => {
67
- const sortedContributions = contributionsForRound
68
- . flat ( )
69
- . sort (
70
- ( a , b ) =>
71
- ( Number ( b . timestamp ) || Number . MAX_SAFE_INTEGER ) -
72
- ( Number ( a . timestamp ) || Number . MAX_SAFE_INTEGER )
73
- ) ;
90
+ return (
91
+ < div className = "pb-8" >
92
+ { Object . entries ( contributions ) . map ( ( [ txnHash , contributionsForTx ] ) => {
93
+ const sortedContributions = contributions
94
+ . sort (
95
+ ( a , b ) => b . amountInUsd - a . amountInUsd // Sort by amountInUsd in descending order
96
+ ) ;
97
+
98
+ console . log ( "=============" )
99
+ console . log ( "txnHash" , txnHash )
100
+ console . log ( "SORTED CONTRIBUTIONS" , sortedContributions )
101
+
74
102
75
- return (
76
- < Accordion
77
- className = "w-full"
78
- allowMultiple = { true }
79
- defaultIndex = { defaultIndex }
80
- onChange = { ( index ) => {
81
- setDefaultIndex ( index ) ;
82
- } }
83
- >
84
- < AccordionItem
85
- key = { key }
86
- isDisabled = { sortedContributions . length === 0 }
103
+ return (
104
+ < Accordion
105
+ key = { txnHash }
106
+ className = "w-full"
107
+ allowMultiple = { true }
108
+ defaultIndex = { defaultIndex }
109
+ onChange = { ( index ) => {
110
+ setDefaultIndex ( index ) ;
111
+ } }
112
+ >
113
+ < AccordionItem
114
+ isDisabled = { sortedContributions . length === 0 }
115
+ >
116
+ < h2 >
117
+ < AccordionButton
118
+ _expanded = { {
119
+ bg : "white" ,
120
+ color : "black" ,
121
+ } }
122
+ _hover = { { bg : "white" , color : "black" } }
123
+ _disabled = { { bg : "white" , color : "black" } }
87
124
>
88
- < h2 >
89
- < AccordionButton
90
- _expanded = { {
91
- bg : "white" ,
92
- color : "black" ,
93
- } }
94
- _hover = { { bg : "white" , color : "black" } }
95
- _disabled = { { bg : "white" , color : "black" } }
96
- >
97
- < Table
98
- activeRound = { props . activeRound }
99
- contributions = { sortedContributions }
100
- />
101
- < AccordionIcon />
102
- </ AccordionButton >
103
- </ h2 >
104
- < AccordionPanel pb = { 4 } >
105
- < InnerTable
106
- activeRound = { props . activeRound }
107
- contributions = { sortedContributions }
108
- />
109
- </ AccordionPanel >
110
- </ AccordionItem >
111
- </ Accordion >
112
- ) ;
113
- }
114
- ) }
115
- </ div >
116
- ) ;
117
- }
125
+ < Table
126
+ activeRound = { props . activeRound }
127
+ contributions = { sortedContributions }
128
+ />
129
+ < AccordionIcon />
130
+ </ AccordionButton >
131
+ </ h2 >
132
+ < AccordionPanel pb = { 4 } >
133
+ < InnerTable
134
+ activeRound = { props . activeRound }
135
+ contributions = { sortedContributions }
136
+ />
137
+ </ AccordionPanel >
138
+ </ AccordionItem >
139
+ </ Accordion >
140
+ ) ;
141
+ } ) }
142
+ </ div >
143
+ ) ;
118
144
}
119
145
120
146
function TableHeader ( ) {
121
147
return (
122
148
< table className = "w-full text-left" >
123
149
< thead className = "font-sans text-lg" >
124
150
< tr >
125
- < th className = "w-2/5" > Round</ th >
126
- < th className = "w-2/5" >
151
+ < th className = "w-2/5 font-medium " > Round</ th >
152
+ < th className = "w-2/5 font-medium " >
127
153
< div className = "flex flex-row items-center lg:pr-16" >
128
154
< div className = "py-4" > Total Donation</ div >
129
155
< div className = "py-4" >
130
156
< InformationCircleIcon
131
157
data-tip
132
158
data-background-color = "#0E0333"
133
159
data-for = "donation-tooltip"
134
- className = "inline h-4 w-4 ml-2 mr-3 "
160
+ className = "inline h-5 w-5 ml-2 mb-1 "
135
161
data-testid = { "donation-tooltip" }
136
162
/>
137
163
< ReactTooltip
@@ -148,7 +174,7 @@ function TableHeader() {
148
174
</ div >
149
175
</ div >
150
176
</ th >
151
- < th className = "w-1/5 pl-8" > Transaction </ th >
177
+ < th > </ th >
152
178
</ tr >
153
179
</ thead >
154
180
</ table >
@@ -249,6 +275,7 @@ function Table(props: {
249
275
contributions : Contribution [ ] ;
250
276
activeRound : boolean ;
251
277
} ) {
278
+
252
279
const roundInfo = props . contributions [ 0 ] ;
253
280
const chainId = roundInfo . chainId ;
254
281
const chain = getChainById ( chainId ) ;
@@ -285,6 +312,8 @@ function Table(props: {
285
312
}
286
313
} ) ;
287
314
315
+ const txnHash = sortedContributions [ 0 ] . transactionHash ;
316
+
288
317
return (
289
318
< table className = "w-full text-left font-sans" >
290
319
< tbody >
@@ -295,7 +324,7 @@ function Table(props: {
295
324
< div className = "flex items-center" >
296
325
{ /* Network Icon */ }
297
326
< img
298
- className = "w-4 h-4 mr-2 "
327
+ className = "w-4 h-4 mr-1 "
299
328
src = { chainLogo }
300
329
alt = "Round Chain Logo"
301
330
/>
@@ -323,14 +352,6 @@ function Table(props: {
323
352
/ ${ totalContributionAmountInUsd . toFixed ( 2 ) }
324
353
</ span >
325
354
</ td >
326
- < td className = "truncate w-1/5 pl-48" >
327
- < div >
328
- < TransactionButton
329
- chainId = { sortedContributions [ 0 ] . chainId }
330
- txHash = { sortedContributions [ 0 ] . transactionHash }
331
- />
332
- </ div >
333
- </ td >
334
355
</ tr >
335
356
</ tbody >
336
357
</ table >
0 commit comments