XaBbl4 / pytonconnect

Python SDK for TON Connect 2.0
Apache License 2.0
41 stars 10 forks source link

Incorrect Key for Chain Data in Account.from_dict Method #9

Open skyline9981 opened 2 months ago

skyline9981 commented 2 months ago

Hello,

I've encountered an issue with the Account class in this package. Specifically, the issue arises in the from_dict static method.

Description: The method currently tries to retrieve the chain data using ton_addr['network']. However, in the data returned from the frontend, this piece of information is actually provided under the key 'chain', not 'network'.

Affected Code:

def from_dict(ton_addr: dict):
    if 'address' not in ton_addr:
        raise TonConnectError('address not contains in ton_addr')

    account = Account()
    account.address = ton_addr['address']
    account.chain = ton_addr['network']  # This line needs correction
    account.wallet_state_init = ton_addr['walletStateInit']
    account.public_key = ton_addr.get('publicKey', None)
    return account

Expected Behavior: The method should correctly map the 'chain' key from the input dictionary to the chain attribute of the Account object.

Proposed Fix: Update the line where the chain is assigned:

account.chain = ton_addr['chain']

I believe this correction will align the backend handling of the data with the structure provided by the frontend.

Thank you for looking into this matter. Please let me know if I can provide any more details.