Skip to content

Commit

Permalink
Telegram handle input validation (#94)
Browse files Browse the repository at this point in the history
* add telegram handle validation

* add telegram handle validation in ceate offer btn

* add telegram handle validation in the open trade btn
  • Loading branch information
davirds authored Oct 14, 2022
1 parent cd473b3 commit 902d9f2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
11 changes: 11 additions & 0 deletions app/src/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ export function formatDate(date, showTime = true) {
}
}

/**
* The Telegram handle needs to have at least 5 characters
*
* @param telegram
* @returns {boolean}
*/
export function isTelegramHandleValid(telegram) {
const handle = removeTelegramURLPrefix(telegram)
return handle.length >= 5
}

export function removeTelegramURLPrefix(telegram) {
const search = 't.me/'
const start = telegram.indexOf(search) + search.length
Expand Down
3 changes: 2 additions & 1 deletion app/src/ui/components/offers/CreateOffer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
calculateFiatPriceByRate,
convertMarginRateToOfferRate,
formatAmount,
isTelegramHandleValid,
removeTelegramURLPrefix,
} from '~/shared'
import { usePriceStore } from '~/stores/price'
Expand Down Expand Up @@ -41,7 +42,7 @@ const marginOffsetUnmasked = ref(0)
const rate = ref(0)
const offerType = ref<OfferType>(OfferType.buy)
const fiatCurrency = ref<FiatCurrency>(FiatCurrency.ARS)
const valid = computed(() => maxAmount.value > minAmount.value)
const valid = computed(() => maxAmount.value > minAmount.value && isTelegramHandleValid(ownerContact.value))
const usdRate = computed(() => priceStore.getPrice(fiatCurrency.value))
const offerPrice = computed(() => {
const fiatPrice = calculateFiatPriceByRate(usdRate.value, rate.value)
Expand Down
8 changes: 7 additions & 1 deletion app/src/ui/components/offers/ExpandedOffer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
formatAddress,
formatAmount,
formatTradesCountInfo,
isTelegramHandleValid,
removeTelegramURLPrefix,
scrollToElement,
} from '~/shared'
Expand Down Expand Up @@ -58,7 +59,12 @@ const maxAmountInCrypto = computed(() => parseInt(props.offer.max_amount.toStrin
const maxAmountInFiat = computed(() => fiatPriceByRate.value * (parseInt(props.offer.max_amount.toString()) / 1000000))
const minAmountInFiat = computed(() => fiatPriceByRate.value * (parseInt(props.offer.min_amount.toString()) / 1000000))
const offerPrice = computed(() => `${props.offer.fiat_currency} ${formatAmount(fiatPriceByRate.value, false)}`)
const valid = computed(() => true)
const valid = computed(
() =>
cryptoAmount.value >= minAmountInCrypto.value &&
cryptoAmount.value <= maxAmountInCrypto.value &&
isTelegramHandleValid(telegram.value)
)
const minMaxFiatStr = computed(() => {
const symbol = props.offer.fiat_currency.toUpperCase()
const min = minAmountInFiat.value.toFixed(2)
Expand Down

0 comments on commit 902d9f2

Please sign in to comment.