mirror of
https://github.com/bohd4nx/FragmentAPI.git
synced 2026-07-25 06:14:29 +00:00
fix: cast cookies to dict for type safety and improve error handling in FragmentClient
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
from typing import cast
|
||||||
|
|
||||||
from pyfragment.methods.premium import purchase_premium
|
from pyfragment.methods.premium import purchase_premium
|
||||||
from pyfragment.methods.stars import purchase_stars
|
from pyfragment.methods.stars import purchase_stars
|
||||||
@@ -71,7 +72,7 @@ class FragmentClient:
|
|||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
raise CookieError(CookieError.READ_FAILED.format(exc=exc)) from exc
|
raise CookieError(CookieError.READ_FAILED.format(exc=exc)) from exc
|
||||||
|
|
||||||
missing_keys = [k for k in REQUIRED_COOKIE_KEYS if not str(cookies.get(k, "")).strip()]
|
missing_keys = [k for k in REQUIRED_COOKIE_KEYS if not str(cast(dict, cookies).get(k, "")).strip()]
|
||||||
if missing_keys:
|
if missing_keys:
|
||||||
raise CookieError(CookieError.MISSING_KEYS.format(keys=", ".join(missing_keys)))
|
raise CookieError(CookieError.MISSING_KEYS.format(keys=", ".join(missing_keys)))
|
||||||
|
|
||||||
@@ -85,7 +86,7 @@ class FragmentClient:
|
|||||||
|
|
||||||
self.seed: str = seed.strip()
|
self.seed: str = seed.strip()
|
||||||
self.api_key: str = api_key.strip()
|
self.api_key: str = api_key.strip()
|
||||||
self.cookies: dict = cookies
|
self.cookies: dict = cast(dict, cookies)
|
||||||
self.wallet_version: WalletVersion = version # type: ignore[assignment]
|
self.wallet_version: WalletVersion = version # type: ignore[assignment]
|
||||||
self.timeout: float = timeout
|
self.timeout: float = timeout
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
from typing import Literal, get_args
|
from typing import Any, Literal, get_args
|
||||||
|
|
||||||
from tonutils.contracts.wallet import WalletV4R2, WalletV5R1
|
from tonutils.contracts.wallet import WalletV4R2, WalletV5R1
|
||||||
|
|
||||||
@@ -8,7 +8,7 @@ WalletVersion = Literal["V4R2", "V5R1"]
|
|||||||
SUPPORTED_WALLET_VERSIONS: frozenset[str] = frozenset(get_args(WalletVersion))
|
SUPPORTED_WALLET_VERSIONS: frozenset[str] = frozenset(get_args(WalletVersion))
|
||||||
|
|
||||||
# Wallet class map — used to resolve the correct contract from WALLET_VERSION
|
# Wallet class map — used to resolve the correct contract from WALLET_VERSION
|
||||||
WALLET_CLASSES: dict[str, type] = {"V4R2": WalletV4R2, "V5R1": WalletV5R1}
|
WALLET_CLASSES: dict[str, Any] = {"V4R2": WalletV4R2, "V5R1": WalletV5R1}
|
||||||
|
|
||||||
# Minimum wallet balance required to cover TON network gas fees.
|
# Minimum wallet balance required to cover TON network gas fees.
|
||||||
MIN_TON_BALANCE: float = 0.056
|
MIN_TON_BALANCE: float = 0.056
|
||||||
|
|||||||
@@ -78,6 +78,8 @@ async def process_transaction(client: "FragmentClient", transaction_data: dict)
|
|||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
raise TransactionError(TransactionError.BROADCAST_FAILED.format(exc=exc)) from exc
|
raise TransactionError(TransactionError.BROADCAST_FAILED.format(exc=exc)) from exc
|
||||||
|
|
||||||
|
raise TransactionError(TransactionError.BROADCAST_FAILED.format(exc="transfer loop exited without result"))
|
||||||
|
|
||||||
|
|
||||||
async def get_account_info(client: "FragmentClient") -> dict[str, Any]:
|
async def get_account_info(client: "FragmentClient") -> dict[str, Any]:
|
||||||
"""Fetch wallet address, public key, and state-init for the Fragment API.
|
"""Fetch wallet address, public key, and state-init for the Fragment API.
|
||||||
|
|||||||
Reference in New Issue
Block a user