@@ -19,7 +19,7 @@ import {
1919 IoCloseCircleOutline ,
2020} from "react-icons/io5" ;
2121import { twMerge } from "tailwind-merge" ;
22- import { toDisplayAmount } from "utils" ;
22+ import { isNamadaAsset , toDisplayAmount } from "utils" ;
2323import keplrSvg from "../../integrations/assets/keplr.svg" ;
2424
2525type Tx = TransactionHistoryType ;
@@ -86,25 +86,25 @@ const getTransactionInfo = (
8686
8787 const parsed = typeof tx . data === "string" ? JSON . parse ( tx . data ) : tx . data ;
8888 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 ) ;
8991
90- let receiver : string | undefined ;
9192 let amount : BigNumber | undefined ;
93+ let receiver : string | undefined ;
9294
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 ;
100101 }
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 ) ;
104105 }
105106
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 ]
108108 ?. owner ;
109109
110110 return amount ? { amount, sender, receiver } : undefined ;
@@ -123,10 +123,6 @@ export const TransactionCard = ({
123123 isBondingTransaction ?
124124 getBondTransactionInfo ( transaction )
125125 : getTransactionInfo ( transaction ) ;
126- const baseAmount =
127- asset && txnInfo ?. amount ?
128- toDisplayAmount ( asset , txnInfo . amount )
129- : undefined ;
130126 const receiver = txnInfo ?. receiver ;
131127 const sender = txnInfo ?. sender ;
132128 const isReceived = transactionTopLevel ?. kind === "received" ;
@@ -136,6 +132,14 @@ export const TransactionCard = ({
136132 const validators = useAtomValue ( allValidatorsAtom ) ;
137133 const validator = validators ?. data ?. find ( ( v ) => v . address === receiver ) ;
138134
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+
139143 const renderKeplrIcon = ( address : string ) : JSX . Element | null => {
140144 if ( isShieldedAddress ( address ) ) return null ;
141145 if ( isTransparentAddress ( address ) ) return null ;
@@ -158,6 +162,8 @@ export const TransactionCard = ({
158162 return "Transfer" ;
159163 } ;
160164
165+ const baseAmount = getBaseAmount ( ) ;
166+
161167 return (
162168 < article
163169 className = { twMerge (
0 commit comments