Skip to content

Commit

Permalink
[skip ci] better types for tx interpretation
Browse files Browse the repository at this point in the history
  • Loading branch information
tom2drum committed Jan 4, 2024
1 parent 4afed28 commit a078553
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
14 changes: 12 additions & 2 deletions configs/app/features/txInterpretation.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import type { Feature } from './types';
import type { Provider } from 'types/client/txInterpretation';
import { PROVIDERS } from 'types/client/txInterpretation';

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

const title = 'Transaction interpretation';

const provider = getEnvValue('NEXT_PUBLIC_TRANSACTION_INTERPRETATION_PROVIDER') || 'none';
const provider: Provider = (() => {
const value = getEnvValue('NEXT_PUBLIC_TRANSACTION_INTERPRETATION_PROVIDER');

const config: Feature<{ provider: string }> = (() => {
if (value && PROVIDERS.includes(value as Provider)) {
return value as Provider;
}

return 'none';
})();

const config: Feature<{ provider: Provider }> = (() => {
if (provider !== 'none') {
return Object.freeze({
title,
Expand Down
3 changes: 2 additions & 1 deletion deploy/tools/envs-validator/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type { MarketplaceAppOverview } from '../../../types/client/marketplace';
import { NAVIGATION_LINK_IDS } from '../../../types/client/navigation-items';
import type { NavItemExternal, NavigationLinkId } from '../../../types/client/navigation-items';
import type { BridgedTokenChain, TokenBridge } from '../../../types/client/token';
import { PROVIDERS as TX_INTERPRETATION_PROVIDERS } from '../../../types/client/txInterpretation';
import type { WalletType } from '../../../types/client/wallets';
import { SUPPORTED_WALLETS } from '../../../types/client/wallets';
import type { CustomLink, CustomLinksGroup } from '../../../types/footerLinks';
Expand Down Expand Up @@ -438,7 +439,7 @@ const schema = yup
return isNoneSchema.isValidSync(data) || isArrayOfWalletsSchema.isValidSync(data);
}),
NEXT_PUBLIC_WEB3_DISABLE_ADD_TOKEN_TO_WALLET: yup.boolean(),
NEXT_PUBLIC_TRANSACTION_INTERPRETATION_PROVIDER: yup.string().oneOf([ 'blockscout', 'none' ]),
NEXT_PUBLIC_TRANSACTION_INTERPRETATION_PROVIDER: yup.string().oneOf(TX_INTERPRETATION_PROVIDERS),
NEXT_PUBLIC_AD_TEXT_PROVIDER: yup.string<AdTextProviders>().oneOf(SUPPORTED_AD_TEXT_PROVIDERS),
NEXT_PUBLIC_PROMOTE_BLOCKSCOUT_IN_TITLE: yup.boolean(),
NEXT_PUBLIC_OG_DESCRIPTION: yup.string(),
Expand Down
8 changes: 8 additions & 0 deletions types/client/txInterpretation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { ArrayElement } from 'types/utils';

export const PROVIDERS = [
'blockscout',
'none',
] as const;

export type Provider = ArrayElement<typeof PROVIDERS>;

0 comments on commit a078553

Please sign in to comment.