@@ -76,7 +76,7 @@ func InitialModel() Model {
7676 }
7777
7878 l := list .New (actionItems , list .NewDefaultDelegate (), 0 , 0 )
79- l .Title = "Select an action to add:"
79+ l .Title = "Select an action to add:" //nolint:goconst
8080
8181 return Model {
8282 state : actionSelection ,
@@ -109,6 +109,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
109109 m .windowHeight = msg .Height
110110 m .list .SetWidth (msg .Width )
111111 m .list .SetHeight (msg .Height - 3 )
112+
112113 return m , nil
113114 }
114115
@@ -127,10 +128,39 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
127128 return m , cmd
128129}
129130
131+ func (m Model ) View () string {
132+ var s strings.Builder
133+
134+ switch m .state {
135+ case actionSelection :
136+ m .writeActionSelection (& s )
137+ case forwardingSelection :
138+ m .writeForwardingSelection (& s )
139+ case feeActionInput :
140+ m .writeFeeActionSelection (& s )
141+ case cctpForwardingInput :
142+ m .writeCCTPForwardingSelection (& s )
143+ }
144+
145+ if m .err != nil {
146+ s .WriteString (
147+ lipgloss .NewStyle ().
148+ Foreground (lipgloss .Color ("196" )).
149+ Render ("\n Error: " + m .err .Error ()),
150+ )
151+ }
152+
153+ return s .String ()
154+ }
155+
130156func (m Model ) handleEnter () (tea.Model , tea.Cmd ) {
131157 switch m .state {
132158 case actionSelection :
133- selected := m .list .SelectedItem ().(item )
159+ selected , ok := m .list .SelectedItem ().(item )
160+ if ! ok {
161+ panic (fmt .Sprintf ("failed to cast list item to item; got: %T" , m .list .SelectedItem ()))
162+ }
163+
134164 switch selected .title {
135165 case core .ACTION_FEE .String ():
136166 return m .initFeeActionInput (), nil
@@ -142,7 +172,11 @@ func (m Model) handleEnter() (tea.Model, tea.Cmd) {
142172 case feeActionInput :
143173 return m .processFeeAction ()
144174 case forwardingSelection :
145- selected := m .list .SelectedItem ().(item )
175+ selected , ok := m .list .SelectedItem ().(item )
176+ if ! ok {
177+ panic (fmt .Sprintf ("failed to cast list item to item; got: %T" , m .list .SelectedItem ()))
178+ }
179+
146180 switch selected .title {
147181 case core .PROTOCOL_CCTP .String ():
148182 return m .initCCTPForwardingInput (), nil
@@ -154,30 +188,6 @@ func (m Model) handleEnter() (tea.Model, tea.Cmd) {
154188 case cctpForwardingInput :
155189 return m .processCCTPForwarding ()
156190 }
157- return m , nil
158- }
159-
160- func (m Model ) View () string {
161- var s strings.Builder
162-
163- switch m .state {
164- case actionSelection :
165- m .writeActionSelection (& s )
166- case forwardingSelection :
167- m .writeForwardingSelection (& s )
168- case feeActionInput :
169- m .writeFeeActionSelection (& s )
170- case cctpForwardingInput :
171- m .writeCCTPForwardingSelection (& s )
172- }
173-
174- if m .err != nil {
175- s .WriteString (
176- lipgloss .NewStyle ().
177- Foreground (lipgloss .Color ("196" )).
178- Render ("\n Error: " + m .err .Error ()),
179- )
180- }
181191
182- return s . String ()
192+ return m , nil
183193}
0 commit comments