swap: variable, method renames

This commit is contained in:
The MMGen Project 2025-05-19 09:23:55 +00:00
commit 0dcfaa2f34
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
4 changed files with 11 additions and 11 deletions

View file

@ -117,20 +117,20 @@ class Thornode:
if trade_limit:
from . import ExpInt4
e = ExpInt4(trade_limit.to_unit('satoshi'))
tl_rounded = UniAmt(e.trunc, from_unit='satoshi')
ratio = usr_trade_limit if type(usr_trade_limit) is float else float(tl_rounded / out_amt)
tl_int = ExpInt4(trade_limit.to_unit('satoshi'))
tl_uniamt = UniAmt(tl_int.trunc, from_unit='satoshi')
ratio = usr_trade_limit if type(usr_trade_limit) is float else float(tl_uniamt / out_amt)
direction = 'ABOVE' if ratio > 1 else 'below'
mcolor, lblcolor = (
(redbg, redbg) if (ratio < 0.93 or ratio > 0.999) else
(yelbg, yelbg) if ratio < 0.97 else
(green, grnbg))
trade_limit_disp = f"""
{lblcolor('Trade limit:')} {tl_rounded.hl()} {out_coin} """ + mcolor(
{lblcolor('Trade limit:')} {tl_uniamt.hl()} {out_coin} """ + mcolor(
f'({abs(1 - ratio) * 100:0.2f}% {direction} expected amount)')
tx_size_adj = len(e.enc) - 1
tx_size_adj = len(tl_int.enc) - 1
if tx.proto.is_evm:
tx.adj_gas_with_extra_data_len(len(e.enc) - 1) # one-shot method, no-op if repeated
tx.adj_gas_with_extra_data_len(len(tl_int.enc) - 1) # one-shot method, no-op if repeated
else:
trade_limit_disp = ''
tx_size_adj = 0

View file

@ -87,7 +87,7 @@ class Bump(Completed, NewSwap):
if self.is_swap:
self.recv_proto = self.check_swap_memo().proto
self.process_swap_options()
self.init_swap_cfg()
fee_hint = await self.update_vault_output(self.send_amt)
else:
fee_hint = None

View file

@ -453,7 +453,7 @@ class New(Base):
cmd_args, addrfile_args = self.get_addrfiles_from_cmdline(cmd_args)
if self.is_swap:
cmd_args = await self.process_swap_cmdline_args(cmd_args, addrfile_args)
self.process_swap_options()
self.init_swap_cfg()
from ..rpc import rpc_init
self.rpc = await rpc_init(self.cfg, self.proto)
from ..addrdata import TwAddrData

View file

@ -166,7 +166,7 @@ class NewSwap(New):
[f'vault,{args.send_amt}', chg_output.mmid, f'data:{memo}'] if args.send_amt else
['vault', f'data:{memo}'])
def process_swap_options(self):
def init_swap_cfg(self):
if s := self.cfg.trade_limit:
self.usr_trade_limit = (
1 - float(s[:-1]) / 100 if s.endswith('%') else
@ -199,10 +199,10 @@ class NewSwap(New):
while True:
self.cfg._util.qmsg(f'Retrieving data from {c.rpc.host}...')
c.get_quote()
await self.set_gas(to_addr=c.router if self.is_token else None)
self.swap_quote_refresh_time = time.time()
trade_limit = get_trade_limit()
self.cfg._util.qmsg('OK')
self.swap_quote_refresh_time = time.time()
await self.set_gas(to_addr=c.router if self.is_token else None)
trade_limit = get_trade_limit()
msg(await c.format_quote(trade_limit, self.usr_trade_limit, deduct_est_fee=deduct_est_fee))
ch = get_char('Press ‘r’ to refresh quote, any other key to continue: ')
msg('')