File tree Expand file tree Collapse file tree 2 files changed +11
-9
lines changed Expand file tree Collapse file tree 2 files changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -101,14 +101,16 @@ class MempoolSpace {
101
101
} ;
102
102
103
103
public latestFee = ( ) : number | undefined => {
104
- for ( const api of this . apis ) {
105
- if ( api . latestFee !== undefined ) {
106
- return api . latestFee ;
107
- }
104
+ const fees = this . apis
105
+ . map ( ( c ) => c . latestFee )
106
+ . filter ( ( val ) : val is number => val !== undefined ) ;
107
+
108
+ if ( fees . length === 0 ) {
109
+ this . logger . warn ( `All ${ this . symbol } MempoolSpace endpoints failed` ) ;
110
+ return undefined ;
108
111
}
109
112
110
- this . logger . warn ( `All ${ this . symbol } MempoolSpace endpoints failed` ) ;
111
- return undefined ;
113
+ return Math . max ( ...fees ) ;
112
114
} ;
113
115
114
116
public stop = ( ) => {
Original file line number Diff line number Diff line change @@ -27,13 +27,13 @@ describe('MempoolSpace', () => {
27
27
expect ( mempool . latestFee ( ) ) . not . toBeUndefined ( ) ;
28
28
} ) ;
29
29
30
- test ( 'should pick results in order ' , async ( ) => {
30
+ test ( 'should pick highest returned fee ' , async ( ) => {
31
31
mempool . stop ( ) ;
32
32
33
33
const expectedFee = 42 ;
34
34
35
- mempool [ 'apis' ] [ 0 ] [ 'latestFee' ] = expectedFee ;
36
- mempool [ 'apis' ] [ 1 ] [ 'latestFee' ] = expectedFee - 12 ;
35
+ mempool [ 'apis' ] [ 0 ] [ 'latestFee' ] = expectedFee - 12 ;
36
+ mempool [ 'apis' ] [ 1 ] [ 'latestFee' ] = expectedFee ;
37
37
expect ( mempool . latestFee ( ) ) . toEqual ( expectedFee ) ;
38
38
39
39
mempool [ 'apis' ] [ 0 ] [ 'latestFee' ] = undefined ;
You can’t perform that action at this time.
0 commit comments