Skip to content

Commit

Permalink
Merge branch 'fix/meme-staging' into tanya/fix-flickering
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanya-atatakai authored Dec 18, 2024
2 parents be430cd + cad9237 commit 47a56bf
Show file tree
Hide file tree
Showing 14 changed files with 226 additions and 147 deletions.
7 changes: 2 additions & 5 deletions frontend/components/AddressLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ import { truncateAddress } from '@/utils/truncate';
type AddressLinkProps = {
address?: Address;
hideLinkArrow?: boolean;

// TODO: mark as required once balance breakdown is updated.
// and remove the default value
middlewareChain?: MiddlewareChain;
middlewareChain: MiddlewareChain;
};

export const AddressLink = ({
address,
hideLinkArrow = false,
middlewareChain = MiddlewareChain.GNOSIS,
middlewareChain,
}: AddressLinkProps) => {
if (!address) return null;
if (!middlewareChain) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,27 @@ export const AgentNotRunningButton = () => {
selectedService?.service_config_id,
);

const {
setIsPaused: setIsBalancePollingPaused,
totalStakedOlasBalance,
updateBalances,
} = useBalanceContext();
const { setIsPaused: setIsBalancePollingPaused, updateBalances } =
useBalanceContext();

const { serviceStakedBalances, serviceSafeBalances } = useServiceBalances(
selectedService?.service_config_id,
);

const serviceStakedOlasBalanceOnHomeChain = serviceStakedBalances?.find(
const serviceStakedOlasBalancesOnHomeChain = serviceStakedBalances?.find(
(stakedBalance) =>
stakedBalance.evmChainId === selectedAgentConfig.evmHomeChainId,
);

const serviceTotalStakedOlas = sum([
serviceStakedOlasBalanceOnHomeChain?.olasBondBalance,
serviceStakedOlasBalanceOnHomeChain?.olasDepositBalance,
serviceStakedOlasBalancesOnHomeChain?.olasBondBalance,
serviceStakedOlasBalancesOnHomeChain?.olasDepositBalance,
]);

const serviceOlasBalanceOnHomeChain = serviceSafeBalances?.find(
(balance) => balance.evmChainId === selectedAgentConfig.evmHomeChainId,
)?.balance;

const { masterSafeBalances, masterSafeNativeGasBalance } =
useMasterBalances();

Expand All @@ -103,7 +104,10 @@ export const AgentNotRunningButton = () => {
selectedStakingProgramId
]?.stakingRequirements[TokenSymbol.OLAS];

const serviceSafeOlasWithStaked = sum([totalStakedOlasBalance]);
const serviceSafeOlasWithStaked = sum([
serviceOlasBalanceOnHomeChain,
serviceTotalStakedOlas,
]);

const isDeployable = useMemo(() => {
if (isServicesLoading) return false;
Expand Down Expand Up @@ -143,25 +147,27 @@ export const AgentNotRunningButton = () => {
selectedAgentConfig.operatingThresholds[WalletOwnerType.Master];
const tokenSymbol =
CHAIN_CONFIG[selectedAgentConfig.evmHomeChainId].nativeToken.symbol;
const agentSafeNativeBalance = serviceSafeBalances?.find(
({ symbol }) => symbol === tokenSymbol,
)?.balance;

const safeThreshold = masterThresholds[WalletType.Safe][tokenSymbol];

// SERVICE IS STAKED, AND STARTING AGAIN
if (isServiceStaked) {
const hasEnoughOlas =
(serviceSafeOlasWithStaked ?? 0) >= requiredStakedOlas;
const hasEnoughOlas = serviceSafeOlasWithStaked >= requiredStakedOlas;

// @note: Funds are transferred to the agent safe from the master safe.
// Hence, if the agent safe has enough funds, it is considered as enough.
const hasEnoughNativeGas =
(masterSafeNativeGasBalance ?? 0) > safeThreshold ||
(agentSafeNativeBalance ?? 0) > safeThreshold;
return hasEnoughOlas && hasEnoughNativeGas;
(masterSafeNativeGasBalance ?? 0) > safeThreshold;
return hasEnoughNativeGas && hasEnoughOlas;
}

// SERVICE IS NOT STAKED AND/OR IS STARTING FOR THE FIRST TIME
const totalOlasStakedAndInSafes = sum([
serviceOlasBalanceOnHomeChain,
serviceTotalStakedOlas,
masterSafeOlasBalance,
]);

const hasEnoughForInitialDeployment =
(masterSafeOlasBalance ?? 0) >= requiredStakedOlas &&
(totalOlasStakedAndInSafes ?? 0) >= requiredStakedOlas &&
(masterSafeNativeGasBalance ?? 0) >= safeThreshold;

return hasEnoughForInitialDeployment;
Expand All @@ -176,14 +182,14 @@ export const AgentNotRunningButton = () => {
service,
storeState,
selectedAgentType,
isEligibleForStaking,
isAgentEvicted,
masterSafeNativeGasBalance,
isEligibleForStaking,
selectedAgentConfig.operatingThresholds,
selectedAgentConfig.evmHomeChainId,
serviceOlasBalanceOnHomeChain,
serviceTotalStakedOlas,
masterSafeNativeGasBalance,
serviceSafeOlasWithStaked,
serviceSafeBalances,
]);

const pauseAllPolling = useCallback(() => {
Expand Down Expand Up @@ -245,7 +251,7 @@ export const AgentNotRunningButton = () => {
// Update the service if the hash is different
if (!middlewareServiceResponse && service) {
if (service.hash !== serviceTemplate.hash) {
return ServicesService.updateService({
await ServicesService.updateService({
serviceConfigId: service.service_config_id,
stakingProgramId: selectedStakingProgramId,
// chainId: selectedAgentConfig.evmHomeChainId,
Expand Down
4 changes: 0 additions & 4 deletions frontend/components/SettingsPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { CustomAlert } from '../Alert';
import { CardTitle } from '../Card/CardTitle';
import { CardSection } from '../styled/CardSection';
import { AddBackupWalletPage } from './AddBackupWalletPage';
import { DebugInfoSection } from './DebugInfoSection';

const { Text, Paragraph } = Typography;

Expand Down Expand Up @@ -161,9 +160,6 @@ const SettingsMain = () => {
<Text strong>Backup wallet</Text>
{walletBackup}
</CardSection>

{/* Debug info */}
<DebugInfoSection />
</Card>
);
};
15 changes: 12 additions & 3 deletions frontend/components/YourWalletPage/Titles.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Flex, Typography } from 'antd';

import { MiddlewareChain } from '@/client';
import { InfoTooltip } from '@/components/InfoTooltip';
import { TokenSymbol } from '@/enums/Token';
import { Address } from '@/types/Address';
Expand All @@ -8,11 +9,16 @@ import { AddressLink } from '../AddressLink';

const { Paragraph, Text, Title } = Typography;

type SignerTitleProps = { signerText: string; signerAddress?: Address };
type SignerTitleProps = {
signerText: string;
signerAddress: Address;
middlewareChain: MiddlewareChain;
};

export const SignerTitle = ({
signerText,
signerAddress,
middlewareChain,
}: SignerTitleProps) => (
<>
Signer&nbsp;
Expand All @@ -28,7 +34,10 @@ export const SignerTitle = ({
<Paragraph className="text-sm m-0">
<Flex gap={4} vertical>
<Text className="text-sm">{signerText}</Text>
<AddressLink address={signerAddress} />
<AddressLink
address={signerAddress}
middlewareChain={middlewareChain}
/>
</Flex>
</Paragraph>
</InfoTooltip>
Expand Down Expand Up @@ -58,7 +67,7 @@ export const NativeTokenTitle = ({ symbol }: { symbol: TokenSymbol }) => (
</Title>
&nbsp;
<InfoTooltip>
{/* TODO: address multi-agent tooltip, specfic to agent config */}
{/* TODO: address multi-agent tooltip, specific to agent config */}
<Paragraph className="text-sm m-0">
{symbol} is used by the agent to engage in prediction markets. This
amount will fluctuate based on your agent&apos;s performance.
Expand Down
7 changes: 6 additions & 1 deletion frontend/components/YourWalletPage/WithdrawFunds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React, { useCallback, useMemo, useState } from 'react';

import { COLOR } from '@/constants/colors';
import { useBalanceContext } from '@/hooks/useBalanceContext';
import { useFeatureFlag } from '@/hooks/useFeatureFlag';
import { useService } from '@/hooks/useService';
import { useServices } from '@/hooks/useServices';
import { useStakingContractCountdown } from '@/hooks/useStakingContractCountdown';
Expand All @@ -14,6 +15,7 @@ import { ServicesService } from '@/service/Services';
import { Address } from '@/types/Address';

import { CustomAlert } from '../Alert';
import { FeatureNotEnabled } from '../FeatureNotEnabled';

const { Text } = Typography;

Expand Down Expand Up @@ -54,7 +56,6 @@ const CompatibleMessage = () => (
export const WithdrawFunds = () => {
const { selectedService, refetch: refetchServices } = useServices();
const { refetch: refetchMasterWallets } = useMasterWalletContext();

const { updateBalances } = useBalanceContext();

const { service, isServiceRunning } = useService(
Expand All @@ -64,6 +65,7 @@ export const WithdrawFunds = () => {
const { isServiceStakedForMinimumDuration, selectedStakingContractDetails } =
useActiveStakingContractDetails();

// state
const [isModalVisible, setIsModalVisible] = useState(false);
const [withdrawAddress, setWithdrawAddress] = useState('');
const [isWithdrawalLoading, setIsWithdrawalLoading] = useState(false);
Expand Down Expand Up @@ -148,6 +150,9 @@ export const WithdrawFunds = () => {
[service, isServiceStakedForMinimumDuration, showModal],
);

const isWithdrawFundsEnabled = useFeatureFlag('withdraw-funds');
if (!isWithdrawFundsEnabled) return <FeatureNotEnabled />;

return (
<>
{isServiceStakedForMinimumDuration ? (
Expand Down
Loading

0 comments on commit 47a56bf

Please sign in to comment.