diff --git a/blockapi/test/v2/api/debank/test_debank.py b/blockapi/test/v2/api/debank/test_debank.py index 781900c..763c0d7 100644 --- a/blockapi/test/v2/api/debank/test_debank.py +++ b/blockapi/test/v2/api/debank/test_debank.py @@ -232,6 +232,28 @@ def test_debank_parse_chains( assert parsed_items[0] == debank_chain_eth +def test_debank_parse_unknown_chain(debank_api, requests_mock): + requests_mock.get( + "https://pro-openapi.debank.com/v1/chain/list", + json=[ + { + "id": "new-chain", + "community_id": 1234, + "name": "New Chain", + "native_token_id": "new-chain", + "logo_url": "https://example.com/new-chain.png", + "wrapped_token_id": "new-chain", + "is_support_pre_exec": False, + } + ], + ) + + chain = debank_api.get_chains()[0] + + assert chain.chain == "new-chain" + assert chain.name == "New Chain" + + def test_get_balance_fetches_protocols( debank_api, yflink_protocol_response_raw, diff --git a/blockapi/v2/api/debank.py b/blockapi/v2/api/debank.py index ced2508..abf8a60 100644 --- a/blockapi/v2/api/debank.py +++ b/blockapi/v2/api/debank.py @@ -161,7 +161,7 @@ class DebankModelChain(BaseModel): class DebankChain(BaseModel): - chain: Blockchain + chain: Union[Blockchain, str] community_id: int name: str logo_url: str @@ -204,13 +204,8 @@ def parse(self, response: List) -> list[DebankChain]: return list(sorted(chains, key=lambda x: x.name)) @staticmethod - def parse_item(item: DebankModelChain) -> Optional[DebankChain]: - blockchain = get_blockchain_from_debank_chain(item.id) - if not blockchain: - logger.warning( - f'No blockchain found for debank chain {item.id} ({item.name}, {item.community_id}). Skipping.' - ) - return None + def parse_item(item: DebankModelChain) -> DebankChain: + blockchain = get_blockchain_from_debank_chain(item.id) or item.id return DebankChain( chain=blockchain,