@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.
36 lines • 1.18 kB
JavaScript
// Use for a single item check
export const isItemAllowed = (item, items) => {
if (items?.allow?.length) {
return items.allow.includes(item);
}
return !items?.deny?.includes(item);
};
// Use for a O(1) set lookup of multiple items check
export const isItemAllowedForSets = (item, items, getKey) => {
if (items?.allow?.size) {
return items.allow.has(getKey?.(item) ?? item);
}
return !items?.deny?.has(getKey?.(item) ?? item);
};
export const getConfigItemSets = (items, getSet, formType) => {
if (!items) {
return undefined;
}
return {
allow: getSet(items.allow ?? []),
deny: getSet(items.deny ?? []),
...(formType && {
[formType]: {
allow: getSet(items[formType]?.allow ?? []),
deny: getSet(items[formType]?.deny ?? []),
},
}),
};
};
export const isFormItemAllowed = (item, configTokens, formType, getKey) => {
return (isItemAllowedForSets(item, configTokens, getKey) &&
(formType
? isItemAllowedForSets(item, configTokens?.[formType], getKey)
: true));
};
//# sourceMappingURL=item.js.map