# Wallets menu

**Selecting a wallet**

If already you have created wallet / wallets, the only thing you need to do is made a choice of the pull out list, and confim you decision clicking "Confirm choice" button and alternatively entering your decription key ("Encryption" Section).

<figure><img src="/files/kCZVabl9tNfzjPmyHKIL" alt=""><figcaption></figcaption></figure>

```python
def list_wallets():
    directory = create_wallet_directory()
    wallets = [f for f in os.listdir(directory) if f.endswith('.txt') or f.endswith('.dat')]
    return wallets
```

```python
def on_wallet_confirm(self):
    selected_wallet_display = self.wallet_option_menu.get()
    wallets = list_wallets()
    wallet_filenames = {f[:-4]: f for f in wallets}
    wallet_filename = wallet_filenames.get(selected_wallet_display)
    if wallet_filename:
        self.current_wallet = wallet_filename
        self.wallet_switch_counter += 1
        current_counter = self.wallet_switch_counter

        self.token_list = []

        if wallet_filename.endswith('.dat'):
            if wallet_filename in self.decrypted_wallets:
                public_key, private_key_base58 = self.decrypted_wallets[wallet_filename]
            else:
                passphrase, _ = self.prompt_for_passphrase(title="Unlock wallet", allow_no_encrypt=False)
                if passphrase is None:
                    self.show_message("Passphrase is required to decrypt the wallet.", "Error")
                    self.current_wallet = None
                    self.selected_wallet_label.configure(text="Selected wallet: None")
                    self.navigate_to(self.wallet_menu)
                    return
                public_key, private_key_base58 = get_wallet_details(wallet_filename, passphrase)
                if public_key is None:
                    self.show_message("Incorrect passphrase. Failed to decrypt the wallet.", "Error")
                    self.current_wallet = None
                    self.selected_wallet_label.configure(text="Selected wallet: None")
                    self.navigate_to(self.wallet_menu)
                    return
                self.decrypted_wallets[wallet_filename] = (public_key, private_key_base58)
        elif wallet_filename.endswith('.txt'):
            public_key, private_key_base58 = get_wallet_details(wallet_filename)
            if public_key is None:
                self.show_message("Failed to load wallet details.", "Error")
                self.navigate_to(self.wallet_menu)
                return

        if public_key is None:
            self.show_message("Failed to load wallet details.", "Error")
            self.navigate_to(self.wallet_menu)
            return

        self.wallet_actions_menu(wallet_filename, current_counter, public_key, private_key_base58)
        formatted_name = selected_wallet_display
        self.selected_wallet_label.configure(text=f"Selected wallet: {formatted_name}")

```

\
**Displaying tokens according to public key**

After confirmation your choice, the Terminal is going to display all Solana assets which specific wallet posses. View of assets includes:

* Ticker
* Balance (with accuracy to 3 places after dot)
* Estimated value in USD (with accuracy to 2 places after dot)
* Comfortable way to swap or audit selected token (check "Terminal" Section)

<figure><img src="/files/OoC4e8tHcc40Af5j9bhs" alt=""><figcaption></figcaption></figure>

Identifying tokens:

```python
def get_token_by_ca(contract_address, endpoint):
    url = f"https://api.dexscreener.com/latest/dex/tokens/{contract_address}"
    try:
        response = requests.get(url, timeout=10)
        if response.status_code == 200:
            token_data = response.json()
            if token_data.get('pairs'):
                return token_data['pairs'][0]
            else:
                return None
        else:
            return None
    except requests.RequestException as e:
        print(f"Dexscreener API Error for CA {contract_address}: {e}")
        return None
```

Displaying values:

```python
def get_token_balances_dexscreener(self, public_key):
    client = Client(self.endpoints['fetch_transaction_history'])
    opts = TokenAccountOpts(program_id=TOKEN_PROGRAM_ID, encoding='jsonParsed')
    try:
        token_accounts = client.get_token_accounts_by_owner(PublicKey(public_key), opts)
    except Exception as e:
        print(f"Error fetching token accounts: {e}")
        return []

    tokens = []
    if token_accounts['result']['value']:
        for token_account in token_accounts['result']['value']:
            account_info = token_account['account']['data']['parsed']['info']
            token_address = account_info['mint']
            token_amount = int(account_info['tokenAmount']['amount'])
            decimals = int(account_info['tokenAmount']['decimals'])
            amount = token_amount / (10 ** decimals)

            if token_address in self.dexscreener_cache:
                symbol, price = self.dexscreener_cache[token_address]
            else:
                token_data = get_token_by_ca(token_address, self.endpoints['fetch_transaction_history'])
                if token_data:
                    symbol = token_data['baseToken']['symbol']
                    try:
                        price = float(token_data['priceUsd'])
                    except (ValueError, TypeError):
                        price = 0
                    self.dexscreener_cache[token_address] = (symbol, price)
                else:
                    symbol = "Unknown"
                    price = 0
                    self.dexscreener_cache[token_address] = (symbol, price)

            usd_value = amount * price

            if usd_value < 0.01:
                continue

            tokens.append({
                'mint': token_address,
                'symbol': symbol,
                'amount': amount,
                'decimals': decimals,
                'usd_value': usd_value
            })
    return tokens
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://low-caps-hub.gitbook.io/lowcapshubterminal/wallet-section/wallets-menu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
