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

feat(definitions): network arrays in support device object #36

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 48 additions & 14 deletions coins_details/coins_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class WalletInfo(t.TypedDict):
url: str


SupportEntry = t.Dict[str, bool]
SupportEntry = t.Dict[str, list[str]]


@dataclass
Expand All @@ -46,26 +46,44 @@ def from_coin(cls, coin: Coin, support_info: dict[str, SupportEntry]) -> CoinDet
key = coin["key"]
cg_id = COINGECKO_IDS.get(key)

support = {model: [] for model in MODELS}

for model in MODELS:
if model in support_info[key]:
support[model].extend(support_info[key][model])

return cls(
id=key,
coingecko_id=cg_id,
name=coin["name"],
shortcut=coin["shortcut"],
support=support_info[key],
support=support,
networks={cg_id},
)

@classmethod
def from_eth_network(cls, network: Network) -> CoinDetail:
cg_id = network.get("coingecko_id")
key = f"eth:{network['shortcut']}:{network['chain_id']}"

support = {model: [] for model in MODELS}

for model in MODELS:
if network_cg_id:
support[model].append(network_cg_id)

new = cls(
id=key,
coingecko_id=cg_id,
name=network["name"],
shortcut=network["shortcut"],
<<<<<<< HEAD
support={model: True for model in MODELS},
networks={cg_id},
=======
support=support,
networks={network_cg_id},
>>>>>>> a42f976 (feat: supported networks per device)
)
new.wallets.extend(WALLETS_ETH_3RDPARTY)
return new
Expand All @@ -75,13 +93,19 @@ def from_eth_token(cls, token: Token, network: Network) -> CoinDetail:
cg_id = token.get("coingecko_id")
network_cg_id = network.get("coingecko_network_id")

support = {model: [] for model in MODELS}

for model in MODELS:
if network_cg_id:
support[model].append(network_cg_id)

key = f"erc20:{network['chain']}:{token['address']}"
new = cls(
id=key,
coingecko_id=cg_id,
name=token["name"],
shortcut=token["shortcut"],
support={model: True for model in MODELS},
support=support,
networks={network_cg_id},
)
network_key = f"eth:{network['shortcut']}:{network['chain_id']}"
Expand All @@ -91,12 +115,17 @@ def from_eth_token(cls, token: Token, network: Network) -> CoinDetail:

def merge(self, other: CoinDetail) -> None:
assert self.coingecko_id == other.coingecko_id, "Cannot merge different coins"
self.support = {
model: self.support[model] or other.support[model] for model in MODELS
}
for wallet in other.wallets:
if wallet not in self.wallets:
self.wallets.append(wallet)

for model in MODELS:
if not isinstance(self.support[model], list):
self.support[model] = []
if not isinstance(other.support[model], list):
other.support[model] = []

combined_support = set(self.support[model])
combined_support.update(other.support[model])
self.support[model] = list(combined_support)

self.networks.update(other.networks)

def to_json(self) -> dict[str, t.Any]:
Expand Down Expand Up @@ -131,9 +160,6 @@ def to_json(self) -> dict[str, t.Any]:

def summary(coins: dict[str, t.Any]) -> dict[str, t.Any]:
counter = {model: 0 for model in MODELS}
for coin in coins.values():
for model in counter:
counter[model] += coin["support"].get(model, False)

return dict(
updated_at=int(time.time()),
Expand Down Expand Up @@ -214,10 +240,18 @@ def main(verbose: int):

coin_info_defs, _ = coin_info.coin_info_with_duplicates()
support_info = {
key: {model: bool(value.get(model)) for model in MODELS}
for key, value in coin_info.support_info(coin_info_defs).items()
key: {model: [] for model in MODELS}
for key in coin_info.support_info(coin_info_defs)
}

for key, value in coin_info.support_info(coin_info_defs).items():
for model in MODELS:
if value.get(model):
if key in COINGECKO_IDS:
support_info[key][model].append(COINGECKO_IDS[key])
else:
support_info[key][model].append(key)

cg_ids_unfiltered: dict[str | None, CoinDetail] = {}

# Update non-ETH things from coin_info
Expand Down