Skip to content

Commit

Permalink
Merge pull request #542 from valory-xyz/tanya/fixes
Browse files Browse the repository at this point in the history
chore: fix dummy service requests
  • Loading branch information
Tanya-atatakai authored Dec 5, 2024
2 parents 5ad0487 + 68d5690 commit b49a09b
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export const MainOlasBalance = ({
bordertop={isBorderTopVisible ? 'true' : 'false'}
borderbottom="true"
padding="16px 24px"
align="center"
>
{isBalanceLoaded ? (
<Flex vertical gap={8}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const useEpochEndTime = () => {
activeStakingProgramAddress!,
),
queryFn: async () => {
return await getLatestEpochDetails(activeStakingProgramAddress!);
return await getLatestEpochDetails(chainId, activeStakingProgramAddress!);
},
select: (data) => {
// last epoch end time + epoch length
Expand Down
3 changes: 3 additions & 0 deletions frontend/components/SettingsPage/DebugInfoSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Tooltip,
Typography,
} from 'antd';
import { isAddress } from 'ethers/lib/utils';
import { isEmpty, isNil } from 'lodash';
import { Fragment, useCallback, useMemo, useState } from 'react';
import styled from 'styled-components';
Expand Down Expand Up @@ -195,6 +196,8 @@ export const DebugInfoSection = () => {

if (!isNil(serviceAddresses)) {
serviceAddresses?.forEach((serviceWallet) => {
if (!isAddress(serviceWallet.address)) return;

if (serviceWallet.type === WalletType.EOA) {
result.push({
title: 'Agent Instance EOA',
Expand Down
2 changes: 2 additions & 0 deletions frontend/components/SetupPage/SetupYourAgent/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ServicesService } from '@/service/Services';
* Validate the Google Gemini API key
*/
export const validateGeminiApiKey = async (apiKey: string) => {
return true;
if (!apiKey) return false;

try {
Expand Down Expand Up @@ -38,6 +39,7 @@ export const validateTwitterCredentials = async (
password: string;
}) => Promise<{ success: boolean }>,
) => {
return true;
if (!email || !username || !password) return false;

try {
Expand Down
10 changes: 8 additions & 2 deletions frontend/constants/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ export const FAQ_URL: Url = 'https://olas.network/operate#faq';
export const DOWNLOAD_URL: Url = 'https://olas.network/operate#download';

// thegraph
export const GNOSIS_REWARDS_HISTORY_SUBGRAPH_URL: Url =
'https://api.studio.thegraph.com/query/81371/gnosis-pearl-rewards-history/version/latest';
export const REWARDS_HISTORY_SUBGRAPH_URLS_BY_EVM_CHAIN = {
[EvmChainId.Ethereum]: '',
[EvmChainId.Optimism]: '',
[EvmChainId.Gnosis]:
'https://api.studio.thegraph.com/query/81371/gnosis-pearl-rewards-history/version/latest',
[EvmChainId.Base]:
'https://api.studio.thegraph.com/query/67875/olas-base-staking-rewards-history/version/latest',
};

// discord
export const SUPPORT_URL: Url =
Expand Down
41 changes: 23 additions & 18 deletions frontend/context/BalanceProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,17 @@ const getCrossChainWalletBalances = async (
ERC20_BALANCE_OF_STRING_FRAGMENT,
);

const erc20Calls = relevantWallets.map((wallet) =>
const relevantWalletsFiltered = relevantWallets.filter((wallet) =>
isAddress(wallet.address),
);

const erc20Calls = relevantWalletsFiltered.map((wallet) =>
erc20Contract.balanceOf(wallet.address),
);

const erc20Balances = await multicallProvider.all(erc20Calls);

const erc20Results = relevantWallets.map(
const erc20Results = relevantWalletsFiltered.map(
({ address: walletAddress }, index) => ({
walletAddress,
evmChainId: providerEvmChainId,
Expand Down Expand Up @@ -340,27 +344,28 @@ const getCrossChainStakedBalances = async (
const registryInfos = await Promise.allSettled(registryInfoPromises);

registryInfos.forEach((res, idx) => {
if (res.status === 'fulfilled' && res.value) {
const { serviceId, chainId, depositValue, bondValue, serviceState } =
res.value;

result.push({
serviceId,
evmChainId: asEvmChainId(chainId),
...correctBondDepositByServiceState({
olasBondBalance: bondValue,
olasDepositBalance: depositValue,
serviceState,
}),
walletAddress:
services[idx].chain_configs[chainId].chain_data.multisig!, // multisig must exist if registry info is fetched
});
} else {
if (res.status !== 'fulfilled') {
console.error(
'Error fetching registry info for',
services[idx].service_config_id,
);
return;
}

const value = res.value;
if (!value) return;

const { serviceId, chainId, depositValue, bondValue, serviceState } = value;
result.push({
serviceId,
evmChainId: asEvmChainId(chainId),
...correctBondDepositByServiceState({
olasBondBalance: bondValue,
olasDepositBalance: depositValue,
serviceState,
}),
walletAddress: services[idx].chain_configs[chainId].chain_data.multisig!, // Multisig must exist if registry info is fetched
});
});

return result;
Expand Down
10 changes: 7 additions & 3 deletions frontend/graphql/queries.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { gql, request } from 'graphql-request';

import { GNOSIS_REWARDS_HISTORY_SUBGRAPH_URL } from '@/constants/urls';
import { REWARDS_HISTORY_SUBGRAPH_URLS_BY_EVM_CHAIN } from '@/constants/urls';
import { EvmChainId } from '@/enums/Chain';
import {
EpochDetailsResponse,
EpochDetailsResponseSchema,
Expand All @@ -23,11 +24,14 @@ export const getLatestEpochTimeQuery = (contractAddress: string) => gql`
}
`;

export const getLatestEpochDetails = async (contractAddress: string) => {
export const getLatestEpochDetails = async (
chainId: EvmChainId,
contractAddress: string,
) => {
const response = await request<{
checkpoints: EpochDetailsResponse[];
}>(
GNOSIS_REWARDS_HISTORY_SUBGRAPH_URL,
REWARDS_HISTORY_SUBGRAPH_URLS_BY_EVM_CHAIN[chainId],
getLatestEpochTimeQuery(contractAddress),
);

Expand Down
4 changes: 2 additions & 2 deletions frontend/hooks/useRewardsHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { z } from 'zod';

import { STAKING_PROGRAM_ADDRESS } from '@/config/stakingPrograms';
import { REACT_QUERY_KEYS } from '@/constants/react-query-keys';
import { GNOSIS_REWARDS_HISTORY_SUBGRAPH_URL } from '@/constants/urls';
import { REWARDS_HISTORY_SUBGRAPH_URLS_BY_EVM_CHAIN } from '@/constants/urls';
import { EvmChainId } from '@/enums/Chain';
import { Address } from '@/types/Address';
import { Nullable } from '@/types/Util';
Expand Down Expand Up @@ -174,7 +174,7 @@ const useContractCheckpoints = (
queryKey: REACT_QUERY_KEYS.REWARDS_HISTORY_KEY(chainId, serviceId!),
queryFn: async () => {
const checkpointsResponse = await request<CheckpointsResponse>(
GNOSIS_REWARDS_HISTORY_SUBGRAPH_URL,
REWARDS_HISTORY_SUBGRAPH_URLS_BY_EVM_CHAIN[chainId],
fetchRewardsQuery(chainId),
);

Expand Down
1 change: 1 addition & 0 deletions frontend/service/agents/StakedAgentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export abstract class StakedAgentService {
evmChainId: EvmChainId,
): Promise<Maybe<StakingProgramId>> => {
if (!serviceNftTokenId || !evmChainId) return;
if (serviceNftTokenId <= 0) return;
try {
const { multicallProvider } = PROVIDERS[evmChainId];

Expand Down

0 comments on commit b49a09b

Please sign in to comment.