Skip to content
This repository was archived by the owner on Jan 29, 2023. It is now read-only.
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
71 changes: 36 additions & 35 deletions electrum_gui/android/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def update_status(self):
out["tokens"] = contracts_balance_info
out["sum_fiat"] = f"{self.daemon.fx.ccy_amount_str(sum_fiat, True)} {self.ccy}"
out["coin_asset"] = self._fill_balance_info_with_coin(sum_fiat, coin)
out["name"] = self.wallet.identity
out["id"] = self.wallet.identity
elif (
self.network
and self.network.is_connected()
Expand All @@ -343,7 +343,7 @@ def update_status(self):
out["tokens"] = []
out["sum_fiat"] = fiat_str
out["coin_asset"] = out["balance"]
out["name"] = self.wallet.identity
out["id"] = self.wallet.identity

if u:
out["unconfirmed"] = self.format_amount(u, is_diff=True).strip()
Expand Down Expand Up @@ -3299,7 +3299,7 @@ def create( # noqa
self.wallet_context.set_backup_info(wallet.keystore.xpub)
ret = {
"seed": seed if new_seed else "",
"wallet_info": [{"coin_type": coin, "name": wallet.identity, "exist": 0}],
"wallet_info": [{"coin_type": coin, "id": wallet.identity, "exist": 0}],
"derived_info": [],
}
return json.dumps(ret)
Expand Down Expand Up @@ -3465,8 +3465,8 @@ def filter_wallet(self):
{
"coin": coin,
"blance": balance,
"name": str(wallets[index]),
"label": wallets[index].get_name(),
"id": wallets[index].identity,
"name": wallets[index].get_name(),
"exist": "1"
if self.daemon.get_wallet(self._wallet_path(wallets[index].identity)) is not None
else "0",
Expand All @@ -3482,8 +3482,8 @@ def filter_wallet(self):
{
"coin": coin,
"blance": balance,
"name": str(wallet),
"label": wallet.get_name(),
"id": wallet.identity,
"name": wallet.get_name(),
"exist": "1"
if self.daemon.get_wallet(self._wallet_path(wallet.identity)) is not None
else "0",
Expand Down Expand Up @@ -3586,9 +3586,9 @@ def filter_wallet_with_account_is_zero(self):
exist = 1 if self.daemon.get_wallet(self._wallet_path(wallet_id)) is not None else 0
wallet_info = {
'coin_type': coin,
'name': wallet.identity,
'id': wallet.identity,
'exist': exist,
'label': wallet.get_name(),
'name': wallet.get_name(),
}
wallet_list.append(wallet_info)
except BaseException as e:
Expand Down Expand Up @@ -3819,18 +3819,18 @@ def get_all_wallet_balance(self):
"btc_asset":"",
"wallet_info": [
{
"name": "",
"id": "",
"coin":""
"label": "",
"name": "",
"sum_fiat": "1,333.55",
"wallets": [
{"coin": "btc", "address":"", "balance": "", "fiat": "", "icon":""}
]
},
{
"name": "",
"id": "",
"coin":""
"label": "",
"name": "",
"sum_fiat": "",
"wallets": [
{ "coin": "btc", "address":"", "balance": "", "fiat": "", "icon":""},
Expand All @@ -3845,7 +3845,7 @@ def get_all_wallet_balance(self):
all_balance = Decimal("0")
all_wallet_info = []
for wallet in self.daemon.get_wallets().values():
wallet_info = {"name": wallet.identity, "label": wallet.get_name()}
wallet_info = {"name": wallet.get_name(), "id": wallet.identity}
coin = wallet.coin
wallet_info["coin"] = coin
chain_affinity = _get_chain_affinity(coin)
Expand Down Expand Up @@ -3881,7 +3881,7 @@ def get_all_wallet_balance(self):
) # sort no-zero balance wallet by fiat currency in reverse order

zero_balance_wallets = (i for i in all_wallet_info if i["sum_fiat"] <= 0)
zero_balance_wallets_dict = {i["name"]: i for i in zero_balance_wallets}
zero_balance_wallets_dict = {i["id"]: i for i in zero_balance_wallets}
sorted_wallet_labels = (i[0] for i in self.wallet_context.get_stored_wallets_types())

zero_balance_wallets = [
Expand Down Expand Up @@ -4176,40 +4176,40 @@ def update_wallet_name(self, old_name, new_name):
except BaseException as e:
raise e

def switch_wallet(self, name):
def switch_wallet(self, id):
"""
Switching to a specific wallet
:param name: name as string
:param id: id as string
:return: json like
{
"id": "",
"name": "",
"label": "",
"wallets": [
{"coin": "usdt", "address": ""},
...
]
}
"""
self._assert_daemon_running()
if name is None:
if id is None:
raise FailedToSwitchWallet()

self.wallet = self.daemon.get_wallet(self._wallet_path(name))
self.wallet = self.daemon.get_wallet(self._wallet_path(id))
# self.wallet.use_change = self.config.get("use_change", False)
chain_affinity = _get_chain_affinity(self.wallet.coin)
if chain_affinity == "eth":
contract_info = self.wallet.get_contract_symbols_with_address()

info = {"name": name, "label": self.wallet.get_name(), "wallets": contract_info}
info = {"id": id, "name": self.wallet.get_name(), "wallets": contract_info}
elif chain_affinity == "btc":
if not isinstance(self.wallet, Imported_Wallet):
self.wallet.set_key_pool_size()
c, u, x = self.wallet.get_balance()
util.trigger_callback("wallet_updated", self.wallet)

info = {
"name": name,
"label": self.wallet.get_name(),
"id": id,
"name": self.wallet.get_name(),
"wallets": [],
}
if self.label_flag and self.wallet.wallet_type != "standard":
Expand All @@ -4226,6 +4226,7 @@ def get_wallet_balance(self):
"all_balance": "",
"coin_asset":"",
"coin":"",
"id":"",
"name":"",
"wallets": [
{"coin": "eth", "address": "", "balance": "", "fiat": "", "icon":""},
Expand All @@ -4235,7 +4236,7 @@ def get_wallet_balance(self):
"""
self._assert_wallet_isvalid()
coin = self.wallet.coin
info = {"name": self.wallet.identity, "label": self.wallet.get_name(), "coin": coin}
info = {"id": self.wallet.identity, "name": self.wallet.get_name(), "coin": coin}
chain_affinity = _get_chain_affinity(coin)
if chain_affinity == "eth":
main_balance_info, contracts_balance_info, sum_fiat = self._get_eth_wallet_all_balance(self.wallet)
Expand Down Expand Up @@ -4272,25 +4273,25 @@ def get_wallet_balance(self):
raise UnsupportedCurrencyCoin()
return json.dumps(info, cls=DecimalEncoder)

def select_wallet(self, name): # TODO: Will be deleted later
def select_wallet(self, id): # TODO: Will be deleted later
"""
Select wallet by name
:param name: name as string
:return: json like
{
"id": "",
"name": "",
"label": "",
"wallets": [
{"coin": "eth", "balance": "", "fiat": ""},
{"coin": "usdt", "balance": "", "fiat": ""}
]
}
"""
self._assert_daemon_running()
if name is None:
if id is None:
self.wallet = None
else:
self.wallet = self.daemon.get_wallet(self._wallet_path(name))
self.wallet = self.daemon.get_wallet(self._wallet_path(id))

self.wallet.use_change = self.config.get("use_change", False)
coin = self.wallet.coin
Expand All @@ -4300,8 +4301,8 @@ def select_wallet(self, name): # TODO: Will be deleted later
self.wallet, with_sum_fiat=False
)
info = {
"name": name,
"label": self.wallet.get_name(),
"id": id,
"name": self.wallet.get_name(),
"wallets": [main_balance_info] + contracts_balance_info,
}
return json.dumps(info, cls=DecimalEncoder)
Expand All @@ -4314,8 +4315,8 @@ def select_wallet(self, name): # TODO: Will be deleted later
fiat_str = f"{self.daemon.fx.ccy_amount_str(fiat, True)} {self.ccy}"
info = {
"balance": self.format_amount(balance) + " (%s)" % fiat_str, # fixme deprecated field
"name": name,
"label": self.wallet.get_name(),
"id": id,
"name": self.wallet.get_name(),
"wallets": [{"coin": "btc", "balance": self.format_amount(balance), "fiat": fiat_str}],
}
if self.label_flag and self.wallet.wallet_type != "standard":
Expand Down Expand Up @@ -4397,7 +4398,7 @@ def list_wallets(self, type_=None):
"""
List available wallets
:param type: None/hw/hd/btc/eth/bsc/heco/okt
:return: json like "[{"wallet_key":{'type':"", "addr":"", "name":"", "label":"", "device_id": ""}}, ...]"
:return: json like "[{"wallet_key":{'type':"", "addr":"", "id":"", "name":"", "device_id": ""}}, ...]"
exp:
all_list = testcommond.list_wallets()
hd_list = testcommond.list_wallets(type='hd')
Expand Down Expand Up @@ -4428,8 +4429,8 @@ def list_wallets(self, type_=None):
wallet_id: {
"type": wallet_type,
"addr": wallet.get_addresses()[0],
"name": wallet.identity,
"label": wallet.get_name(),
"id": wallet.identity,
"name": wallet.get_name(),
"device_id": device_id,
}
}
Expand Down