From d4ef18c632472cdac357d6ea9d8e59e47ac2cf6e Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Tue, 29 Apr 2025 10:13:43 +0000 Subject: [PATCH] swap: ETH display fix, reload quote only after timeout --- mmgen/proto/eth/tx/info.py | 4 ++-- mmgen/tx/completed.py | 3 +++ mmgen/tx/info.py | 2 +- mmgen/tx/new.py | 4 +++- mmgen/tx/new_swap.py | 3 +++ 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/mmgen/proto/eth/tx/info.py b/mmgen/proto/eth/tx/info.py index b4d8e567..f4a39da2 100755 --- a/mmgen/proto/eth/tx/info.py +++ b/mmgen/proto/eth/tx/info.py @@ -49,7 +49,7 @@ class TxInfo(TxInfo): f = t['from'].hl(0), t = to_addr.hl(0) if to_addr else blue('None'), a = t['amt'].hl(), - toaddr = ('Router:' if tokenswap else 'To:').ljust(8), + toaddr = ('Router:' if tokenswap else 'Vault:' if tx.is_swap else 'To:').ljust(8), tvault = (f'\nVault: {cyan(tx.token_vault_addr)}' if tokenswap else ''), n = t['nonce'].hl(), d = blue('None') if not td else '{}... ({} bytes)'.format(td[:40], len(td)//2), @@ -58,7 +58,7 @@ class TxInfo(TxInfo): g = yellow(tx.pretty_fmt_fee(t['gasPrice'].to_unit('Gwei'))), G = yellow(tx.pretty_fmt_fee(t['startGas'].to_unit('Kwei'))), f_mmid = mmid_disp(tx.inputs[0]), - t_mmid = mmid_disp(tx.outputs[0]) if tx.outputs and not tokenswap else '') + '\n\n' + t_mmid = mmid_disp(tx.outputs[0]) if tx.outputs and not tx.is_swap else '') + '\n\n' def format_abs_fee(self, iwidth, /, *, color=None): return self.tx.fee.fmt(iwidth, color=color) + (' (max)' if self.tx.txobj['data'] else '') diff --git a/mmgen/tx/completed.py b/mmgen/tx/completed.py index 54cf3f21..39e1429a 100755 --- a/mmgen/tx/completed.py +++ b/mmgen/tx/completed.py @@ -100,3 +100,6 @@ class Completed(Base): else: raise ValueError('Swap to non-wallet address forbidden (override with --allow-non-wallet-swap)') return self.Output(proto, addr=p.address, mmid=mmid, amt=proto.coin_amt('0')) + + if self.is_swap: + raise ValueError('missing or invalid memo in swap transaction') diff --git a/mmgen/tx/info.py b/mmgen/tx/info.py index 7ad0b52a..b7991436 100755 --- a/mmgen/tx/info.py +++ b/mmgen/tx/info.py @@ -82,7 +82,7 @@ class TxInfo: yield ' Swap: {}\n'.format(orange(f'{tx.send_asset.name} => {tx.recv_asset.name}')) yield ' Dest: {}{}\n'.format( cyan(p.address), - orange(f' ({recv_mmid})') if recv_mmid else '') + orange(f' {recv_mmid}') if recv_mmid else '') if not recv_mmid: yield yellow(' Warning: swap destination address is not a wallet address!\n') diff --git a/mmgen/tx/new.py b/mmgen/tx/new.py index 85123a8d..3a76d8d3 100755 --- a/mmgen/tx/new.py +++ b/mmgen/tx/new.py @@ -515,7 +515,9 @@ class New(Base): self.add_comment() # edits an existing comment if self.is_swap: - await self.update_vault_output(self.vault_output.amt) + import time + if time.time() > self.swap_quote_refresh_time + self.swap_quote_refresh_timeout: + await self.update_vault_output(self.vault_output.amt) await self.create_serialized(locktime=locktime) # creates self.txid too diff --git a/mmgen/tx/new_swap.py b/mmgen/tx/new_swap.py index 25f30375..596ffd6c 100755 --- a/mmgen/tx/new_swap.py +++ b/mmgen/tx/new_swap.py @@ -39,6 +39,7 @@ def get_send_proto(cfg): class NewSwap(New): desc = 'swap transaction' + swap_quote_refresh_timeout = 30 def __init__(self, *args, **kwargs): self.is_swap = True @@ -183,6 +184,7 @@ class NewSwap(New): async def update_vault_output(self, amt, *, deduct_est_fee=False): c = self.swap_proto_mod.rpc_client(self, amt) + import time from ..util import msg from ..term import get_char @@ -197,6 +199,7 @@ class NewSwap(New): while True: self.cfg._util.qmsg(f'Retrieving data from {c.rpc.host}...') c.get_quote() + self.swap_quote_refresh_time = time.time() trade_limit = get_trade_limit() self.cfg._util.qmsg('OK') msg(await c.format_quote(trade_limit, self.usr_trade_limit, deduct_est_fee=deduct_est_fee))