You've already forked AstralRinth
forked from didirus/AstralRinth
refactor: migrate to common eslint+prettier configs (#4168)
* refactor: migrate to common eslint+prettier configs * fix: prettier frontend * feat: config changes * fix: lint issues * fix: lint * fix: type imports * fix: cyclical import issue * fix: lockfile * fix: missing dep * fix: switch to tabs * fix: continue switch to tabs * fix: rustfmt parity * fix: moderation lint issue * fix: lint issues * fix: ui intl * fix: lint issues * Revert "fix: rustfmt parity" This reverts commit cb99d2376c321d813d4b7fc7e2a213bb30a54711. * feat: revert last rs
This commit is contained in:
@@ -1,139 +1,138 @@
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-nocheck
|
||||
|
||||
export const getCurrency = (userCountry) => {
|
||||
const countryCurrency = {
|
||||
US: 'USD',
|
||||
GB: 'GBP',
|
||||
EU: 'EUR',
|
||||
AT: 'EUR',
|
||||
BE: 'EUR',
|
||||
CY: 'EUR',
|
||||
EE: 'EUR',
|
||||
FI: 'EUR',
|
||||
FR: 'EUR',
|
||||
DE: 'EUR',
|
||||
GR: 'EUR',
|
||||
IE: 'EUR',
|
||||
IT: 'EUR',
|
||||
LV: 'EUR',
|
||||
LT: 'EUR',
|
||||
LU: 'EUR',
|
||||
MT: 'EUR',
|
||||
NL: 'EUR',
|
||||
PT: 'EUR',
|
||||
SK: 'EUR',
|
||||
SI: 'EUR',
|
||||
RU: 'RUB',
|
||||
BR: 'BRL',
|
||||
JP: 'JPY',
|
||||
ID: 'IDR',
|
||||
MY: 'MYR',
|
||||
PH: 'PHP',
|
||||
TH: 'THB',
|
||||
VN: 'VND',
|
||||
KR: 'KRW',
|
||||
TR: 'TRY',
|
||||
UA: 'UAH',
|
||||
MX: 'MXN',
|
||||
CA: 'CAD',
|
||||
NZ: 'NZD',
|
||||
NO: 'NOK',
|
||||
PL: 'PLN',
|
||||
CH: 'CHF',
|
||||
LI: 'CHF',
|
||||
IN: 'INR',
|
||||
CL: 'CLP',
|
||||
PE: 'PEN',
|
||||
CO: 'COP',
|
||||
ZA: 'ZAR',
|
||||
HK: 'HKD',
|
||||
AR: 'ARS',
|
||||
KZ: 'KZT',
|
||||
UY: 'UYU',
|
||||
CN: 'CNY',
|
||||
AU: 'AUD',
|
||||
TW: 'TWD',
|
||||
SA: 'SAR',
|
||||
QA: 'QAR',
|
||||
}
|
||||
const countryCurrency = {
|
||||
US: 'USD',
|
||||
GB: 'GBP',
|
||||
EU: 'EUR',
|
||||
AT: 'EUR',
|
||||
BE: 'EUR',
|
||||
CY: 'EUR',
|
||||
EE: 'EUR',
|
||||
FI: 'EUR',
|
||||
FR: 'EUR',
|
||||
DE: 'EUR',
|
||||
GR: 'EUR',
|
||||
IE: 'EUR',
|
||||
IT: 'EUR',
|
||||
LV: 'EUR',
|
||||
LT: 'EUR',
|
||||
LU: 'EUR',
|
||||
MT: 'EUR',
|
||||
NL: 'EUR',
|
||||
PT: 'EUR',
|
||||
SK: 'EUR',
|
||||
SI: 'EUR',
|
||||
RU: 'RUB',
|
||||
BR: 'BRL',
|
||||
JP: 'JPY',
|
||||
ID: 'IDR',
|
||||
MY: 'MYR',
|
||||
PH: 'PHP',
|
||||
TH: 'THB',
|
||||
VN: 'VND',
|
||||
KR: 'KRW',
|
||||
TR: 'TRY',
|
||||
UA: 'UAH',
|
||||
MX: 'MXN',
|
||||
CA: 'CAD',
|
||||
NZ: 'NZD',
|
||||
NO: 'NOK',
|
||||
PL: 'PLN',
|
||||
CH: 'CHF',
|
||||
LI: 'CHF',
|
||||
IN: 'INR',
|
||||
CL: 'CLP',
|
||||
PE: 'PEN',
|
||||
CO: 'COP',
|
||||
ZA: 'ZAR',
|
||||
HK: 'HKD',
|
||||
AR: 'ARS',
|
||||
KZ: 'KZT',
|
||||
UY: 'UYU',
|
||||
CN: 'CNY',
|
||||
AU: 'AUD',
|
||||
TW: 'TWD',
|
||||
SA: 'SAR',
|
||||
QA: 'QAR',
|
||||
}
|
||||
|
||||
return countryCurrency[userCountry] ?? 'USD'
|
||||
return countryCurrency[userCountry] ?? 'USD'
|
||||
}
|
||||
|
||||
export const formatPrice = (locale, price, currency, trimZeros = false) => {
|
||||
let formatter = new Intl.NumberFormat(locale, {
|
||||
style: 'currency',
|
||||
currency,
|
||||
})
|
||||
let formatter = new Intl.NumberFormat(locale, {
|
||||
style: 'currency',
|
||||
currency,
|
||||
})
|
||||
|
||||
const maxDigits = formatter.resolvedOptions().maximumFractionDigits
|
||||
const convertedPrice = price / Math.pow(10, maxDigits)
|
||||
const maxDigits = formatter.resolvedOptions().maximumFractionDigits
|
||||
const convertedPrice = price / Math.pow(10, maxDigits)
|
||||
|
||||
let minimumFractionDigits = maxDigits
|
||||
let minimumFractionDigits = maxDigits
|
||||
|
||||
if (trimZeros && Number.isInteger(convertedPrice)) {
|
||||
minimumFractionDigits = 0
|
||||
}
|
||||
if (trimZeros && Number.isInteger(convertedPrice)) {
|
||||
minimumFractionDigits = 0
|
||||
}
|
||||
|
||||
formatter = new Intl.NumberFormat(locale, {
|
||||
style: 'currency',
|
||||
currency,
|
||||
minimumFractionDigits,
|
||||
})
|
||||
return formatter.format(convertedPrice)
|
||||
formatter = new Intl.NumberFormat(locale, {
|
||||
style: 'currency',
|
||||
currency,
|
||||
minimumFractionDigits,
|
||||
})
|
||||
return formatter.format(convertedPrice)
|
||||
}
|
||||
|
||||
export const calculateSavings = (monthlyPlan, plan, months = 12) => {
|
||||
const monthlyAnnualized = monthlyPlan * months
|
||||
const monthlyAnnualized = monthlyPlan * months
|
||||
|
||||
return Math.floor(((monthlyAnnualized - plan) / monthlyAnnualized) * 100)
|
||||
return Math.floor(((monthlyAnnualized - plan) / monthlyAnnualized) * 100)
|
||||
}
|
||||
|
||||
export const createStripeElements = (stripe, paymentMethods, options) => {
|
||||
const styles = getComputedStyle(document.body)
|
||||
const styles = getComputedStyle(document.body)
|
||||
|
||||
const elements = stripe.elements({
|
||||
appearance: {
|
||||
variables: {
|
||||
colorPrimary: styles.getPropertyValue('--color-brand'),
|
||||
colorBackground: styles.getPropertyValue('--experimental-color-button-bg'),
|
||||
colorText: styles.getPropertyValue('--color-base'),
|
||||
colorTextPlaceholder: styles.getPropertyValue('--color-secondary'),
|
||||
colorDanger: styles.getPropertyValue('--color-red'),
|
||||
fontFamily: styles.getPropertyValue('--font-standard'),
|
||||
spacingUnit: '0.25rem',
|
||||
borderRadius: '0.75rem',
|
||||
},
|
||||
},
|
||||
loader: 'never',
|
||||
...options,
|
||||
})
|
||||
const elements = stripe.elements({
|
||||
appearance: {
|
||||
variables: {
|
||||
colorPrimary: styles.getPropertyValue('--color-brand'),
|
||||
colorBackground: styles.getPropertyValue('--experimental-color-button-bg'),
|
||||
colorText: styles.getPropertyValue('--color-base'),
|
||||
colorTextPlaceholder: styles.getPropertyValue('--color-secondary'),
|
||||
colorDanger: styles.getPropertyValue('--color-red'),
|
||||
fontFamily: styles.getPropertyValue('--font-standard'),
|
||||
spacingUnit: '0.25rem',
|
||||
borderRadius: '0.75rem',
|
||||
},
|
||||
},
|
||||
loader: 'never',
|
||||
...options,
|
||||
})
|
||||
|
||||
const paymentElement = elements.create('payment')
|
||||
paymentElement.mount('#payment-element')
|
||||
const paymentElement = elements.create('payment')
|
||||
paymentElement.mount('#payment-element')
|
||||
|
||||
const addressElement = elements.create('address', {
|
||||
mode: 'billing',
|
||||
contacts: paymentMethods
|
||||
? [
|
||||
...new Set(
|
||||
paymentMethods.map((x) => ({
|
||||
address: x.billing_details.address,
|
||||
email: x.billing_details.email,
|
||||
name: x.billing_details.name,
|
||||
})),
|
||||
),
|
||||
]
|
||||
: undefined,
|
||||
})
|
||||
addressElement.mount('#address-element')
|
||||
const addressElement = elements.create('address', {
|
||||
mode: 'billing',
|
||||
contacts: paymentMethods
|
||||
? [
|
||||
...new Set(
|
||||
paymentMethods.map((x) => ({
|
||||
address: x.billing_details.address,
|
||||
email: x.billing_details.email,
|
||||
name: x.billing_details.name,
|
||||
})),
|
||||
),
|
||||
]
|
||||
: undefined,
|
||||
})
|
||||
addressElement.mount('#address-element')
|
||||
|
||||
addressElement.on('change', (e) => {
|
||||
if (e.value && e.value.address && e.value.address.country) {
|
||||
elements.update({ currency: getCurrency(e.value.address.country).toLowerCase() })
|
||||
}
|
||||
})
|
||||
addressElement.on('change', (e) => {
|
||||
if (e.value && e.value.address && e.value.address.country) {
|
||||
elements.update({ currency: getCurrency(e.value.address.country).toLowerCase() })
|
||||
}
|
||||
})
|
||||
|
||||
return { elements, paymentElement, addressElement }
|
||||
return { elements, paymentElement, addressElement }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user