Skip to content

Commit

Permalink
Fix balance check and provide more detail
Browse files Browse the repository at this point in the history
The check was broken during the last refactoring.
  • Loading branch information
karlb committed Nov 23, 2020
1 parent 9d8d232 commit d1d126e
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/raiden_libs/service_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,19 +221,25 @@ def send_registration_transaction(
maybe_prompt: Callable,
account_balance: int,
service_address: Address,
fmt_amount: Callable[[float], str],
) -> None:
# Get required deposit
required_deposit = service_registry_contract.functions.currentPrice().call()
click.secho(
f"\nThe current required deposit is fmt_amount({required_deposit})"
f"\nThe current required deposit is {fmt_amount(required_deposit)}"
"\n\tNote: The required deposit continuously decreases, but "
"\n\t increases significantly after a deposit is made."
)
if web3.eth.chainId == 1:
click.secho("You don't have sufficient tokens", err=True)
sys.exit(1)
elif account_balance < required_deposit:
click.secho("You are operating on a testnet. Tokens will be minted as required.")
if account_balance < required_deposit:
if web3.eth.chainId == 1:
click.secho(
f"You have {fmt_amount(account_balance)} but need {fmt_amount(required_deposit)}.",
err=True,
)
sys.exit(1)
else:
click.secho("You are operating on a testnet. Tokens will be minted as required.")

maybe_prompt(
"I have read the current deposit and understand that continuing will transfer tokens"
)
Expand Down Expand Up @@ -370,7 +376,6 @@ def maybe_prompt(query: str) -> None:
# Check current token balance
fmt_amount = get_token_formatter(deposit_token_contract)
account_balance = deposit_token_contract.functions.balanceOf(service_address).call()
fmt_amount = get_token_formatter(deposit_token_contract)
log.info("Current account balance", balance=account_balance)
click.secho(
"\nThe address of the token used is "
Expand Down Expand Up @@ -402,6 +407,7 @@ def maybe_prompt(query: str) -> None:
maybe_prompt=maybe_prompt,
account_balance=account_balance,
service_address=service_address,
fmt_amount=fmt_amount,
)
elif not currently_registered:
log.info("Address not registered in ServiceRegistry")
Expand All @@ -412,6 +418,7 @@ def maybe_prompt(query: str) -> None:
maybe_prompt=maybe_prompt,
account_balance=account_balance,
service_address=service_address,
fmt_amount=fmt_amount,
)
else:
log.info(
Expand Down

0 comments on commit d1d126e

Please sign in to comment.