swap: ETH display fix, reload quote only after timeout
This commit is contained in:
parent
19592955cb
commit
d4ef18c632
5 changed files with 12 additions and 4 deletions
|
|
@ -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 '')
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue