{!hasEnoughOlasForInitialFunding && (
- {`${UNICODE_SYMBOLS.OLAS}${serviceFundRequirements.olas} OLAS `}
+ {`${UNICODE_SYMBOLS.OLAS}${serviceFundRequirements[homeChainId].olas} OLAS `}
for staking
)}
{!hasEnoughEthForInitialFunding && (
- {`$${serviceFundRequirements.eth} XDAI `}
+ {`$${serviceFundRequirements[homeChainId].eth} XDAI `}
for trading
@@ -56,9 +60,10 @@ export const MainNeedsFunds = () => {
),
[
+ hasEnoughOlasForInitialFunding,
serviceFundRequirements,
+ homeChainId,
hasEnoughEthForInitialFunding,
- hasEnoughOlasForInitialFunding,
],
);
diff --git a/frontend/components/MainPage/sections/OlasBalanceSection.tsx b/frontend/components/MainPage/sections/OlasBalanceSection.tsx
index 1132bd5a..5a7ca8ae 100644
--- a/frontend/components/MainPage/sections/OlasBalanceSection.tsx
+++ b/frontend/components/MainPage/sections/OlasBalanceSection.tsx
@@ -4,8 +4,14 @@ import { useMemo } from 'react';
import styled from 'styled-components';
import { UNICODE_SYMBOLS } from '@/constants/symbols';
+import { TokenSymbol } from '@/enums/Token';
// import { Pages } from '@/enums/PageState';
-import { useBalanceContext } from '@/hooks/useBalanceContext';
+import {
+ useBalanceContext,
+ useMasterBalances,
+ useServiceBalances,
+} from '@/hooks/useBalanceContext';
+import { useServices } from '@/hooks/useServices';
// import { usePageState } from '@/hooks/usePageState';
import { balanceFormat } from '@/utils/numberFormatters';
@@ -22,13 +28,52 @@ type MainOlasBalanceProps = { isBorderTopVisible?: boolean };
export const MainOlasBalance = ({
isBorderTopVisible = true,
}: MainOlasBalanceProps) => {
- const { isLoaded: isBalanceLoaded, totalOlasBalance } = useBalanceContext();
+ const { selectedService } = useServices();
+ const { isLoaded: isBalanceLoaded } = useBalanceContext();
+ const { masterWalletBalances } = useMasterBalances();
+ const { serviceStakedBalances, serviceWalletBalances } = useServiceBalances(
+ selectedService?.service_config_id,
+ );
// const { goto } = usePageState();
- const balance = useMemo(() => {
- if (totalOlasBalance === undefined) return '--';
+ const displayedBalance = useMemo(() => {
+ // olas across master wallets, safes and eoa
+ const masterWalletOlasBalance = masterWalletBalances?.reduce(
+ (acc, { symbol, balance }) => {
+ if (symbol === TokenSymbol.OLAS) {
+ return acc + Number(balance);
+ }
+ return acc;
+ },
+ 0,
+ );
+
+ // olas across all service wallets
+ const serviceWalletOlasBalance = serviceWalletBalances?.reduce(
+ (acc, { symbol, balance }) => {
+ if (symbol === TokenSymbol.OLAS) {
+ return acc + Number(balance);
+ }
+ return acc;
+ },
+ 0,
+ );
+
+ // olas staked across all services
+ const serviceStakedOlasBalance = serviceStakedBalances?.reduce(
+ (acc, { olasBondBalance, olasDepositBalance }) => {
+ return acc + Number(olasBondBalance) + Number(olasDepositBalance);
+ },
+ 0,
+ );
+
+ const totalOlasBalance =
+ masterWalletOlasBalance +
+ serviceWalletOlasBalance +
+ serviceStakedOlasBalance;
+
return balanceFormat(totalOlasBalance, 2);
- }, [totalOlasBalance]);
+ }, [masterWalletBalances, serviceStakedBalances, serviceWalletBalances]);
return (