Skip to content

Commit

Permalink
hotfix: network configurations for the polygon ledger (#825)
Browse files Browse the repository at this point in the history
* hotfix: polygon network configurations

Signed-off-by: bhavanakarwade <[email protected]>

* refactor: created common function for fetch polygon networks

Signed-off-by: bhavanakarwade <[email protected]>

* fix: made enum is in pascal case

Signed-off-by: bhavanakarwade <[email protected]>

---------

Signed-off-by: bhavanakarwade <[email protected]>
  • Loading branch information
bhavanakarwade authored Nov 19, 2024
1 parent f8b2636 commit 5a2e64a
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .env.sample
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PUBLIC_BASE_URL=
PUBLIC_CRYPTO_PRIVATE_KEY=

PUBLIC_MODE=
PUBLIC_SHOW_NAME_AS_LOGO= # Please provide true if you want to give platform name with logo

PUBLIC_KEYCLOAK_MANAGEMENT_CLIENT_ID= # Please sepcify your client id
Expand Down
8 changes: 7 additions & 1 deletion src/common/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,10 @@ export enum RequestType {
export enum ProofType {
polygon = 'EcdsaSecp256k1Signature2019',
no_ledger = 'Ed25519Signature2018'
}
}

export enum Environment {
Prod = 'Prod',
Dev = 'Dev',
Qa = 'Qa'
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
getLedgerConfig,
getLedgers
} from '../../../api/Agent';
import { DidMethod, Ledgers, Network} from '../../../common/enums';
import { DidMethod, Environment, Ledgers, Network} from '../../../common/enums';
import type { IDedicatedAgentForm, ILedgerConfigData, ILedgerItem, IValuesShared, IDedicatedAgentData} from './interfaces';
import { getFromLocalStorage } from '../../../api/Auth';
import CopyDid from '../../../commonComponents/CopyDid';
Expand All @@ -20,6 +20,8 @@ import SetPrivateKeyValueInput from './SetPrivateKeyValue';
import { getOrganizationById, setAgentConfigDetails } from '../../../api/organization';
import type { IDedicatedAgentConfig} from '../interfaces';
import React from 'react';
import { envConfig } from '../../../config/envConfig';
import { getFilteredNetworks } from '../../../lib/data';

const RequiredAsterisk = () => <span className="text-xs text-red-500">*</span>

Expand Down Expand Up @@ -236,12 +238,13 @@ const networkRenderOptions = (formikHandlers: { handleChange: (e: React.ChangeEv
return null;
}

let filteredNetworks = Object.keys(networks);
if (selectedMethod === DidMethod.POLYGON) {
filteredNetworks = filteredNetworks.filter(network => network === Network.MAINNET);
}
const filterNetworks = getFilteredNetworks(
Object.keys(networks),
envConfig.MODE,
selectedMethod
);

return filteredNetworks.map((network) => (
return filterNetworks.map((network) => (
<div key={network} className="mt-2">
<input
type="radio"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import { apiStatusCodes } from "../../../config/CommonConstant";
import * as yup from 'yup';
import type { AxiosResponse } from 'axios';
import CopyDid from '../../../commonComponents/CopyDid';
import { DidMethod, Ledgers, Network } from '../../../common/enums';
import { DidMethod, Environment, Ledgers, Network } from '../../../common/enums';
import SetDomainValueInput from './SetDomainValueInput';
import SetPrivateKeyValueInput from './SetPrivateKeyValue';
import type { ISharedAgentForm, IValuesShared } from "./interfaces";
import React from "react";
import { envConfig } from "../../../config/envConfig";
import { getFilteredNetworks } from "../../../lib/data";
interface IDetails {
[key: string]: string | { [subKey: string]: string };
}
Expand Down Expand Up @@ -210,10 +212,11 @@ const SharedAgentForm = ({
return null;
}

let filteredNetworks = Object.keys(networks);
if (selectedMethod === DidMethod.POLYGON) {
filteredNetworks = filteredNetworks.filter(network => network === Network.MAINNET);
}
const filteredNetworks = getFilteredNetworks(
Object.keys(networks),
envConfig.MODE,
selectedMethod
);

return filteredNetworks.map((network) => (
<div key={network} className="mt-2">
Expand Down
5 changes: 3 additions & 2 deletions src/config/envConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if (import.meta.env) {
}
}

const { PUBLIC_BASE_URL, PUBLIC_POLYGON_TESTNET_URL, PUBLIC_POLYGON_MAINNET_URL, PUBLIC_CRYPTO_PRIVATE_KEY,PUBLIC_SHOW_NAME_AS_LOGO, PUBLIC_PLATFORM_NAME, PUBLIC_PLATFORM_LOGO, PUBLIC_POWERED_BY, PUBLIC_PLATFORM_WEB_URL, PUBLIC_POWERED_BY_URL, PUBLIC_PLATFORM_DOCS_URL, PUBLIC_PLATFORM_GIT, PUBLIC_PLATFORM_SUPPORT_EMAIL, PUBLIC_PLATFORM_TWITTER_URL, PUBLIC_KEYCLOAK_MANAGEMENT_CLIENT_ID, PUBLIC_KEYCLOAK_MANAGEMENT_CLIENT_SECRET, PUBLIC_PLATFORM_SUPPORT_INVITE, PUBLIC_PLATFORM_DISCORD_URL, PUBLIC_ALLOW_DOMAIN }: any = envVariables;
const { PUBLIC_BASE_URL, PUBLIC_POLYGON_TESTNET_URL, PUBLIC_POLYGON_MAINNET_URL, PUBLIC_CRYPTO_PRIVATE_KEY,PUBLIC_SHOW_NAME_AS_LOGO, PUBLIC_PLATFORM_NAME, PUBLIC_PLATFORM_LOGO, PUBLIC_POWERED_BY, PUBLIC_PLATFORM_WEB_URL, PUBLIC_POWERED_BY_URL, PUBLIC_PLATFORM_DOCS_URL, PUBLIC_PLATFORM_GIT, PUBLIC_PLATFORM_SUPPORT_EMAIL, PUBLIC_PLATFORM_TWITTER_URL, PUBLIC_KEYCLOAK_MANAGEMENT_CLIENT_ID, PUBLIC_KEYCLOAK_MANAGEMENT_CLIENT_SECRET, PUBLIC_PLATFORM_SUPPORT_INVITE, PUBLIC_PLATFORM_DISCORD_URL, PUBLIC_ALLOW_DOMAIN, PUBLIC_MODE }: any = envVariables;

export const envConfig = {
PUBLIC_BASE_URL:
Expand Down Expand Up @@ -69,5 +69,6 @@ export const envConfig = {
PUBLIC_KEYCLOAK_MANAGEMENT_CLIENT_SECRET ||
import.meta.env.PUBLIC_KEYCLOAK_MANAGEMENT_CLIENT_SECRET,
},
PUBLIC_ALLOW_DOMAIN: PUBLIC_ALLOW_DOMAIN || import.meta.env.PUBLIC_ALLOW_DOMAIN
PUBLIC_ALLOW_DOMAIN: PUBLIC_ALLOW_DOMAIN || import.meta.env.PUBLIC_ALLOW_DOMAIN,
MODE: PUBLIC_MODE || import.meta.env.PUBLIC_MODE
}
18 changes: 18 additions & 0 deletions src/lib/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// GraphQL, Databases, REST APIs, CDNs, proxies, S3, Matrix, IPFS, you name it…

import { API_URL, REMOTE_ASSETS_BASE_URL } from '../app/constants.js';
import { DidMethod, Environment, Network } from '../common/enums.js';
import type { Endpoint, EndpointsToOperations } from '../types/entities.js';

export async function fetchData<Selected extends Endpoint>(endpoint: Selected) {
Expand Down Expand Up @@ -31,3 +32,20 @@ export function asset(path: string) {
// NOTE: Fetching remote assets from the Hugo admin dashboard Vercel dist.
return `${REMOTE_ASSETS_BASE_URL}/${path}`;
}

export const getFilteredNetworks = (
networks: string[],
envMode: Environment,
selectedMethod: string
): string[] => {
if (envMode === Environment.Prod && selectedMethod === DidMethod.POLYGON) {
return networks.filter(network => network === Network.MAINNET);
} else if (
(envMode === Environment.Dev || envMode === Environment.Qa) &&
selectedMethod === DidMethod.POLYGON
) {
return networks.filter(network => network === Network.TESTNET);
}
return networks;
};

0 comments on commit 5a2e64a

Please sign in to comment.