@@ -19,7 +19,7 @@ import {
19
19
IoCloseCircleOutline ,
20
20
} from "react-icons/io5" ;
21
21
import { twMerge } from "tailwind-merge" ;
22
- import { toDisplayAmount } from "utils" ;
22
+ import { isNamadaAsset , toDisplayAmount } from "utils" ;
23
23
import keplrSvg from "../../integrations/assets/keplr.svg" ;
24
24
25
25
type Tx = TransactionHistoryType ;
@@ -86,25 +86,25 @@ const getTransactionInfo = (
86
86
87
87
const parsed = typeof tx . data === "string" ? JSON . parse ( tx . data ) : tx . data ;
88
88
const sections : RawDataSection [ ] = Array . isArray ( parsed ) ? parsed : [ parsed ] ;
89
+ const target = sections . find ( ( s ) => s . targets ?. length ) ;
90
+ const source = sections . find ( ( s ) => s . sources ?. length ) ;
89
91
90
- let receiver : string | undefined ;
91
92
let amount : BigNumber | undefined ;
93
+ let receiver : string | undefined ;
92
94
93
- // Find first section with targets or sources that has amount
94
- const targetSection = sections . find ( ( sec ) => sec . targets ?. [ 0 ] ?. amount ) ;
95
- const sourceSection = sections . find ( ( sec ) => sec . sources ?. [ 0 ] ?. amount ) ;
96
-
97
- if ( targetSection ?. targets ?. [ 0 ] ) {
98
- amount = new BigNumber ( targetSection . targets [ 0 ] . amount ) ;
99
- receiver = targetSection . targets [ 0 ] . owner ;
95
+ if ( target ?. targets ) {
96
+ const mainTarget = target . targets . reduce ( ( max , cur ) =>
97
+ new BigNumber ( cur . amount ) . isGreaterThan ( max . amount ) ? cur : max
98
+ ) ;
99
+ amount = new BigNumber ( mainTarget . amount ) ;
100
+ receiver = mainTarget . owner ;
100
101
}
101
-
102
- if ( ! amount && sourceSection ?. sources ?. [ 0 ] ) {
103
- amount = new BigNumber ( sourceSection . sources [ 0 ] . amount ) ;
102
+ // fall back to sources only when we had no targets
103
+ if ( ! amount && source ?. sources ?. [ 0 ] ) {
104
+ amount = new BigNumber ( source . sources [ 0 ] . amount ) ;
104
105
}
105
106
106
- // Find sender from any section with sources
107
- const sender = sections . find ( ( sec ) => sec . sources ?. [ 0 ] ?. owner ) ?. sources ?. [ 0 ]
107
+ const sender = sections . find ( ( s ) => s . sources ?. [ 0 ] ?. owner ) ?. sources ?. [ 0 ]
108
108
?. owner ;
109
109
110
110
return amount ? { amount, sender, receiver } : undefined ;
@@ -123,10 +123,6 @@ export const TransactionCard = ({
123
123
isBondingTransaction ?
124
124
getBondTransactionInfo ( transaction )
125
125
: getTransactionInfo ( transaction ) ;
126
- const baseAmount =
127
- asset && txnInfo ?. amount ?
128
- toDisplayAmount ( asset , txnInfo . amount )
129
- : undefined ;
130
126
const receiver = txnInfo ?. receiver ;
131
127
const sender = txnInfo ?. sender ;
132
128
const isReceived = transactionTopLevel ?. kind === "received" ;
@@ -136,6 +132,14 @@ export const TransactionCard = ({
136
132
const validators = useAtomValue ( allValidatorsAtom ) ;
137
133
const validator = validators ?. data ?. find ( ( v ) => v . address === receiver ) ;
138
134
135
+ const getBaseAmount = ( ) : BigNumber | undefined => {
136
+ if ( asset && txnInfo ?. amount ) {
137
+ if ( isBondingTransaction ) return toDisplayAmount ( asset , txnInfo . amount ) ;
138
+ if ( isNamadaAsset ( asset ) ) return txnInfo . amount ;
139
+ return toDisplayAmount ( asset , txnInfo . amount ) ;
140
+ } else return undefined ;
141
+ } ;
142
+
139
143
const renderKeplrIcon = ( address : string ) : JSX . Element | null => {
140
144
if ( isShieldedAddress ( address ) ) return null ;
141
145
if ( isTransparentAddress ( address ) ) return null ;
@@ -158,6 +162,8 @@ export const TransactionCard = ({
158
162
return "Transfer" ;
159
163
} ;
160
164
165
+ const baseAmount = getBaseAmount ( ) ;
166
+
161
167
return (
162
168
< article
163
169
className = { twMerge (
0 commit comments