Skip to content

Commit

Permalink
add CTID support
Browse files Browse the repository at this point in the history
  • Loading branch information
mvadari committed Oct 2, 2023
1 parent c7e270c commit 25213ec
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
7 changes: 7 additions & 0 deletions src/containers/Header/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
}
Expand Down
30 changes: 15 additions & 15 deletions src/containers/Transactions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions src/containers/shared/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
11 changes: 9 additions & 2 deletions src/rippled/lib/rippled.js
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit 25213ec

Please sign in to comment.