Skip to content

Commit

Permalink
Merge pull request #592 from valory-xyz/tanya/fixes
Browse files Browse the repository at this point in the history
fix: show needs funds alert, fix debug info
  • Loading branch information
Tanya-atatakai authored Dec 15, 2024
2 parents 899c9ec + a6b3151 commit 005cd99
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const EmptyFunds = () => {
<InlineBanner text="Your safe address" address={masterEoaAddress} />
)}
<PurpleDivider />
<FundsToActivate stakingFundsRequired tradingFundsRequired />
<FundsToActivate stakingFundsRequired otherFundsRequired />
</Flex>
}
type="primary"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useMemo } from 'react';

import { getNativeTokenSymbol } from '@/config/tokens';
import { UNICODE_SYMBOLS } from '@/constants/symbols';
import { AgentType } from '@/enums/Agent';
import { TokenSymbol } from '@/enums/Token';
import { useNeedsFunds } from '@/hooks/useNeedsFunds';
import { useServices } from '@/hooks/useServices';
Expand All @@ -15,18 +16,23 @@ const { Text } = Typography;

type FundsToActivateProps = {
stakingFundsRequired: boolean;
tradingFundsRequired: boolean;
otherFundsRequired: boolean;
};

const FUNDS_REQUIRED_FOR_BY_AGENT_TYPE = {
[AgentType.PredictTrader]: 'for trading',
[AgentType.Memeooorr]: 'for agent operations',
};

export const FundsToActivate = ({
stakingFundsRequired = true,
tradingFundsRequired = true,
otherFundsRequired = true,
}: FundsToActivateProps) => {
const { selectedStakingProgramId } = useStakingProgram();

const { serviceFundRequirements } = useNeedsFunds(selectedStakingProgramId);

const { selectedAgentConfig } = useServices();
const { selectedAgentConfig, selectedAgentType } = useServices();
const { evmHomeChainId: homeChainId } = selectedAgentConfig;
const nativeTokenSymbol = getNativeTokenSymbol(homeChainId);
const { chainName, masterSafeAddress } = useLowFundsDetails();
Expand Down Expand Up @@ -57,10 +63,10 @@ export const FundsToActivate = ({
staking.
</div>
)}
{tradingFundsRequired && (
{otherFundsRequired && (
<div>
{UNICODE_SYMBOLS.BULLET} <Text strong>{nativeTokenRequired}</Text> -
for trading.
{` ${FUNDS_REQUIRED_FOR_BY_AGENT_TYPE[selectedAgentType]}.`}
</div>
)}
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const MainNeedsFunds = () => {

<FundsToActivate
stakingFundsRequired={!hasEnoughOlasForInitialFunding}
tradingFundsRequired={!hasEnoughEthForInitialFunding}
otherFundsRequired={!hasEnoughEthForInitialFunding}
/>
</Flex>
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CardSection } from '@/components/styled/CardSection';
import { useFeatureFlag } from '@/hooks/useFeatureFlag';

import { AddBackupWalletAlert } from './AddBackupWalletAlert';
import { AvoidSuspensionAlert } from './AvoidSuspensionAlert';
Expand All @@ -9,15 +8,13 @@ import { NoAvailableSlotsOnTheContract } from './NoAvailableSlotsOnTheContract';
import { UpdateAvailableAlert } from './UpdateAvailableAlert';

export const AlertSections = () => {
const isLowFundsEnabled = useFeatureFlag('low-funds');

return (
<CardSection vertical>
<UpdateAvailableAlert />
<AddBackupWalletAlert />
<NewStakingProgramAlert />
<AvoidSuspensionAlert />
{isLowFundsEnabled && <LowFunds />}
<LowFunds />
<NoAvailableSlotsOnTheContract />
</CardSection>
);
Expand Down
20 changes: 12 additions & 8 deletions frontend/components/SettingsPage/DebugInfoSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ const DebugItem = ({

export const DebugInfoSection = () => {
const { masterEoa, masterSafes } = useMasterWalletContext();
const { serviceWallets: serviceAddresses } = useServices();
const { serviceWallets: serviceAddresses, selectedAgentConfig } =
useServices();
const { walletBalances } = useBalanceContext();
const { masterEoaBalances, masterSafeBalances } = useMasterBalances();

Expand Down Expand Up @@ -184,13 +185,15 @@ export const DebugInfoSection = () => {
});
}

if (!isNil(masterSafeBalances)) {
masterSafes.forEach((wallet) => {
result.push({
title: 'Master Safe',
...getBalanceData(masterSafeBalances),
address: wallet.address,
});
const masterSafe = masterSafes.find(
(item) => item.evmChainId === selectedAgentConfig.evmHomeChainId,
);

if (!isNil(masterSafeBalances) && !isNil(masterSafe)) {
result.push({
title: 'Master Safe',
...getBalanceData(masterSafeBalances),
address: masterSafe.address,
});
}

Expand Down Expand Up @@ -232,6 +235,7 @@ export const DebugInfoSection = () => {
masterEoaBalances,
masterSafeBalances,
masterSafes,
selectedAgentConfig.evmHomeChainId,
serviceAddresses,
walletBalances,
]);
Expand Down
4 changes: 2 additions & 2 deletions frontend/context/RewardProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const useStakingRewardsDetails = () => {
token!,
),
queryFn: async () => {
if (!multisig || !token || !selectedStakingProgramId) return;
if (!multisig || !token || !selectedStakingProgramId) return null;
const response =
await selectedAgentConfig.serviceApi.getAgentStakingRewardsInfo({
agentMultisigAddress: multisig,
Expand All @@ -71,7 +71,7 @@ const useStakingRewardsDetails = () => {
chainId: currentChainId,
});

if (!response) return;
if (!response) return null;

try {
const parsed = StakingRewardsInfoSchema.parse(response);
Expand Down

0 comments on commit 005cd99

Please sign in to comment.