-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: better history #98
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import { TruncatedAddressWithCopy } from '@/components/react/addressCopy'; | |
import { formatDenom, TransactionGroup } from '@/components'; | ||
import { FaExternalLinkAlt } from 'react-icons/fa'; | ||
import { shiftDigits } from '@/utils'; | ||
import { useEndpointStore } from '@/store/endpointStore'; | ||
|
||
interface TxInfoModalProps { | ||
tx: TransactionGroup; | ||
|
@@ -11,6 +12,9 @@ interface TxInfoModalProps { | |
} | ||
|
||
export default function TxInfoModal({ tx, modalId }: TxInfoModalProps) { | ||
const { selectedEndpoint } = useEndpointStore(); | ||
const explorerUrl = selectedEndpoint?.explorer || ''; | ||
|
||
function formatDate(dateString: string): string { | ||
const date = new Date(dateString); | ||
return date.toLocaleString('en-US', { | ||
|
@@ -39,13 +43,36 @@ export default function TxInfoModal({ tx, modalId }: TxInfoModalProps) { | |
</h3> | ||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6"> | ||
<div> | ||
<InfoItem label="TRANSACTION HASH" value={tx?.tx_hash} isAddress={true} /> | ||
<InfoItem label="BLOCK" value={tx?.block_number?.toString()} /> | ||
<InfoItem label="TIMESTAMP" value={formatDate(tx?.formatted_date)} /> | ||
<InfoItem | ||
label="TRANSACTION HASH" | ||
explorerUrl={explorerUrl} | ||
value={tx?.tx_hash} | ||
isAddress={true} | ||
/> | ||
<InfoItem | ||
label="BLOCK" | ||
explorerUrl={explorerUrl} | ||
value={tx?.block_number?.toString()} | ||
/> | ||
<InfoItem | ||
label="TIMESTAMP" | ||
explorerUrl={explorerUrl} | ||
value={formatDate(tx?.formatted_date)} | ||
/> | ||
</div> | ||
<div> | ||
<InfoItem label="FROM" value={tx?.data?.from_address} isAddress={true} /> | ||
<InfoItem label="TO" value={tx?.data?.to_address} isAddress={true} /> | ||
<InfoItem | ||
label="FROM" | ||
explorerUrl={explorerUrl} | ||
value={tx?.data?.from_address} | ||
isAddress={true} | ||
/> | ||
<InfoItem | ||
label="TO" | ||
explorerUrl={explorerUrl} | ||
value={tx?.data?.to_address} | ||
isAddress={true} | ||
/> | ||
<div> | ||
<p className="text-sm font-semibold text-[#00000099] dark:text-[#FFFFFF99] mb-2"> | ||
VALUE | ||
|
@@ -74,10 +101,12 @@ export default function TxInfoModal({ tx, modalId }: TxInfoModalProps) { | |
function InfoItem({ | ||
label, | ||
value, | ||
explorerUrl, | ||
isAddress = false, | ||
}: { | ||
label: string; | ||
value: string; | ||
explorerUrl: string; | ||
isAddress?: boolean; | ||
}) { | ||
return ( | ||
|
@@ -88,7 +117,7 @@ function InfoItem({ | |
<div className="flex items-center"> | ||
<TruncatedAddressWithCopy address={value} slice={8} /> | ||
<a | ||
href={`${process.env.NEXT_PUBLIC_TESTNET_EXPLORER_URL}/${label === 'TRANSACTION HASH' ? 'transaction' : 'account'}/${label?.includes('TRANSACTION') ? value?.toUpperCase() : value}`} | ||
href={`${explorerUrl}/${label === 'TRANSACTION HASH' ? 'transaction' : 'account'}/${label?.includes('TRANSACTION') ? value?.toUpperCase() : value}`} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
className="ml-2 text-primary hover:text-primary/50" | ||
Comment on lines
+120
to
123
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Simplify complex URL construction logic The current URL construction logic is complex and hard to maintain. It mixes multiple conditions and string manipulations in a single line. Consider extracting the logic into a helper function: + const getExplorerLink = (explorerUrl: string, label: string, value: string) => {
+ const type = label === 'TRANSACTION HASH' ? 'transaction' : 'account';
+ const formattedValue = label?.includes('TRANSACTION') ? value?.toUpperCase() : value;
+ return `${explorerUrl}/${type}/${formattedValue}`;
+ };
- href={`${explorerUrl}/${label === 'TRANSACTION HASH' ? 'transaction' : 'account'}/${label?.includes('TRANSACTION') ? value?.toUpperCase() : value}`}
+ href={getExplorerLink(explorerUrl, label, value)}
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add unit tests for transaction helper functions
The newly added functions
getTransactionIcon
,getTransactionMessage
,getTransactionPlusMinus
, andgetTransactionColor
are essential for correctly rendering transaction details based ontx_type
. Currently, these functions are not covered by unit tests. To ensure reliability and prevent future regressions, please add unit tests for these functions.Would you like assistance in creating these unit tests?
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 101-105: components/bank/components/historyBox.tsx#L101-L105
Added lines #L101 - L105 were not covered by tests
[warning] 107-112: components/bank/components/historyBox.tsx#L107-L112
Added lines #L107 - L112 were not covered by tests
[warning] 114-114: components/bank/components/historyBox.tsx#L114
Added line #L114 was not covered by tests
[warning] 122-129: components/bank/components/historyBox.tsx#L122-L129
Added lines #L122 - L129 were not covered by tests
[warning] 137-144: components/bank/components/historyBox.tsx#L137-L144
Added lines #L137 - L144 were not covered by tests
[warning] 152-159: components/bank/components/historyBox.tsx#L152-L159
Added lines #L152 - L159 were not covered by tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create a new ticket and create those unit tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fmorency, I've created a new GitHub issue to track the addition of these unit tests: #101.
🔗 Analysis chain
Understood, @fmorency. I'll create a new GitHub issue to track the addition of these unit tests.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 542
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Write the unit tests and add them to the issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fmorency, here are the unit tests for the transaction helper functions. I've also added them to issue #101.