@@ -18,6 +18,8 @@ import { allValidatorsAtom } from "atoms/validators";
18
18
import BigNumber from "bignumber.js" ;
19
19
import clsx from "clsx" ;
20
20
import { useAtomValue } from "jotai" ;
21
+ import { AtomWithQueryResult } from "jotai-tanstack-query" ;
22
+ import { useCallback } from "react" ;
21
23
import { FaLock } from "react-icons/fa6" ;
22
24
import {
23
25
IoCheckmarkCircleOutline ,
@@ -85,14 +87,23 @@ export function getToken(
85
87
return undefined ;
86
88
}
87
89
88
- const getVoteTransactionInfo = (
89
- tx : Tx [ "tx" ]
90
- ) : VoteTransactionInfo | undefined => {
91
- if ( ! tx ?. data ) return undefined ;
92
- const parsed = typeof tx . data === "string" ? JSON . parse ( tx . data ) : tx . data ;
90
+ const getVoteTransactionInfo = ( tx : Tx [ "tx" ] ) : VoteTransactionInfo => {
91
+ if ( ! tx ?. data )
92
+ return {
93
+ proposalId : "" ,
94
+ vote : "" ,
95
+ } ;
96
+
97
+ let parsed ;
98
+ try {
99
+ parsed = JSON . parse ( tx . data ) ;
100
+ } catch ( error ) {
101
+ parsed = tx . data ;
102
+ }
103
+
93
104
return {
94
- proposalId : parsed . id ,
95
- vote : parsed . vote ,
105
+ proposalId : parsed . id || "" ,
106
+ vote : parsed . vote || "" ,
96
107
} ;
97
108
} ;
98
109
@@ -103,7 +114,7 @@ const getBondOrUnbondTransactionInfo = (
103
114
104
115
let parsed : BondData ;
105
116
try {
106
- parsed = typeof tx . data === "string" ? JSON . parse ( tx . data ) : tx . data ;
117
+ parsed = JSON . parse ( tx . data ) ;
107
118
} catch {
108
119
return undefined ;
109
120
}
@@ -165,7 +176,7 @@ const useTransactionCardData = (
165
176
asset : NamadaAsset | undefined ;
166
177
transparentAddress : string ;
167
178
transactionFailed : boolean ;
168
- validators : ReturnType < typeof useAtomValue < typeof allValidatorsAtom > > ;
179
+ validators : AtomWithQueryResult < Validator [ ] , Error > ;
169
180
} => {
170
181
const transaction = tx . tx ;
171
182
const nativeToken = useAtomValue ( nativeTokenAddressAtom ) . data ;
@@ -434,9 +445,8 @@ const TransactionAmount = ({
434
445
const tokenPrices = useAtomValue (
435
446
tokenPricesFamily ( asset ?. address ? [ asset . address ] : [ ] )
436
447
) ;
437
- const tokenPrice =
438
- asset ?. address ? tokenPrices . data ?. [ asset . address ] : undefined ;
439
- const dollarAmount = tokenPrice ? amount . multipliedBy ( tokenPrice ) : undefined ;
448
+ const tokenPrice = asset ?. address && tokenPrices . data ?. [ asset . address ] ;
449
+ const dollarAmount = tokenPrice && amount . multipliedBy ( tokenPrice ) ;
440
450
441
451
return (
442
452
< div className = "flex items-center" >
@@ -469,11 +479,11 @@ const BondUnbondTransactionCard = ({ tx }: Props): JSX.Element => {
469
479
( v ) => v . address === txnInfo ?. receiver
470
480
) ;
471
481
472
- const getTitle = ( ) : string => {
482
+ const getTitle = useCallback ( ( ) : string => {
473
483
if ( transaction ?. kind === "bond" ) return "Stake" ;
474
484
if ( transaction ?. kind === "unbond" ) return "Unstake" ;
475
485
return "Bond/Unbond" ;
476
- } ;
486
+ } , [ transaction ?. kind ] ) ;
477
487
478
488
return (
479
489
< TransactionCardContainer
@@ -581,8 +591,7 @@ const RedelegationTransactionCard = ({ tx }: Props): JSX.Element => {
581
591
const VoteTransactionCard = ( { tx } : Props ) : JSX . Element => {
582
592
const { transaction, transactionFailed } = useTransactionCardData ( tx ) ;
583
593
const voteInfo = getVoteTransactionInfo ( transaction ) ;
584
- const proposalId =
585
- voteInfo ?. proposalId ? BigInt ( voteInfo . proposalId ) : undefined ;
594
+ const proposalId = voteInfo ?. proposalId && BigInt ( voteInfo . proposalId ) ;
586
595
const proposal = useAtomValue ( proposalFamily ( proposalId || BigInt ( 0 ) ) ) ;
587
596
const navigate = useNavigate ( ) ;
588
597
0 commit comments