7
7
isShieldedAddress ,
8
8
isTransparentAddress ,
9
9
} from "App/Transfer/common" ;
10
+ import { allDefaultAccountsAtom } from "atoms/accounts" ;
10
11
import { chainAssetsMapAtom , nativeTokenAddressAtom } from "atoms/chain" ;
11
12
import { TransactionHistory as TransactionHistoryType } from "atoms/transactions/atoms" ;
12
13
import { allValidatorsAtom } from "atoms/validators" ;
@@ -25,9 +26,9 @@ import keplrSvg from "../../integrations/assets/keplr.svg";
25
26
type Tx = TransactionHistoryType ;
26
27
type Props = { tx : Tx } ;
27
28
type RawDataSection = {
28
- amount ? : string ;
29
- sources ? : Array < { amount : string ; owner : string } > ;
30
- targets ? : Array < { amount : string ; owner : string } > ;
29
+ amount : string ;
30
+ sources : Array < { amount : string ; owner : string } > ;
31
+ targets : Array < { amount : string ; owner : string } > ;
31
32
} ;
32
33
type BondData = {
33
34
amount : string ;
@@ -80,7 +81,8 @@ const getBondOrUnbondTransactionInfo = (
80
81
} ;
81
82
} ;
82
83
const getTransactionInfo = (
83
- tx : Tx [ "tx" ]
84
+ tx : Tx [ "tx" ] ,
85
+ transparentAddress : string
84
86
) : { amount : BigNumber ; sender ?: string ; receiver ?: string } | undefined => {
85
87
if ( ! tx ?. data ) return undefined ;
86
88
@@ -90,22 +92,20 @@ const getTransactionInfo = (
90
92
const source = sections . find ( ( s ) => s . sources ?. length ) ;
91
93
92
94
let amount : BigNumber | undefined ;
93
- let receiver : string | undefined ;
95
+ const mainTarget = target ?. targets . find (
96
+ ( src ) => src . owner === transparentAddress
97
+ ) ;
98
+ const mainSource = source ?. sources . find (
99
+ ( src ) => src . owner === transparentAddress
100
+ ) ;
94
101
95
- if ( target ?. targets ) {
96
- const mainTarget = target . targets . reduce ( ( max , cur ) =>
97
- new BigNumber ( cur . amount ) . isGreaterThan ( max . amount ) ? cur : max
98
- ) ;
102
+ if ( mainTarget ) {
99
103
amount = new BigNumber ( mainTarget . amount ) ;
100
- receiver = mainTarget . owner ;
104
+ } else if ( mainSource ) {
105
+ amount = new BigNumber ( mainSource . amount ) ;
101
106
}
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 ) ;
105
- }
106
-
107
- const sender = sections . find ( ( s ) => s . sources ?. [ 0 ] ?. owner ) ?. sources ?. [ 0 ]
108
- ?. owner ;
107
+ const receiver = target ?. targets [ 0 ] . owner ;
108
+ const sender = source ?. sources [ 0 ] . owner ;
109
109
110
110
return amount ? { amount, sender, receiver } : undefined ;
111
111
} ;
@@ -121,10 +121,15 @@ export const TransactionCard = ({
121
121
const isBondingOrUnbondingTransaction = [ "bond" , "unbond" ] . includes (
122
122
transactionTopLevel ?. tx ?. kind ?? ""
123
123
) ;
124
+ const { data : accounts } = useAtomValue ( allDefaultAccountsAtom ) ;
125
+
126
+ const transparentAddress =
127
+ accounts ?. find ( ( acc ) => isTransparentAddress ( acc . address ) ) ?. address ?? "" ;
128
+
124
129
const txnInfo =
125
130
isBondingOrUnbondingTransaction ?
126
131
getBondOrUnbondTransactionInfo ( transaction )
127
- : getTransactionInfo ( transaction ) ;
132
+ : getTransactionInfo ( transaction , transparentAddress ) ;
128
133
const receiver = txnInfo ?. receiver ;
129
134
const sender = txnInfo ?. sender ;
130
135
const isReceived = transactionTopLevel ?. kind === "received" ;
0 commit comments