Added user currency to charge page
This commit is contained in:
parent
40324d445a
commit
0ebcd46fb6
@ -9,23 +9,23 @@ component Charge(user *arn.User)
|
||||
p.text-center.mountable You can add balance via PayPal. 1 Japanese Yen equals 1 Gem.
|
||||
|
||||
.buttons
|
||||
button.action.mountable(data-trigger="click", data-action="chargeUp", data-amount=1000)
|
||||
button.action.tip.mountable(data-trigger="click", data-action="chargeUp", data-amount=1000, aria-label=utils.YenToUserCurrency(1000, user))
|
||||
Icon("diamond")
|
||||
span 1000
|
||||
|
||||
button.action.mountable(data-trigger="click", data-action="chargeUp", data-amount=2000)
|
||||
button.action.tip.mountable(data-trigger="click", data-action="chargeUp", data-amount=2000, aria-label=utils.YenToUserCurrency(2000, user))
|
||||
Icon("diamond")
|
||||
span 2000
|
||||
|
||||
button.action.mountable(data-trigger="click", data-action="chargeUp", data-amount=3000)
|
||||
button.action.tip.mountable(data-trigger="click", data-action="chargeUp", data-amount=3000, aria-label=utils.YenToUserCurrency(3000, user))
|
||||
Icon("diamond")
|
||||
span 3000
|
||||
|
||||
button.action.mountable(data-trigger="click", data-action="chargeUp", data-amount=6000)
|
||||
button.action.tip.mountable(data-trigger="click", data-action="chargeUp", data-amount=6000, aria-label=utils.YenToUserCurrency(6000, user))
|
||||
Icon("diamond")
|
||||
span 6000
|
||||
|
||||
button.action.mountable(data-trigger="click", data-action="chargeUp", data-amount=12000)
|
||||
button.action.tip.mountable(data-trigger="click", data-action="chargeUp", data-amount=12000, aria-label=utils.YenToUserCurrency(12000, user))
|
||||
Icon("diamond")
|
||||
span 12000
|
||||
|
||||
|
35
utils/YenToUserCurrency.go
Normal file
35
utils/YenToUserCurrency.go
Normal file
@ -0,0 +1,35 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/pariz/gountries"
|
||||
)
|
||||
|
||||
// Current currency rates
|
||||
const (
|
||||
yenToEuro = 0.0075
|
||||
yenToDollar = 0.0093
|
||||
)
|
||||
|
||||
var countryQuery = gountries.New()
|
||||
|
||||
// YenToUserCurrency converts the Yen price to the user currency.
|
||||
func YenToUserCurrency(amount int, user *arn.User) string {
|
||||
if user == nil || user.Location.CountryName == "" {
|
||||
return fmt.Sprintf("%.2f $", float64(amount)*yenToDollar)
|
||||
}
|
||||
|
||||
country, err := countryQuery.FindCountryByName(user.Location.CountryName)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Sprintf("%.2f $", float64(amount)*yenToDollar)
|
||||
}
|
||||
|
||||
if arn.Contains(country.Currencies, "EUR") {
|
||||
return fmt.Sprintf("%.2f €", float64(amount)*yenToEuro)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%.2f $", float64(amount)*yenToDollar)
|
||||
}
|
Loading…
Reference in New Issue
Block a user