Browse Source

TwView.item_action.i_comment_add(): inline nested function

The MMGen Project 1 week ago
parent
commit
3d8e1223a1
1 changed files with 22 additions and 25 deletions
  1. 22 25
      mmgen/tw/view.py

+ 22 - 25
mmgen/tw/view.py

@@ -810,29 +810,6 @@ class TwView(MMGenObject, metaclass=AsyncInit):
 
 
 		async def i_comment_add(self, parent, idx, acct_addr_idx=None):
 		async def i_comment_add(self, parent, idx, acct_addr_idx=None):
 
 
-			async def do_comment_add(comment_in):
-				from ..obj import TwComment
-				new_comment = await parent.twctl.set_comment(
-					addrspec     = None,
-					comment      = comment_in,
-					trusted_pair = (entry.twmmid, entry.addr),
-					silent       = parent.scroll)
-
-				edited = old_comment and new_comment
-				if isinstance(new_comment, TwComment):
-					entry.comment = new_comment
-					parent.oneshot_msg = (green if new_comment else yellow)('Label {a} {b}{c}'.format(
-						a = 'for' if edited else 'added to' if new_comment else 'removed from',
-						b = desc,
-						c = ' edited' if edited else ''))
-					return 'redraw' if parent.cfg.coin == 'XMR' else True
-				else:
-					await asyncio.sleep(3)
-					parent.oneshot_msg = red('Label for {desc} could not be {action}'.format(
-						desc = desc,
-						action = 'edited' if edited else 'added' if new_comment else 'removed'))
-					return False
-
 			if acct_addr_idx is None:
 			if acct_addr_idx is None:
 				desc       = f'{parent.item_desc} #{idx}'
 				desc       = f'{parent.item_desc} #{idx}'
 				color_desc = f'{parent.item_desc} {red("#" + str(idx))}'
 				color_desc = f'{parent.item_desc} {red("#" + str(idx))}'
@@ -845,7 +822,7 @@ class TwView(MMGenObject, metaclass=AsyncInit):
 			msg('Current label: {}'.format(old_comment.hl() if old_comment else '(none)'))
 			msg('Current label: {}'.format(old_comment.hl() if old_comment else '(none)'))
 
 
 			from ..ui import line_input
 			from ..ui import line_input
-			match res:= line_input(
+			match comment_in := line_input(
 					parent.cfg,
 					parent.cfg,
 					f'Enter label text for {color_desc}: ',
 					f'Enter label text for {color_desc}: ',
 					insert_txt = old_comment):
 					insert_txt = old_comment):
@@ -856,7 +833,27 @@ class TwView(MMGenObject, metaclass=AsyncInit):
 					if not parent.keypress_confirm(f'Removing label for {color_desc}. OK?'):
 					if not parent.keypress_confirm(f'Removing label for {color_desc}. OK?'):
 						return 'redo'
 						return 'redo'
 
 
-			return await do_comment_add(res)
+			from ..obj import TwComment
+			new_comment = await parent.twctl.set_comment(
+				addrspec     = None,
+				comment      = comment_in,
+				trusted_pair = (entry.twmmid, entry.addr),
+				silent       = parent.scroll)
+
+			edited = old_comment and new_comment
+			if isinstance(new_comment, TwComment):
+				entry.comment = new_comment
+				parent.oneshot_msg = (green if new_comment else yellow)('Label {a} {b}{c}'.format(
+					a = 'for' if edited else 'added to' if new_comment else 'removed from',
+					b = desc,
+					c = ' edited' if edited else ''))
+				return 'redraw' if parent.cfg.coin == 'XMR' else True
+			else:
+				await asyncio.sleep(3)
+				parent.oneshot_msg = red('Label for {desc} could not be {action}'.format(
+					desc = desc,
+					action = 'edited' if edited else 'added' if new_comment else 'removed'))
+				return False
 
 
 	class scroll_action:
 	class scroll_action: