Skip to content

Commit

Permalink
add(offers): Visible second currency in the offer creation modal
Browse files Browse the repository at this point in the history
  • Loading branch information
hassnian committed Sep 19, 2024
1 parent 8570ee9 commit 4057f84
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions components/offer/OfferPriceInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,27 @@
</NeoButton>
</div>

<div class="flex justify-end text-k-grey text-xs mt-3 gap-1">
{{ $t('general.balance') }}:
<span v-if="isSymbolMode">
{{ balance }} {{ chainSymbol }}
</span>
<span v-else>
{{ balanceUsd }} USD
<div class="flex justify-between text-xs mt-3">
<span class="text-k-grey">
~ {{ formattedOppositeCurrency }}
</span>

<div class="flex gap-1">
{{ $t('general.balance') }}:
<span v-if="isSymbolMode">
{{ balance }} {{ chainSymbol }}
</span>
<span v-else>
{{ balanceUsd }} USD
</span>
</div>
</div>
</div>
</template>

<script setup lang="ts">
import { NeoButton, NeoIcon } from '@kodadot1/brick'
import { roundTo } from '@/utils/format/balance'
const props = defineProps<{
modelValue?: number | string
Expand All @@ -59,16 +66,20 @@ const fiatStore = useFiatStore()
const emit = defineEmits(['update:modelValue'])
const isSymbolMode = ref(true)
const tokenAmount = ref<string | number | undefined>(props.modelValue || '')
const tokenPrice = computed(() => fiatStore.getCurrentTokenValue(chainSymbol.value as Token) as number)
const switchSymbolMode = () => {
isSymbolMode.value = !isSymbolMode.value
}
const balanceUsd = computed(() => {
return balance.value * tokenPrice.value
})
const balanceUsd = computed(() => roundTo(balance.value * tokenPrice.value))
const tokenAmount = ref<string | number | undefined>(props.modelValue || '')
const formattedOppositeCurrency = computed(() => {
const value = roundTo(isSymbolMode.value ? Number(tokenAmount.value || 0) * tokenPrice.value : Number(tokenAmount.value || 0) / tokenPrice.value)
const symbol = isSymbolMode.value ? 'USD' : chainSymbol.value
return `${value} ${symbol}`
})
const model = computed({
get: () => tokenAmount.value,
Expand Down

0 comments on commit 4057f84

Please sign in to comment.