Skip to content

Commit

Permalink
Merge pull request #11068 from uDaiko/trim_trailing_zeroes
Browse files Browse the repository at this point in the history
Trim trailing zeroes
  • Loading branch information
vikiival authored Oct 16, 2024
2 parents 9309bd4 + 33f14b0 commit e6751b1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import ListingCartPriceInput from '../shared/ListingCartPriceInput.vue'
import CartItemDetails from '@/components/common/CartItemDetails.vue'
import type { ListCartItem } from '@/stores/listingCart'
import { useListingCartStore } from '@/stores/listingCart'
import formatBalance from '@/utils/format/balance'
const { decimals, chainSymbol } = useChain()
Expand All @@ -56,9 +55,7 @@ const props = defineProps<{
nft: ListCartItem
}>()
const floor = computed(() =>
formatBalance(props.nft.collection.floor, decimals.value, chainSymbol.value),
)
const { formatted: floor } = useAmount(computed(() => props.nft.collection.floor || 0), decimals, chainSymbol, { withBlank: true })
const listingCartItem = computed({
get: () => listingCartStore.getItem(props.nft.id)?.listPrice,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import ListingCartFloorPrice from '../shared/ListingCartFloorPrice.vue'
import ListingCartPriceInput from '../shared/ListingCartPriceInput.vue'
import CartItemDetails from '@/components/common/CartItemDetails.vue'
import { useListingCartStore } from '@/stores/listingCart'
import formatBalance from '@/utils/format/balance'
const emit = defineEmits([
'setFixedPrice',
Expand All @@ -65,15 +64,8 @@ const { chainSymbol, decimals } = useChain()
const item = computed(() => listingCartStore.itemsInChain[0])
const itemPrice = computed(() => formatWithBlank(Number(item.value.price)))
const collectionPrice = computed(() =>
formatWithBlank(Number(item.value.collection.floor)),
)
const formatWithBlank = (value: number) => {
return value ? formatBalance(value, decimals.value, chainSymbol.value) : '--'
}
const { formatted: itemPrice } = useAmount(computed(() => (item.value.price || 0)), decimals, chainSymbol, { withBlank: true })
const { formatted: collectionPrice } = useAmount(computed(() => item.value.collection.floor || 0), decimals, chainSymbol, { withBlank: true })
watch(
() => props.fixedPrice,
Expand Down
13 changes: 3 additions & 10 deletions components/offer/MakingOfferSingleItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import OfferPriceInput from '@/components/offer/OfferPriceInput.vue'
import OfferExpirationSelector from '@/components/offer/OfferExpirationSelector.vue'
import { useMakingOfferStore } from '@/stores/makeOffer'
import formatBalance from '@/utils/format/balance'
import CartItemDetails from '@/components/common/CartItemDetails.vue'
const emit = defineEmits([
Expand All @@ -73,11 +72,8 @@ const { chainSymbol, decimals } = useChain()
const item = computed(() => offerStore.items[0])
const itemPrice = computed(() => formatWithBlank(Number(item.value.price)))
const { formatted: itemPrice } = useAmount(computed(() => item.value.price), decimals, chainSymbol, { withBlank: true })
const formatWithBlank = (value: number) => {
return value ? formatBalance(value, decimals.value, chainSymbol.value) : '--'
}
const offerPriceStoreItem = computed({
get: () => offerStore.getItem(item.value?.id)?.offerPrice,
set: price => offerStore.updateItem({ id: item.value.id, offerPrice: price }),
Expand All @@ -87,11 +83,8 @@ const offerExpirationStoreItem = computed({
set: v => offerStore.updateItem({ id: item.value.id, offerExpiration: v }),
})
const highestOfferPrice = computed(() => formatWithBlank(Number(item.value.highestOffer) || 0) || '--')
const collectionFloorPrice = computed(() =>
formatWithBlank(Number(item.value.collection.floorPrice?.[0]?.price || '0')) || '--',
)
const { formatted: highestOfferPrice } = useAmount(computed(() => item.value.highestOffer || 0), decimals, chainSymbol, { withBlank: true })
const { formatted: collectionFloorPrice } = useAmount(computed(() => item.value.collection.floorPrice?.[0]?.price || 0), decimals, chainSymbol, { withBlank: true })
watch(
() => props.offerPrice,
Expand Down
4 changes: 2 additions & 2 deletions composables/useAmount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ export default function (
tokenAmount: ComputedRef<number | string | undefined>,
tokenDecimals: ComputedRef<number>,
chainSymbol: ComputedRef<string>,
roundBy?: ComputedRef<Prefix | number>,
{ roundBy, withBlank = false }: { roundBy?: ComputedRef<Prefix | number>, withBlank?: boolean } = {},
) {
const { getCurrentTokenValue } = useFiatStore()

const amountFormatted = computed(() => {
const amount = tokenAmount.value
? formatAmountWithRound(tokenAmount.value, tokenDecimals.value, roundBy?.value)
: 0
return `${amount} ${chainSymbol.value}`
return (!Number(amount) && withBlank) ? '--' : `${amount} ${chainSymbol.value}`
})

const amountUsd = computed(() => {
Expand Down

0 comments on commit e6751b1

Please sign in to comment.