1
1
import { div , eq , gt , round , toFixed } from 'biggystring'
2
2
import { asNumber , asObject } from 'cleaners'
3
+ import { PluginPromotion } from 'edge-info-server'
3
4
import { sprintf } from 'sprintf-js'
4
5
5
6
import { getFirstOpenInfo } from '../../actions/FirstOpenActions'
@@ -144,7 +145,7 @@ export const amountQuoteFiatPlugin: FiatPluginFactory = async (params: FiatPlugi
144
145
try {
145
146
if ( infoServerData . rollup ?. fiatPluginPriority != null ) {
146
147
providerPriority = infoServerData . rollup . fiatPluginPriority
147
- priorityArray = createPriorityArray ( providerPriority [ paymentTypes [ 0 ] ] )
148
+ priorityArray = createPriorityArray ( providerPriority [ paymentTypes [ 0 ] ] , pluginPromotions )
148
149
}
149
150
} catch ( e : any ) {
150
151
console . warn ( 'Failed to fetch provider priorities:' , e )
@@ -606,12 +607,37 @@ export const amountQuoteFiatPlugin: FiatPluginFactory = async (params: FiatPlugi
606
607
// showing the quotes.
607
608
// TODO: conflict: also defines whether or not to accept a quote from the
608
609
// provider
609
- export const createPriorityArray = ( providerPriorityMap ?: ProviderPriorityMap ) : PriorityArray => {
610
+ export const createPriorityArray = ( providerPriorityMap ?: ProviderPriorityMap , pluginPromotions : PluginPromotion [ ] = [ ] ) : PriorityArray => {
610
611
const priorityArray : PriorityArray = [ ]
611
612
if ( providerPriorityMap != null ) {
613
+ // Create a copy of the providerPriorityMap to avoid modifying the original
614
+ const priorityMapCopy = { ...providerPriorityMap }
615
+
616
+ // Create a separate object for preferred providers
617
+ const preferredProviders : { [ pluginId : string ] : boolean } = { }
618
+
619
+ // Identify all preferred providers from pluginPromotions
620
+ for ( const pluginPromotion of pluginPromotions ) {
621
+ if ( pluginPromotion . preferProviders != null ) {
622
+ for ( const provider of pluginPromotion . preferProviders ) {
623
+ // Add to preferred providers list
624
+ preferredProviders [ provider ] = true
625
+ // Remove from the regular priority map if it exists there, so they
626
+ // are omitted from normal ordering logic
627
+ delete priorityMapCopy [ provider ]
628
+ }
629
+ }
630
+ }
631
+
632
+ // If we have preferred providers, add them as the first priority group
633
+ if ( Object . keys ( preferredProviders ) . length > 0 ) {
634
+ priorityArray . push ( preferredProviders )
635
+ }
636
+
637
+ // Process the remaining providers by priority
612
638
const tempPriorityList : Array < { pluginId : string ; priority : number } > = [ ]
613
- for ( const pluginId in providerPriorityMap ) {
614
- tempPriorityList . push ( { pluginId, priority : providerPriorityMap [ pluginId ] } )
639
+ for ( const pluginId in priorityMapCopy ) {
640
+ tempPriorityList . push ( { pluginId, priority : priorityMapCopy [ pluginId ] } )
615
641
}
616
642
tempPriorityList . sort ( ( a , b ) => b . priority - a . priority )
617
643
let currentPriority = Infinity
@@ -625,6 +651,7 @@ export const createPriorityArray = (providerPriorityMap?: ProviderPriorityMap):
625
651
priorityObj [ tempPriority . pluginId ] = true
626
652
}
627
653
}
654
+
628
655
return priorityArray
629
656
}
630
657
0 commit comments