tw.unspent: separate status messages for added and edited labels

This commit is contained in:
The MMGen Project 2022-08-15 12:38:45 +00:00
commit 784ae44596
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
2 changed files with 24 additions and 14 deletions

View file

@ -283,24 +283,29 @@ class TwUnspentOutputs(MMGenObject,TwCommon,metaclass=AsyncInit):
e = uo.data[idx-1]
if await uo.wallet.add_label( e.twmmid, lbl, coinaddr=e.addr ):
await uo.get_data()
uo.oneshot_msg = yellow('Label {} {} #{}\n\n'.format(
('added to' if lbl else 'removed from'),
uo.item_desc,
idx ))
uo.oneshot_msg = yellow('Label {a} {b}{c}\n\n'.format(
a = 'to' if cur_lbl and lbl else 'added to' if lbl else 'removed from',
b = desc,
c = ' edited' if cur_lbl and lbl else '' ))
else:
await asyncio.sleep(3)
uo.oneshot_msg = red('Label could not be added\n\n')
uo.oneshot_msg = red('Label could not be {}\n\n'.format(
'edited' if cur_lbl and lbl else
'added' if lbl else
'removed' ))
desc = f'{uo.item_desc} #{idx}'
cur_lbl = uo.data[idx-1].label
msg('Current label: {}'.format(cur_lbl.hl() if cur_lbl else '(none)'))
res = line_input(
"Enter label text (or ENTER to return to main menu): ",
insert_txt = cur_lbl )
if res == cur_lbl:
return None
elif res == '':
return (await do_lbl_add(res)) if keypress_confirm(
f'Removing label for {uo.item_desc} #{idx}. Is this what you want?') else 'redo'
return (await do_lbl_add('')) if keypress_confirm(
f'Removing label for {desc}. Is this what you want?') else 'redo'
else:
return (await do_lbl_add(res)) if get_obj(TwComment,s=res) else 'redo'

View file

@ -347,8 +347,9 @@ class TestSuiteEthdev(TestSuiteBase,TestSuiteShared):
'label': (
'creating, editing and removing labels',
('edit_label1', f'adding label to addr #{del_addrs[0]} in {coin} tracking wallet (zh)'),
('edit_label2', f'adding label to addr #{del_addrs[1]} in {coin} tracking wallet (lat+cyr+gr)'),
('edit_label3', f'removing label from addr #{del_addrs[0]} in {coin} tracking wallet'),
('edit_label2', f'editing label for addr #{del_addrs[0]} in {coin} tracking wallet (zh)'),
('edit_label3', f'adding label to addr #{del_addrs[1]} in {coin} tracking wallet (lat+cyr+gr)'),
('edit_label4', f'removing label from addr #{del_addrs[0]} in {coin} tracking wallet'),
('token_edit_label1', f'adding label to addr #{del_addrs[0]} in {coin} token tracking wallet'),
),
'remove': (
@ -1271,16 +1272,18 @@ class TestSuiteEthdev(TestSuiteBase,TestSuiteShared):
def token_twview3(self):
return self.twview(args=['--token=mm1'],tool_args=['wide=1','sort=age'])
def edit_label(self,out_num,args=[],action='l',label_text=None):
def edit_label(self,out_num,args=[],action='l',label_text=None,changed=False):
t = self.spawn('mmgen-txcreate', self.eth_args + args + ['-B','-i'])
p1,p2 = ('efresh balance:\b','return to main menu): ')
p3,r3 = (p2,label_text+'\n') if label_text is not None else ('(y/N): ','y')
p4,r4 = (('(y/N): ',),('y',)) if label_text == self.erase_input else ((),())
for p,r in zip((p1,p1,p2,p3)+p4,('M',action,out_num+'\n',r3)+r4):
t.expect(p,r)
m = ( 'Account #{} removed' if action == 'D' else
'Label added to account #{}' if label_text and label_text != self.erase_input else
'Label removed from account #{}' )
m = (
'Label to account #{} edited' if changed else
'Account #{} removed' if action == 'D' else
'Label added to account #{}' if label_text and label_text != self.erase_input else
'Label removed from account #{}' )
t.expect(m.format(out_num))
for p,r in zip((p1,p1),('M','q')):
t.expect(p,r)
@ -1290,8 +1293,10 @@ class TestSuiteEthdev(TestSuiteBase,TestSuiteShared):
def edit_label1(self):
return self.edit_label(out_num=del_addrs[0],label_text=tw_label_zh)
def edit_label2(self):
return self.edit_label(out_num=del_addrs[1],label_text=tw_label_lat_cyr_gr)
return self.edit_label(out_num=del_addrs[0],label_text=tw_label_zh[:-1],changed=True)
def edit_label3(self):
return self.edit_label(out_num=del_addrs[1],label_text=tw_label_lat_cyr_gr)
def edit_label4(self):
return self.edit_label(out_num=del_addrs[0],label_text=self.erase_input)
def token_edit_label1(self):