diff --git a/apps/autonolas-registry/common-util/Details/DetailsSubInfo/utils.ts b/apps/autonolas-registry/common-util/Details/DetailsSubInfo/utils.ts index a98e19d4..1071a62b 100644 --- a/apps/autonolas-registry/common-util/Details/DetailsSubInfo/utils.ts +++ b/apps/autonolas-registry/common-util/Details/DetailsSubInfo/utils.ts @@ -1,4 +1,6 @@ -import { NAV_TYPES, TOKENOMICS_UNIT_TYPES } from '../../../util/constants'; +import { TOKENOMICS_UNIT_TYPES } from 'libs/util-constants/src'; + +import { NAV_TYPES } from '../../../util/constants'; export const getTokenomicsUnitType = (type?: string) => { if (type === NAV_TYPES.COMPONENT) return TOKENOMICS_UNIT_TYPES.COMPONENT; diff --git a/apps/autonolas-registry/components/ListAgents/utils.jsx b/apps/autonolas-registry/components/ListAgents/utils.jsx index 901397c9..5e22045d 100644 --- a/apps/autonolas-registry/components/ListAgents/utils.jsx +++ b/apps/autonolas-registry/components/ListAgents/utils.jsx @@ -1,6 +1,8 @@ -import { getMechMinterContract, getAgentContract } from '../../common-util/Contracts'; -import { getFirstAndLastIndex } from '../../common-util/List/functions'; +import { TOKENOMICS_UNIT_TYPES } from 'libs/util-constants/src'; + import { getListByAccount } from '../../common-util/ContractUtils/myList'; +import { getAgentContract, getMechMinterContract } from '../../common-util/Contracts'; +import { getFirstAndLastIndex } from '../../common-util/List/functions'; import { sendTransaction } from '../../common-util/functions'; // --------- HELPER METHODS --------- @@ -71,8 +73,7 @@ export const getAgentHashes = async (id) => { export const updateAgentHashes = async (account, id, newHash) => { const contract = getMechMinterContract(); - // 0 to indicate `agents` - const fn = contract.methods.updateHash('0', id, `0x${newHash}`).send({ + const fn = contract.methods.updateHash(TOKENOMICS_UNIT_TYPES.AGENT, id, `0x${newHash}`).send({ from: account, }); await sendTransaction(fn, account); diff --git a/apps/autonolas-registry/components/ListComponents/utils.jsx b/apps/autonolas-registry/components/ListComponents/utils.jsx index a3fa85ee..b9aa72fe 100644 --- a/apps/autonolas-registry/components/ListComponents/utils.jsx +++ b/apps/autonolas-registry/components/ListComponents/utils.jsx @@ -1,3 +1,4 @@ +import { TOKENOMICS_UNIT_TYPES } from 'libs/util-constants/src'; import { GATEWAY_URL, HASH_PREFIX } from 'libs/util-constants/src/lib/ipfs'; import { getListByAccount } from 'common-util/ContractUtils/myList'; @@ -73,8 +74,7 @@ export const getComponentHashes = async (id) => { export const updateComponentHashes = async (account, id, newHash) => { const contract = getMechMinterContract(); - // 0 to indicate `components` - const fn = contract.methods.updateHash('0', id, `0x${newHash}`).send({ + const fn = contract.methods.updateHash(TOKENOMICS_UNIT_TYPES.COMPONENT, id, `0x${newHash}`).send({ from: account, }); await sendTransaction(fn, account); diff --git a/apps/autonolas-registry/tests/components/ListAgents/details.test.jsx b/apps/autonolas-registry/tests/components/ListAgents/details.test.jsx index 9c3bed0d..b0c1f873 100644 --- a/apps/autonolas-registry/tests/components/ListAgents/details.test.jsx +++ b/apps/autonolas-registry/tests/components/ListAgents/details.test.jsx @@ -55,6 +55,10 @@ jest.mock('common-util/Details/utils', () => ({ checkIfServiceRequiresWhitelisting: jest.fn(() => false), })); +jest.mock('common-util/Details/DetailsSubInfo/utils', () => ({ + getTokenomicsUnitType: jest.fn(() => 1), +})); + jest.mock('common-util/hooks/useHelpers', () => ({ useHelpers: () => useHelpersEvmMock, })); @@ -68,6 +72,7 @@ jest.mock('components/ListAgents/utils', () => ({ getAgentHashes: jest.fn(), getAgentOwner: jest.fn(), getTokenUri: jest.fn(), + updateAgentHashes: jest.fn(), })); const dummyDetails = { diff --git a/apps/autonolas-registry/tests/components/ListAgents/utils.test.jsx b/apps/autonolas-registry/tests/components/ListAgents/utils.test.jsx index 9dcbd23f..1ca2c485 100644 --- a/apps/autonolas-registry/tests/components/ListAgents/utils.test.jsx +++ b/apps/autonolas-registry/tests/components/ListAgents/utils.test.jsx @@ -8,6 +8,11 @@ jest.mock('../../../common-util/Contracts', () => ({ getAgentContract: jest.fn(), })); +// TODO: mock updateAgentHashes instead +jest.mock('libs/util-constants/src', () => ({ + TOKENOMICS_UNIT_TYPES: { COMPONENT: '0', AGENT: '1' }, +})); + describe('listAgents/utils.jsx', () => { it('getFilteredAgents: Promise resolved', async () => { getAgentContract.mockImplementation(() => ({ diff --git a/apps/autonolas-registry/tests/components/ListComponents/details.test.jsx b/apps/autonolas-registry/tests/components/ListComponents/details.test.jsx index 3c719411..98c88143 100644 --- a/apps/autonolas-registry/tests/components/ListComponents/details.test.jsx +++ b/apps/autonolas-registry/tests/components/ListComponents/details.test.jsx @@ -71,6 +71,10 @@ jest.mock('components/ListComponents/utils', () => ({ getTokenUri: jest.fn(), })); +jest.mock('common-util/Details/DetailsSubInfo/utils', () => ({ + getTokenomicsUnitType: jest.fn(() => 1), +})); + const dummyDetails = { owner: dummyAddress, developer: dummyAddress, diff --git a/apps/autonolas-registry/tests/components/ListComponents/utils.test.jsx b/apps/autonolas-registry/tests/components/ListComponents/utils.test.jsx index fe135410..047327de 100644 --- a/apps/autonolas-registry/tests/components/ListComponents/utils.test.jsx +++ b/apps/autonolas-registry/tests/components/ListComponents/utils.test.jsx @@ -12,6 +12,11 @@ jest.mock('../../../common-util/Contracts', () => ({ getComponentContract: jest.fn(), })); +// TODO: mock updateComponentHashes instead +jest.mock('libs/util-constants/src', () => ({ + TOKENOMICS_UNIT_TYPES: { COMPONENT: '0', AGENT: '1' }, +})); + describe('listComponents/utils.jsx', () => { it('getComponentDetails: Promise resolved', async () => { getComponentContract.mockImplementation(() => ({ diff --git a/apps/autonolas-registry/tests/components/ListServices/details.test.jsx b/apps/autonolas-registry/tests/components/ListServices/details.test.jsx index 11ba9a3a..9f96808f 100644 --- a/apps/autonolas-registry/tests/components/ListServices/details.test.jsx +++ b/apps/autonolas-registry/tests/components/ListServices/details.test.jsx @@ -74,6 +74,11 @@ jest.mock('common-util/Details/utils', () => ({ checkIfServiceRequiresWhitelisting: jest.fn(), })); +jest.mock('common-util/Details/DetailsSubInfo/utils', () => ({ + getTokenomicsUnitType: jest.fn(() => 1), +})); + + jest.mock('common-util/hooks/useSvmConnectivity', () => ({ useSvmConnectivity: jest.fn(), })); diff --git a/apps/autonolas-registry/util/constants.ts b/apps/autonolas-registry/util/constants.ts index a2130cd7..5fd1219b 100644 --- a/apps/autonolas-registry/util/constants.ts +++ b/apps/autonolas-registry/util/constants.ts @@ -100,11 +100,3 @@ export const HASH_DETAILS_STATE = { LOADED: 'LOADED', FAILED: 'FAILED', } as const; - -/** - * Constants for Tokenomics unitTypes - */ -export const TOKENOMICS_UNIT_TYPES = { - COMPONENT: 0, - AGENT: 1, -} as const; diff --git a/apps/bond/common-util/enums/index.js b/apps/bond/common-util/enums/index.js index 11bd736f..000437ab 100644 --- a/apps/bond/common-util/enums/index.js +++ b/apps/bond/common-util/enums/index.js @@ -2,11 +2,6 @@ export const FORM_TYPES = { CLAIMABLE_INCENTIVES: 'CLAIMABLE_INCENTIVES', }; -export const UNIT_TYPES = { - COMPONENT: '0', - AGENT: '1', -}; - export const BONDING_PRODUCTS = { ACTIVE: 'active', INACTIVE: 'inactive', diff --git a/apps/tokenomics/common-util/enums/index.js b/apps/tokenomics/common-util/enums/index.js index 11bd736f..000437ab 100644 --- a/apps/tokenomics/common-util/enums/index.js +++ b/apps/tokenomics/common-util/enums/index.js @@ -2,11 +2,6 @@ export const FORM_TYPES = { CLAIMABLE_INCENTIVES: 'CLAIMABLE_INCENTIVES', }; -export const UNIT_TYPES = { - COMPONENT: '0', - AGENT: '1', -}; - export const BONDING_PRODUCTS = { ACTIVE: 'active', INACTIVE: 'inactive', diff --git a/apps/tokenomics/components/DevIncentives/IncentivesForThisEpoch.jsx b/apps/tokenomics/components/DevIncentives/IncentivesForThisEpoch.jsx index f83f4029..8cdba2a6 100644 --- a/apps/tokenomics/components/DevIncentives/IncentivesForThisEpoch.jsx +++ b/apps/tokenomics/components/DevIncentives/IncentivesForThisEpoch.jsx @@ -1,15 +1,18 @@ -import { useState } from 'react'; -import { Row, Col, Table, Typography, Alert } from 'antd'; +import { Alert, Col, Row, Table, Typography } from 'antd'; import { round, toLower } from 'lodash'; +import { useState } from 'react'; + import { notifyError } from '@autonolas/frontend-library'; -import { FORM_TYPES, UNIT_TYPES } from 'common-util/enums'; -import { DynamicFieldsForm } from 'common-util/DynamicFieldsForm'; +import { TOKENOMICS_UNIT_TYPES } from 'libs/util-constants/src'; +import { DynamicFieldsForm } from 'common-util/DynamicFieldsForm'; +import { FORM_TYPES } from 'common-util/enums'; import { notifySpecificError } from 'common-util/functions/errors'; -import { sortUnitIdsAndTypes } from 'common-util/functions/units'; import { parseToEth } from 'common-util/functions/ethers'; +import { sortUnitIdsAndTypes } from 'common-util/functions/units'; import { useHelpers } from 'common-util/hooks/useHelpers'; + import { getOwnerIncentivesRequest, getOwnersForUnits } from './requests'; import { RewardAndTopUpContainer } from './styles'; @@ -29,11 +32,9 @@ const columns = [ ]; const checkIfHasDuplicate = (unitIds, unitTypes) => { - const agentIds = unitIds.filter( - (e, index) => unitTypes[index] === UNIT_TYPES.AGENT, - ); + const agentIds = unitIds.filter((e, index) => unitTypes[index] === TOKENOMICS_UNIT_TYPES.AGENT); const componentIds = unitIds.filter( - (e, index) => unitTypes[index] === UNIT_TYPES.COMPONENT, + (e, index) => unitTypes[index] === TOKENOMICS_UNIT_TYPES.COMPONENT, ); const uniqueAgentIds = [...new Set(agentIds)]; @@ -88,20 +89,14 @@ export const IncentivesForThisEpoch = () => { const ids = indexesWithDifferentOwner .map((e) => { const type = - unitTypes[e] === UNIT_TYPES.AGENT ? 'Agent ID' : 'Component ID'; + unitTypes[e] === TOKENOMICS_UNIT_TYPES.AGENT ? 'Agent ID' : 'Component ID'; return `${type} ${unitIds[e]}`; }) .join(', '); - notifyError( - 'Provided address is not the owner of the following units: ', - ids, - ); + notifyError('Provided address is not the owner of the following units: ', ids); } else { - const [sortedUnitIds, sortedUnitTypes] = sortUnitIdsAndTypes( - unitIds, - unitTypes, - ); + const [sortedUnitIds, sortedUnitTypes] = sortUnitIdsAndTypes(unitIds, unitTypes); try { const params = { @@ -163,12 +158,7 @@ export const IncentivesForThisEpoch = () => {