@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
29 lines • 1.49 kB
JavaScript
import { useRightBalanceAsset } from "../hooks/useRightBalanceAsset";
import { useRightMarketTrendModule } from "../hooks/modules/useRightMarketTrendModule";
import { useLeftApyModule } from "../hooks/modules/useLeftApyModule";
import { useLeftMarketTrendModule } from "../hooks/modules/useLeftMarketTrendModule";
import { compareByBalanceThenFiat } from "../utils/sortByBalance";
export const sortAssets = (result, rightElement) => {
if (rightElement === "balance" || rightElement === undefined) {
return [...result].sort((a, b) => compareByBalanceThenFiat(a?.balanceData, b?.balanceData));
}
return result;
};
export function useAssetConfiguration(assets, options) {
const { rightElement = "balance", leftElement } = options;
const rightResults = {
balance: useRightBalanceAsset(rightElement === "balance" || rightElement === undefined ? assets : [], options),
marketTrend: useRightMarketTrendModule(rightElement === "marketTrend" ? assets : [], options),
};
const leftResults = {
apy: useLeftApyModule(leftElement === "apy" ? assets : [], options),
marketTrend: useLeftMarketTrendModule(leftElement === "marketTrend" ? assets : [], options),
};
const merged = assets.map((asset, i) => ({
...asset,
...rightResults[rightElement]?.[i],
...leftResults[leftElement ?? ""]?.[i],
}));
return sortAssets(merged, rightElement);
}
//# sourceMappingURL=createAssetConfiguration.js.map