Skip to content

Commit

Permalink
Merge pull request #90 from ilyarolf/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ilyarolf authored Jan 5, 2025
2 parents 48dd62f + 5eac194 commit c9b3842
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions crypto_api/CryptoApiManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ async def get_usdt_erc20_balance(user_dto: UserDTO, deposits) -> float:
deposit.network == "ETH" and deposit.token_name == "USDT_ERC20"]
deposits_sum = 0.0
for deposit in data['operations']:
if deposit['transactionHash'] not in deposits and deposit['to'] == user_dto.eth_address:
if deposit['transactionHash'] not in deposits and deposit['to'] == user_dto.eth_address.lower():
deposit_dto = DepositDTO(
tx_id=deposit['transactionHash'],
user_id=user_dto.id,
Expand All @@ -148,7 +148,7 @@ async def get_usdc_erc20_balance(user_dto: UserDTO, deposits):
deposit.network == "ETH" and deposit.token_name == "USDC_ERC20"]
deposits_sum = 0.0
for deposit in data['operations']:
if deposit['transactionHash'] not in deposits and deposit['to'] == user_dto.eth_address:
if deposit['transactionHash'] not in deposits and deposit['to'] == user_dto.eth_address.lower():
deposit_dto = DepositDTO(
tx_id=deposit['transactionHash'],
user_id=user_dto.id,
Expand Down
11 changes: 11 additions & 0 deletions repositories/buy.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,14 @@ async def get_by_timedelta(timedelta: StatisticsTimeDelta) -> list[BuyDTO]:
async with get_db_session() as session:
buys = await session_execute(stmt, session)
return [BuyDTO.model_validate(buy, from_attributes=True) for buy in buys.scalars().all()]

@staticmethod
async def get_max_page_purchase_history(buyerd_id: int) -> int:
stmt = select(func.count(Buy.id)).where(Buy.buyer_id == buyerd_id)
async with get_db_session() as session:
not_refunded_buys = await session_execute(stmt, session)
not_refunded_buys = not_refunded_buys.scalar_one()
if not_refunded_buys % config.PAGE_ENTRIES == 0:
return not_refunded_buys / config.PAGE_ENTRIES - 1
else:
return math.trunc(not_refunded_buys / config.PAGE_ENTRIES)
5 changes: 4 additions & 1 deletion services/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from enums.bot_entity import BotEntity
from enums.cryptocurrency import Cryptocurrency
from enums.user import UserResponse
from handlers.common.common import add_pagination_buttons
from models.user import User, UserDTO
from repositories.buy import BuyRepository
from repositories.buyItem import BuyItemRepository
Expand Down Expand Up @@ -135,7 +136,9 @@ async def get_purchase_history_buttons(callback: CallbackQuery, telegram_id: int
args_for_action=buy.id
))
kb_builder.adjust(1)
kb_builder.row(unpacked_cb.get_back_button(0))
kb_builder = await add_pagination_buttons(kb_builder, unpacked_cb,
BuyRepository.get_max_page_purchase_history(user.id),
unpacked_cb.get_back_button(0))
if len(kb_builder.as_markup().inline_keyboard) > 1:
return Localizator.get_text(BotEntity.USER, "purchases"), kb_builder
else:
Expand Down

0 comments on commit c9b3842

Please sign in to comment.