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

Celo: Cross-link to epoch block on the regular block view and Epoch rewards CSV export #2386

Merged
merged 4 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 24 additions & 0 deletions configs/app/features/celo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { Feature } from './types';

import { getEnvValue } from '../utils';

const title = 'Celo chain';

const config: Feature<{ L2UpgradeBlock: number | undefined; BLOCKS_PER_EPOCH: number }> = (() => {

if (getEnvValue('NEXT_PUBLIC_CELO_ENABLED') === 'true') {
return Object.freeze({
title,
isEnabled: true,
L2UpgradeBlock: getEnvValue('NEXT_PUBLIC_CELO_L2_UPGRADE_BLOCK') ? Number(getEnvValue('NEXT_PUBLIC_CELO_L2_UPGRADE_BLOCK')) : undefined,
BLOCKS_PER_EPOCH: 17_280,
});
}

return Object.freeze({
title,
isEnabled: false,
});
})();

export default config;
1 change: 1 addition & 0 deletions configs/app/features/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export { default as adsText } from './adsText';
export { default as beaconChain } from './beaconChain';
export { default as bridgedTokens } from './bridgedTokens';
export { default as blockchainInteraction } from './blockchainInteraction';
export { default as celo } from './celo';
export { default as csvExport } from './csvExport';
export { default as dataAvailability } from './dataAvailability';
export { default as deFiDropdown } from './deFiDropdown';
Expand Down
3 changes: 3 additions & 0 deletions configs/envs/.env.celo_alfajores
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ NEXT_PUBLIC_APP_PORT=3000
NEXT_PUBLIC_APP_ENV=development
NEXT_PUBLIC_API_WEBSOCKET_PROTOCOL=ws

NEXT_PUBLIC_CELO_ENABLED=true
NEXT_PUBLIC_CELO_L2_UPGRADE_BLOCK=26369280

# Instance ENVs
NEXT_PUBLIC_API_BASE_PATH=/
NEXT_PUBLIC_API_HOST=celo-alfajores.blockscout.com
Expand Down
17 changes: 17 additions & 0 deletions deploy/tools/envs-validator/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,22 @@ const rollupSchema = yup
}),
});

const celoSchema = yup
.object()
.shape({
NEXT_PUBLIC_CELO_ENABLED: yup.boolean(),
NEXT_PUBLIC_CELO_L2_UPGRADE_BLOCK: yup
.string()
.when('NEXT_PUBLIC_CELO_ENABLED', {
is: (value: boolean) => value,
then: (schema) => schema.min(0).optional(),
otherwise: (schema) => schema.max(
-1,
'NEXT_PUBLIC_CELO_L2_UPGRADE_BLOCK cannot not be used if NEXT_PUBLIC_CELO_ENABLED is not set to "true"',
),
}),
});

const adButlerConfigSchema = yup
.object<AdButlerConfig>()
.transform(replaceQuotes)
Expand Down Expand Up @@ -867,6 +883,7 @@ const schema = yup
.concat(adsBannerSchema)
.concat(marketplaceSchema)
.concat(rollupSchema)
.concat(celoSchema)
.concat(beaconChainSchema)
.concat(bridgedTokensSchema)
.concat(sentrySchema);
Expand Down
2 changes: 2 additions & 0 deletions deploy/tools/envs-validator/test/.env.celo
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NEXT_PUBLIC_CELO_ENABLED=true
NEXT_PUBLIC_CELO_L2_UPGRADE_BLOCK=420
11 changes: 11 additions & 0 deletions docs/ENVS.md
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,17 @@ For blockchains that implement SUAVE architecture additional fields will be show

&nbsp;

### Celo chain

For blockchains that use the Celo platform. _Note_, that once the Celo mainnet becomes an L2 chain, these variables will be migrated to the Rollup configuration section.

| Variable | Type| Description | Compulsoriness | Default value | Example value | Version |
| --- | --- | --- | --- | --- | --- | --- |
| NEXT_PUBLIC_CELO_ENABLED | `boolean` | Indicates that it is a Celo-based chain. | - | - | `true` | v1.37.0+ |
| NEXT_PUBLIC_CELO_L2_UPGRADE_BLOCK | `number` | Indicates the block number when the Celo-type chain transitioned to L2. This is used to display links to the Epoch block page from a regular block page. | - | - | `26369280` | v1.37.0+ |

&nbsp;

### MetaSuites extension

Enables [MetaSuites browser extension](https://github.com/blocksecteam/metasuites) to integrate with the app views.
Expand Down
3 changes: 3 additions & 0 deletions lib/api/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,9 @@ export const RESOURCES = {
csv_export_logs: {
path: '/api/v1/logs-csv',
},
csv_export_epoch_rewards: {
path: '/api/v1/celo-election-rewards-csv',
},
graphql: {
path: '/api/v1/graphql',
},
Expand Down
8 changes: 7 additions & 1 deletion mocks/address/epochRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,11 @@ export const epochRewards: AddressEpochRewardsResponse = {
token: tokenInfo,
},
],
next_page_params: null,
next_page_params: {
amount: '71952055594478242556',
associated_account_address_hash: '0x30d060f129817c4de5fbc1366d53e19f43c8c64f',
block_number: 25954560,
items_count: 50,
type: 'delegated_payment',
},
};
3 changes: 3 additions & 0 deletions theme/components/Badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const variantSubtle = defineStyle((props) => {
return {
bg: mode('gray.100', 'gray.800')(props),
color: mode('blackAlpha.800', 'whiteAlpha.800')(props),
_hover: {
opacity: 0.76,
},
};
}

Expand Down
4 changes: 4 additions & 0 deletions types/client/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ export type CsvExportParams = {
type: 'holders';
filterType?: undefined;
filterValue?: undefined;
} | {
type: 'epoch-rewards';
filterType?: undefined;
filterValue?: undefined;
};
9 changes: 8 additions & 1 deletion ui/address/AddressEpochRewards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import DataListDisplay from 'ui/shared/DataListDisplay';
import Pagination from 'ui/shared/pagination/Pagination';
import useQueryWithPages from 'ui/shared/pagination/useQueryWithPages';

import AddressCsvExportLink from './AddressCsvExportLink';
import AddressEpochRewardsListItem from './epochRewards/AddressEpochRewardsListItem';

type Props = {
Expand Down Expand Up @@ -71,7 +72,13 @@ const AddressEpochRewards = ({ scrollRef, shouldRender = true, isQueryEnabled =

const actionBar = rewardsQuery.pagination.isVisible ? (
<ActionBar mt={ -6 }>
<Pagination ml="auto" { ...rewardsQuery.pagination }/>
<AddressCsvExportLink
address={ hash }
isLoading={ rewardsQuery.pagination.isLoading }
params={{ type: 'epoch-rewards' }}
ml={{ lg: 'auto' }}
/>
<Pagination ml={{ base: 0, lg: 8 }} { ...rewardsQuery.pagination }/>
</ActionBar>
) : null;

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 15 additions & 1 deletion ui/pages/Block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import React from 'react';
import type { PaginationParams } from 'ui/shared/pagination/types';
import type { RoutedTab } from 'ui/shared/Tabs/types';

import { route } from 'nextjs-routes';

import config from 'configs/app';
import { useAppContext } from 'lib/contexts/app';
import throwOnAbsentParamError from 'lib/errors/throwOnAbsentParamError';
Expand All @@ -24,6 +26,7 @@ import TextAd from 'ui/shared/ad/TextAd';
import ServiceDegradationWarning from 'ui/shared/alerts/ServiceDegradationWarning';
import Tag from 'ui/shared/chakra/Tag';
import AddressEntity from 'ui/shared/entities/address/AddressEntity';
import LinkInternal from 'ui/shared/links/LinkInternal';
import NetworkExplorers from 'ui/shared/NetworkExplorers';
import PageTitle from 'ui/shared/Page/PageTitle';
import Pagination from 'ui/shared/pagination/Pagination';
Expand Down Expand Up @@ -152,9 +155,20 @@ const BlockPageContent = () => {
}

if (!blockQuery.data.celo.is_epoch_block) {
const celoConfig = config.features.celo;
const epochBlockNumber = celoConfig.isEnabled && celoConfig.L2UpgradeBlock && blockQuery.data.height <= celoConfig.L2UpgradeBlock ?
blockQuery.data.celo.epoch_number * celoConfig.BLOCKS_PER_EPOCH :
undefined;
const tag = <Tag colorScheme={ epochBlockNumber ? 'gray-blue' : 'gray' }>Epoch #{ blockQuery.data.celo.epoch_number }</Tag>;
const content = epochBlockNumber ? (
<LinkInternal href={ route({ pathname: '/block/[height_or_hash]', query: { height_or_hash: String(epochBlockNumber) } }) }>
{ tag }
</LinkInternal>
) : tag;

return (
<Tooltip label="Displays the epoch this block belongs to before the epoch is finalized" maxW="280px" textAlign="center">
<Tag>Epoch #{ blockQuery.data.celo.epoch_number }</Tag>
{ content }
</Tooltip>
);
}
Expand Down
5 changes: 5 additions & 0 deletions ui/pages/CsvExport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ const EXPORT_TYPES: Record<CsvExportParams['type'], ExportTypeEntity> = {
resource: 'csv_export_token_holders',
fileNameTemplate: 'holders',
},
'epoch-rewards': {
text: 'epoch rewards',
resource: 'csv_export_epoch_rewards',
fileNameTemplate: 'epoch_rewards',
},
};

const isCorrectExportType = (type: string): type is CsvExportParams['type'] => Object.keys(EXPORT_TYPES).includes(type);
Expand Down
Loading