Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: show needs funds alert, fix debug info #592

Merged
merged 2 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]}`}
Tanya-atatakai marked this conversation as resolved.
Show resolved Hide resolved
</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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doubt: oh, why just return wasn't working? 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tanstack complains when returning undefined :( there are a lot of errors in console


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