Skip to content

Commit

Permalink
Development (#345)
Browse files Browse the repository at this point in the history
* feat: update did string validation

* feat: add did string check before aquarius request

* feat: explicitly display prices === 0 for secondary tokens
  • Loading branch information
LucaMilanese90 authored May 7, 2023
1 parent 408e99b commit 1ecc8b0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/@utils/aquarius/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '../../@types/aquarius/SearchQuery'
import { transformAssetToAssetSelection } from '../assetConvertor'
import addressConfig from '../../../address.config'
import { isValidDid } from '@utils/ddo'

export interface UserSales {
id: string
Expand Down Expand Up @@ -178,6 +179,8 @@ export async function getAsset(
cancelToken: CancelToken
): Promise<Asset> {
try {
if (!isValidDid(did)) return

const response: AxiosResponse<Asset> = await axios.get(
`${metadataCacheUri}/api/aquarius/assets/ddo/${did}`,
{ cancelToken }
Expand Down
2 changes: 1 addition & 1 deletion src/@utils/ddo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { checkJson } from './codemirror'

export function isValidDid(did: string): boolean {
const regex = /did:op:[A-Za-z0-9]{64}/
const regex = /^did:op:[A-Za-z0-9]{64}$/
return regex.test(did)
}

Expand Down
8 changes: 5 additions & 3 deletions src/components/@shared/Price/PriceUnit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@ export default function PriceUnit({
className,
size = 'small',
symbol,
decimals
decimals,
explicitZero
}: {
price: number
className?: string
size?: 'small' | 'mini' | 'large'
symbol?: string
decimals?: string
explicitZero?: boolean
}): ReactElement {
const { locale } = useUserPreferences()

return (
<div className={`${styles.price} ${styles[size]} ${className}`}>
{price === 0 ? (
{price === 0 && !explicitZero ? (
<div>Free</div>
) : !price || Number.isNaN(price) ? (
) : (!price && price !== 0) || Number.isNaN(price) ? (
<div>-</div>
) : (
<div>
Expand Down
8 changes: 4 additions & 4 deletions src/components/Asset/AssetActions/Compute/PriceOutput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Tooltip from '@shared/atoms/Tooltip'
import styles from './PriceOutput.module.css'
import { MAX_DECIMALS } from '@utils/constants'
import Decimal from 'decimal.js'
import { useWeb3 } from '@context/Web3'

interface PriceOutputProps {
hasPreviousOrder: boolean
Expand Down Expand Up @@ -52,6 +51,7 @@ function Row({
symbol={symbol}
size="small"
className={styles.price}
explicitZero
/>
<span className={styles.timeout}>
{timeout &&
Expand Down Expand Up @@ -90,11 +90,11 @@ export default function PriceOutput({
<div key={item.symbol}>
<PriceUnit
price={Number(item.value)}
symbol={
index < totalPrices.length - 1 ? `${item.symbol} & ` : item.symbol
}
symbol={item.symbol}
size="small"
explicitZero
/>
{index < totalPrices.length - 1 && <>&nbsp;{'&'}&nbsp;</>}
</div>
))}
<Tooltip
Expand Down

1 comment on commit 1ecc8b0

@vercel
Copy link

@vercel vercel bot commented on 1ecc8b0 May 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.