From a08d082c77d3592da89a9f488d8a3befc0e111d2 Mon Sep 17 00:00:00 2001 From: Vivian Plasencia Date: Mon, 25 Mar 2024 14:06:29 +0100 Subject: [PATCH] refactor: move the blockchain credential supported networks to the bandada utils package Since the supported networks are attached to the infrastructure and not to the credential package, they have been to the bandada utils package. re #443 --- apps/api/.env.example | 15 ++++++++------- .../app/credentials/credentials.service.test.ts | 3 ++- .../src/app/credentials/credentials.service.ts | 14 +++++++++++--- .../new-group-stepper/access-mode-step.tsx | 16 +++------------- .../src/providers/blockchain/index.ts | 9 +-------- libs/credentials/src/types/index.ts | 1 - libs/utils/src/getSupportedNetworks.ts | 6 ++++++ libs/utils/src/index.ts | 4 +++- 8 files changed, 34 insertions(+), 34 deletions(-) create mode 100644 libs/utils/src/getSupportedNetworks.ts diff --git a/apps/api/.env.example b/apps/api/.env.example index 84bbf5f8..616f9534 100644 --- a/apps/api/.env.example +++ b/apps/api/.env.example @@ -23,10 +23,11 @@ TWITTER_REDIRECT_URI= TWITTER_CLIENT_ID= TWITTER_CLIENT_SECRET= -# The network name must be the same as the supportedNetworks in blockchain provider -# but with capital letters and an underscore instead of a space to separate words. - -BLOCKCHAIN_SEPOLIA_RPC_URL= -BLOCKCHAIN_POLYGON_MUMBAI_RPC_URL= -BLOCKCHAIN_OPTIMISM_SEPOLIA_RPC_URL= -BLOCKCHAIN_ARBITRUM_SEPOLIA_RPC_URL= +# The network name must be the same as the blockchainCredentialNetworks in `getSupportedNetworks` +# in the `@bandada/utils` package but with capital letters and an underscore instead of a space +# to separate words. + +SEPOLIA_RPC_URL= +POLYGON_MUMBAI_RPC_URL= +OPTIMISM_SEPOLIA_RPC_URL= +ARBITRUM_SEPOLIA_RPC_URL= diff --git a/apps/api/src/app/credentials/credentials.service.test.ts b/apps/api/src/app/credentials/credentials.service.test.ts index 57e9175c..b8439a24 100644 --- a/apps/api/src/app/credentials/credentials.service.test.ts +++ b/apps/api/src/app/credentials/credentials.service.test.ts @@ -18,7 +18,8 @@ jest.mock("@bandada/utils", () => ({ logs: ["1"] }), getGroups: () => [] - }) + }), + blockchainCredentialNetworks: ["Sepolia"] })) jest.mock("@bandada/credentials", () => ({ diff --git a/apps/api/src/app/credentials/credentials.service.ts b/apps/api/src/app/credentials/credentials.service.ts index 47d9c4f3..d9ffe496 100644 --- a/apps/api/src/app/credentials/credentials.service.ts +++ b/apps/api/src/app/credentials/credentials.service.ts @@ -7,6 +7,7 @@ import { Web2Context, BlockchainContext } from "@bandada/credentials" +import { blockchainCredentialNetworks } from "@bandada/utils" import { id } from "@ethersproject/hash" import { BadRequestException, @@ -106,14 +107,21 @@ export class CredentialsService { if (address) { const { network } = JSON.parse(group.credentials).criteria + + if ( + !blockchainCredentialNetworks.some( + (n) => n.toLowerCase() === network.toLowerCase() + ) + ) { + throw new BadRequestException(`The network is not supported`) + } + const networkEnvVariableName = (network as string) .split(" ") .join("_") .toUpperCase() const web3providerRpcURL = - process.env[ - `${providerName.toUpperCase()}_${networkEnvVariableName}_RPC_URL` - ] + process.env[`${networkEnvVariableName}_RPC_URL`] const jsonRpcProvider = await ( provider as BlockchainProvider diff --git a/apps/dashboard/src/components/new-group-stepper/access-mode-step.tsx b/apps/dashboard/src/components/new-group-stepper/access-mode-step.tsx index 13c2c311..5e9dcd6c 100644 --- a/apps/dashboard/src/components/new-group-stepper/access-mode-step.tsx +++ b/apps/dashboard/src/components/new-group-stepper/access-mode-step.tsx @@ -1,9 +1,5 @@ -import { - validators, - providers, - Provider, - BlockchainProvider -} from "@bandada/credentials" +import { validators } from "@bandada/credentials" +import { blockchainCredentialNetworks } from "@bandada/utils" import { Box, Button, @@ -248,13 +244,7 @@ export default function AccessModeStep({ }) } > - {( - providers.find( - (provider: Provider) => - provider.name === - "blockchain" - ) as BlockchainProvider - ).supportedNetworks.map( + {blockchainCredentialNetworks.map( (network: string) => (