diff --git a/src/containers/Header/Search.tsx b/src/containers/Header/Search.tsx index 0abc75bfd..d5db033a6 100644 --- a/src/containers/Header/Search.tsx +++ b/src/containers/Header/Search.tsx @@ -16,6 +16,7 @@ import { FULL_CURRENCY_REGEX, HASH_REGEX, VALIDATORS_REGEX, + CTID_REGEX, } from '../shared/utils' import './search.scss' import { isValidPayString } from '../../rippled/payString' @@ -109,6 +110,12 @@ const getRoute = async ( path: buildPath(VALIDATOR_ROUTE, { identifier: normalizeAccount(id) }), } } + if (CTID_REGEX.test(id)) { + return { + type: 'transactions', + path: buildPath(TRANSACTION_ROUTE, { identifier: id.toUpperCase() }), + } + } return null } diff --git a/src/containers/Transactions/index.tsx b/src/containers/Transactions/index.tsx index b38b8f7da..521876965 100644 --- a/src/containers/Transactions/index.tsx +++ b/src/containers/Transactions/index.tsx @@ -7,7 +7,7 @@ import { useWindowSize } from 'usehooks-ts' import NoMatch from '../NoMatch' import { Loader } from '../shared/components/Loader' import { Tabs } from '../shared/components/Tabs' -import { NOT_FOUND, BAD_REQUEST, HASH_REGEX } from '../shared/utils' +import { NOT_FOUND, BAD_REQUEST, HASH_REGEX, CTID_REGEX } from '../shared/utils' import { SimpleTab } from './SimpleTab' import { DetailTab } from './DetailTab' import './transaction.scss' @@ -48,22 +48,22 @@ export const Transaction = () => { if (identifier === '') { return undefined } - if (!HASH_REGEX.test(identifier)) { - return Promise.reject(BAD_REQUEST) + if (HASH_REGEX.test(identifier) || CTID_REGEX.test(identifier)) { + return getTransaction(identifier, rippledSocket).catch( + (transactionRequestError) => { + const status = transactionRequestError.code + trackException( + `transaction ${identifier} --- ${JSON.stringify( + transactionRequestError.message, + )}`, + ) + + return Promise.reject(status) + }, + ) } - return getTransaction(identifier, rippledSocket).catch( - (transactionRequestError) => { - const status = transactionRequestError.code - trackException( - `transaction ${identifier} --- ${JSON.stringify( - transactionRequestError.message, - )}`, - ) - - return Promise.reject(status) - }, - ) + return Promise.reject(BAD_REQUEST) }, ) const { width } = useWindowSize() diff --git a/src/containers/shared/utils.js b/src/containers/shared/utils.js index f5e583814..674da7764 100644 --- a/src/containers/shared/utils.js +++ b/src/containers/shared/utils.js @@ -29,6 +29,7 @@ export const CURRENCY_REGEX = export const FULL_CURRENCY_REGEX = /^[0-9A-Fa-f]{40}[.:+-]r[rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz]{27,35}$/ export const VALIDATORS_REGEX = /^n[9H][0-9A-Za-z]{50}$/ +export const CTID_REGEX = /^C[0-9A-Za-z]{15}$/ export const PURPLE = '#8884d8' export const GREEN_500 = '#32E685' diff --git a/src/rippled/lib/rippled.js b/src/rippled/lib/rippled.js index 56f38a732..f19fab1c0 100644 --- a/src/rippled/lib/rippled.js +++ b/src/rippled/lib/rippled.js @@ -1,3 +1,4 @@ +import { CTID_REGEX, HASH_REGEX } from '../../containers/shared/utils' import { formatAmount } from './txSummary/formatAmount' import { Error, XRP_BASE, convertRippleDate } from './utils' @@ -139,10 +140,16 @@ const getLedgerEntry = (rippledSocket, { index }) => { } // get transaction -const getTransaction = (rippledSocket, txHash) => { +const getTransaction = (rippledSocket, txId) => { const params = { command: 'tx', - transaction: txHash, + } + if (HASH_REGEX.test(txId)) { + params.transaction = txId + } else if (CTID_REGEX.test(txId)) { + params.ctid = txId + } else { + throw new Error(`${txId} not a ctid or hash`, 404) } return query(rippledSocket, params).then((resp) => {