Skip to content

Commit

Permalink
feat: enhance AddressLink component with optional prefix prop and upd…
Browse files Browse the repository at this point in the history
…ate usage in StakingContractSection
  • Loading branch information
mohandast52 committed Dec 20, 2024
1 parent 8c4059b commit bdf8156
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
11 changes: 11 additions & 0 deletions frontend/components/AddressLink.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ReactNode } from 'react';

import { MiddlewareChain } from '@/client';
import { UNICODE_SYMBOLS } from '@/constants/symbols';
import { EXPLORER_URL_BY_MIDDLEWARE_CHAIN } from '@/constants/urls';
Expand All @@ -7,12 +9,14 @@ import { truncateAddress } from '@/utils/truncate';
type AddressLinkProps = {
address: Address;
middlewareChain: MiddlewareChain;
prefix?: ReactNode;
hideLinkArrow?: boolean;
};

export const AddressLink = ({
address,
hideLinkArrow = false,
prefix,
middlewareChain,
}: AddressLinkProps) => {
if (!address) return null;
Expand All @@ -25,6 +29,13 @@ export const AddressLink = ({
>
{truncateAddress(address)}

{prefix ? (
<>
&nbsp;
{prefix}
</>
) : null}

{hideLinkArrow ? null : (
<>
&nbsp;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Flex, Tag, theme, Typography } from 'antd';
import { useMemo } from 'react';

import { AddressLink } from '@/components/AddressLink';
import { CardSection } from '@/components/styled/CardSection';
import { GNOSIS_STAKING_PROGRAMS_CONTRACT_ADDRESSES } from '@/config/stakingPrograms/gnosis';
import { UNICODE_SYMBOLS } from '@/constants/symbols';
import { EXPLORER_URL_BY_EVM_CHAIN_ID } from '@/constants/urls';
import { STAKING_PROGRAM_ADDRESS } from '@/config/stakingPrograms';
import { StakingProgramId } from '@/enums/StakingProgram';
import { StakingProgramStatus } from '@/enums/StakingProgramStatus';
import { useServices } from '@/hooks/useServices';
Expand Down Expand Up @@ -115,15 +114,11 @@ export const StakingContractSection = ({
<StakingContractDetails stakingProgramId={stakingProgramId} />

{evmChainId && (
<a
href={`${EXPLORER_URL_BY_EVM_CHAIN_ID[evmChainId]}/address/${
// TODO: make chain independent
GNOSIS_STAKING_PROGRAMS_CONTRACT_ADDRESSES[stakingProgramId]
}`}
target="_blank"
>
View contract details {UNICODE_SYMBOLS.EXTERNAL_LINK}
</a>
<AddressLink
address={STAKING_PROGRAM_ADDRESS[evmChainId][stakingProgramId]}
middlewareChain={selectedAgentConfig.middlewareHomeChainId}
prefix="View contract details"
/>
)}

{!migrateValidation.canMigrate && (
Expand Down
1 change: 0 additions & 1 deletion frontend/config/agents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export const AGENT_CONFIG: {
displayName: 'Prediction agent',
description: 'Participates in prediction markets.',
},
// TODO: check optimus config
// [AgentType.Optimus]: {
// name: 'Optimus',
// homeChainId: ChainId.Optimism,
Expand Down
8 changes: 0 additions & 8 deletions frontend/constants/urls.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { MiddlewareChain } from '@/client';
import { EvmChainId } from '@/enums/Chain';
import { asEvmChainId } from '@/utils/middlewareHelpers';

type Url = `http${'s' | ''}://${string}`;

Expand Down Expand Up @@ -65,10 +64,3 @@ export const SWAP_URL_BY_EVM_CHAIN: Record<number | EvmChainId, Url> = {
// [EvmChainId.OPTIMISM]: COW_SWAP_GNOSIS_XDAI_OLAS_URL,
[EvmChainId.Base]: SWAP_BASE_URL,
};

export const EXPLORER_URL_BY_EVM_CHAIN_ID: Record<number | EvmChainId, Url> =
Object.fromEntries(
Object.entries(EXPLORER_URL_BY_MIDDLEWARE_CHAIN).map(
([middlewareChain, url]) => [asEvmChainId(middlewareChain), url],
),
);

0 comments on commit bdf8156

Please sign in to comment.