@@ -150,22 +150,28 @@ impl App {
150150 . iter ( )
151151 . map ( |a| a. symbol . clone ( ) )
152152 . join ( "/" ) ;
153- let price = update
154- . states
155- . get ( id)
156- . map ( |el| el. spot_price ( & comp. tokens [ 0 ] , & comp. tokens [ 1 ] ) )
157- . unwrap_or ( Ok ( 0.0 ) )
158- . expect ( "Expected spot price as f64" ) ;
159153
160154 match update. states . get ( id) {
161155 Some ( state) => {
162- self . items . push ( Data {
163- component : comp. clone ( ) ,
164- state : state. clone ( ) ,
165- name,
166- tokens,
167- price : price. to_string ( ) ,
168- } ) ;
156+ // Check if spot_price calculation is successful
157+ match state. spot_price ( & comp. tokens [ 0 ] , & comp. tokens [ 1 ] ) {
158+ Ok ( price) => {
159+ self . items . push ( Data {
160+ component : comp. clone ( ) ,
161+ state : state. clone ( ) ,
162+ name,
163+ tokens,
164+ price : price. to_string ( ) ,
165+ } ) ;
166+ }
167+ Err ( _) => {
168+ // Skip pools with spot_price errors
169+ warn ! (
170+ "Skipping pool {comp_id} due to spot_price error" ,
171+ comp_id = comp. id
172+ ) ;
173+ }
174+ }
169175 }
170176 None => {
171177 warn ! ( "Received update for unknown pool {comp_id}" , comp_id = comp. id)
@@ -180,12 +186,20 @@ impl App {
180186 . iter ( )
181187 . find_position ( |e| e. component . id == eth_address) ;
182188 if let Some ( ( index, _) ) = entry {
183- let row = self . items . get_mut ( index) . unwrap ( ) ;
184- let price = state
185- . spot_price ( & row. component . tokens [ 0 ] , & row. component . tokens [ 1 ] )
186- . expect ( "Expected spot price as f64" ) ;
187- row. price = price. to_string ( ) ;
188- row. state = state. clone ( ) ;
189+ let row = & self . items [ index] ;
190+ match state. spot_price ( & row. component . tokens [ 0 ] , & row. component . tokens [ 1 ] ) {
191+ Ok ( price) => {
192+ // Update the price and state if calculation is successful
193+ let row = self . items . get_mut ( index) . unwrap ( ) ;
194+ row. price = price. to_string ( ) ;
195+ row. state = state. clone ( ) ;
196+ }
197+ Err ( _) => {
198+ // Remove the pool if spot_price calculation fails
199+ warn ! ( "Removing pool {} due to spot_price error" , address) ;
200+ self . items . remove ( index) ;
201+ }
202+ }
189203 }
190204 }
191205
0 commit comments