Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add currency enum #1194

Merged
merged 4 commits into from Aug 2, 2023
Merged

Add currency enum #1194

merged 4 commits into from Aug 2, 2023

Conversation

ekeew
Copy link
Contributor

@ekeew ekeew commented Jun 21, 2023

Description

I added Currency enum.
I believe that my PR will be useful, for example, when creating a payment:

from aiogram.enum import Currency

await bot.send_invoice(
    ...,
    currency=Currency.USD,
    ...
)

Since it excludes, above all, typos.

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Test A: pytest tests [OK]

  • Test B: [OK]

from aiogram.enum import Currency

print(Currency.USD, Currency.EUR)

Output:

USD EUR

Test Configuration:

  • Operating System: Windows 11 22H2
  • Python version: 3.11.3

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@github-actions github-actions bot added the 3.x Issue or PR for stable 3.x version label Jun 21, 2023
@github-actions
Copy link

github-actions bot commented Jun 21, 2023

✔️ Changelog found.

Thank you for adding a description of the changes

@ekeew ekeew marked this pull request as ready for review June 21, 2023 11:54
@JrooTJunior
Copy link
Member

Is it possible to parse the values ​​for this list using Butcher?

@ekeew
Copy link
Contributor Author

ekeew commented Jun 25, 2023

Do you mean automatically add new currencies?

@JrooTJunior
Copy link
Member

Yes.

@ekeew
Copy link
Contributor Author

ekeew commented Jul 4, 2023

I think it would be better to add them manually :)

@JrooTJunior
Copy link
Member

Please add file .butcher/enums/Currency.yml with content described in this comment and then execute command butcher apply enum (butcher should be installed with extra dev dependencies) and then commit new generated files to the repository.

name: Currency
description: |
  Currencies supported by Telegram Bot API

  Source: https://core.telegram.org/bots/payments#supported-currencies

static:
  AED: "AED"  # United Arab Emirates Dirham
  AFN: "AFN"  # Afghan Afghani
  ALL: "ALL"  # Albanian Lek
  AMD: "AMD"  # Armenian Dram
  ARS: "ARS"  # Argentine Peso
  AUD: "AUD"  # Australian Dollar
  AZN: "AZN"  # Azerbaijani Manat
  BAM: "BAM"  # Bosnia & Herzegovina Convertible Mark
  BDT: "BDT"  # Bangladeshi Taka
  BGN: "BGN"  # Bulgarian Lev
  BND: "BND"  # Brunei Dollar
  BOB: "BOB"  # Bolivian Boliviano
  BRL: "BRL"  # Brazilian Real
  BYN: "BYN"  # Belarusian ruble
  CAD: "CAD"  # Canadian Dollar
  CHF: "CHF"  # Swiss Franc
  CLP: "CLP"  # Chilean Peso
  CNY: "CNY"  # Chinese Renminbi Yuan
  COP: "COP"  # Colombian Peso
  CRC: "CRC"  # Costa Rican Colón
  CZK: "CZK"  # Czech Koruna
  DKK: "DKK"  # Danish Krone
  DOP: "DOP"  # Dominican Peso
  DZD: "DZD"  # Algerian Dinar
  EGP: "EGP"  # Egyptian Pound
  ETB: "ETB"  # Ethiopian Birr
  EUR: "EUR"  # Euro
  GBP: "GBP"  # British Pound
  GEL: "GEL"  # Georgian Lari
  GTQ: "GTQ"  # Guatemalan Quetzal
  HKD: "HKD"  # Hong Kong Dollar
  HNL: "HNL"  # Honduran Lempira
  HRK: "HRK"  # Croatian Kuna
  HUF: "HUF"  # Hungarian Forint
  IDR: "IDR"  # Indonesian Rupiah
  ILS: "ILS"  # Israeli New Sheqel
  INR: "INR"  # Indian Rupee
  ISK: "ISK"  # Icelandic Króna
  JMD: "JMD"  # Jamaican Dollar
  JPY: "JPY"  # Japanese Yen
  KES: "KES"  # Kenyan Shilling
  KGS: "KGS"  # Kyrgyzstani Som
  KRW: "KRW"  # South Korean Won
  KZT: "KZT"  # Kazakhstani Tenge
  LBP: "LBP"  # Lebanese Pound
  LKR: "LKR"  # Sri Lankan Rupee
  MAD: "MAD"  # Moroccan Dirham
  MDL: "MDL"  # Moldovan Leu
  MNT: "MNT"  # Mongolian Tögrög
  MUR: "MUR"  # Mauritian Rupee
  MVR: "MVR"  # Maldivian Rufiyaa
  MXN: "MXN"  # Mexican Peso
  MYR: "MYR"  # Malaysian Ringgit
  MZN: "MZN"  # Mozambican Metical
  NGN: "NGN"  # Nigerian Naira
  NIO: "NIO"  # Nicaraguan Córdoba
  NOK: "NOK"  # Norwegian Krone
  NPR: "NPR"  # Nepalese Rupee
  NZD: "NZD"  # New Zealand Dollar
  PAB: "PAB"  # Panamanian Balboa
  PEN: "PEN"  # Peruvian Nuevo Sol
  PHP: "PHP"  # Philippine Peso
  PKR: "PKR"  # Pakistani Rupee
  PLN: "PLN"  # Polish Złoty
  PYG: "PYG"  # Paraguayan Guaraní
  QAR: "QAR"  # Qatari Riyal
  RON: "RON"  # Romanian Leu
  RSD: "RSD"  # Serbian Dinar
  RUB: "RUB"  # Russian Ruble
  SAR: "SAR"  # Saudi Riyal
  SEK: "SEK"  # Swedish Krona
  SGD: "SGD"  # Singapore Dollar
  THB: "THB"  # Thai Baht
  TJS: "TJS"  # Tajikistani Somoni
  TRY: "TRY"  # Turkish Lira
  TTD: "TTD"  # Trinidad and Tobago Dollar
  TWD: "TWD"  # New Taiwan Dollar
  TZS: "TZS"  # Tanzanian Shilling
  UAH: "UAH"  # Ukrainian Hryvnia
  UGX: "UGX"  # Ugandan Shilling
  USD: "USD"  # United States Dollar
  UYU: "UYU"  # Uruguayan Peso
  UZS: "UZS"  # Uzbekistani Som
  VND: "VND"  # Vietnamese Đồng
  YER: "YER"  # Yemeni Rial
  ZAR: "ZAR"  # South African Rand

@Olegt0rr
Copy link
Contributor

Olegt0rr commented Jul 30, 2023

It would be nice to generate full objects with title and amount constraints.

class Currency(...):
    code: str
    title: str
    min_amount: float | None = None
    max_amount: float | None = None

# E.g.:
ALL = Currency(code="ALL", title="Albanian Lek", min_amount=95,86, max_amount=958.637,25)

This way I can validate amount provided by user BEFORE I send the value to Telegram API

@ekeew
Copy link
Contributor Author

ekeew commented Jul 30, 2023

but the range of values ​​depends on the dollar exchange rate and is often changing.

@Olegt0rr
Copy link
Contributor

Olegt0rr commented Jul 30, 2023

Agree, but the title may help to print the list of choice to user

min and max amount fields may be filled and ttl-cached with code owner data ... or not :)

@codecov
Copy link

codecov bot commented Aug 2, 2023

Codecov Report

Merging #1194 (d08848e) into dev-3.x (c418689) will not change coverage.
Report is 51 commits behind head on dev-3.x.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           dev-3.x     #1194    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files          358       364     +6     
  Lines         8841      9216   +375     
==========================================
+ Hits          8841      9216   +375     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
aiogram/enums/__init__.py 100.00% <100.00%> (ø)
aiogram/enums/currency.py 100.00% <100.00%> (ø)

... and 94 files with indirect coverage changes

@ekeew
Copy link
Contributor Author

ekeew commented Aug 2, 2023

imho in this case it would be better to make sure that the name of the enum element is also their value, nothing more.

@JrooTJunior JrooTJunior merged commit d3bec41 into aiogram:dev-3.x Aug 2, 2023
22 checks passed
@ekeew
Copy link
Contributor Author

ekeew commented Aug 6, 2023

@JrooTJunior im sorry, there is an error in my example - can you replace aiogram.enum with aiogram.enums?

@JrooTJunior
Copy link
Member

@dsodx, fixed in b9abf70

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Issue or PR for stable 3.x version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants