@lifi/widget
Version:
LI.FI Widget for cross-chain bridging and swapping. It will drive your multi-chain strategy and attract new users from everywhere.
34 lines • 1.46 kB
JavaScript
import { isItemAllowed } from '../../utils/item.js';
export const getMatchingLabels = (route, routeLabels) => {
if (!routeLabels?.length) {
return [];
}
return routeLabels
.filter((rule) => {
const conditions = [];
// Check bridge/exchange matches if specified
if (rule.bridges || rule.exchanges) {
const toolNames = route.steps.flatMap((step) => step.includedSteps.map((s) => s.tool));
conditions.push(toolNames.some((toolName) => isItemAllowed(toolName, rule.bridges) &&
isItemAllowed(toolName, rule.exchanges)));
}
// Check token matches if specified
if (rule.fromTokenAddress?.length) {
conditions.push(rule.fromTokenAddress.includes(route.fromToken.address));
}
if (rule.toTokenAddress?.length) {
conditions.push(rule.toTokenAddress.includes(route.toToken.address));
}
// Check chain matches if specified
if (rule.fromChainId?.length) {
conditions.push(rule.fromChainId.includes(route.fromChainId));
}
if (rule.toChainId?.length) {
conditions.push(rule.toChainId.includes(route.toChainId));
}
// Must have at least one condition and all conditions must be true
return conditions.length && conditions.every(Boolean);
})
.map((rule) => rule.label);
};
//# sourceMappingURL=getMatchingLabels.js.map