From e275460c769f4d6d8a47cc9b733f5bb62dfa9100 Mon Sep 17 00:00:00 2001 From: Dexter Edwards Date: Wed, 27 Jul 2022 11:28:29 +0100 Subject: [PATCH] feat: allow default wallet url to be configured (#875) * feat: allow default wallet url to be configured * docs: add docs to environement package --- apps/token-e2e/.env | 3 ++- apps/token/.env | 1 + apps/trading-e2e/.env | 1 + apps/trading/.env | 1 + libs/environment/README.md | 2 ++ .../src/utils/compile-environment.ts | 2 ++ .../src/utils/validate-environment.ts | 1 + .../connect-dialog/connect-dialog.spec.tsx | 23 +++++++++++++++---- libs/wallet/src/rest-connector-form.tsx | 7 +++--- 9 files changed, 31 insertions(+), 10 deletions(-) diff --git a/apps/token-e2e/.env b/apps/token-e2e/.env index 6d3d52c1f..253cd8dda 100644 --- a/apps/token-e2e/.env +++ b/apps/token-e2e/.env @@ -12,7 +12,8 @@ NX_ETHEREUM_CHAIN_ID=1440 NX_ETH_URL_CONNECT=1 NX_ETH_WALLET_MNEMONIC=ozone access unlock valid olympic save include omit supply green clown session NX_LOCAL_PROVIDER_URL=http://localhost:8545/ +NX_VEGA_WALLET_URL=http://localhost:1789/api/v1 #Test configuration variables CYPRESS_FAIRGROUND=false -CYPRESS_INCLUDE_FLOWS=true \ No newline at end of file +CYPRESS_INCLUDE_FLOWS=true diff --git a/apps/token/.env b/apps/token/.env index c5982dfb4..b254c7be6 100644 --- a/apps/token/.env +++ b/apps/token/.env @@ -8,6 +8,7 @@ NX_FAIRGROUND=false NX_IS_NEW_BRIDGE_CONTRACT=true NX_VEGA_NETWORKS='{"DEVNET":"https://dev.token.vega.xyz","STAGNET":"https://dev.token.vega.xyz","STAGNET2":"staging2.token.vega.xyz","TESTNET":"token.fairground.wtf","MAINNET":"token.vega.xyz"}' NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions +NX_VEGA_WALLET_URL=http://localhost:1789/api/v1 #Test configuration variables CYPRESS_FAIRGROUND=false diff --git a/apps/trading-e2e/.env b/apps/trading-e2e/.env index 92559423b..fab1c558d 100644 --- a/apps/trading-e2e/.env +++ b/apps/trading-e2e/.env @@ -1 +1,2 @@ NX_USE_ENV_OVERRIDES=0 +NX_VEGA_WALLET_URL=http://localhost:1789/api/v1 diff --git a/apps/trading/.env b/apps/trading/.env index 1e7125719..cf3e5ef66 100644 --- a/apps/trading/.env +++ b/apps/trading/.env @@ -6,3 +6,4 @@ NX_ETHERSCAN_URL=https://ropsten.etherscan.io NX_VEGA_NETWORKS={\"MAINNET\":\"https://alpha.console.vega.xyz\"} NX_USE_ENV_OVERRIDES=1 NX_VEGA_EXPLORER_URL=https://explorer.fairground.wtf +NX_VEGA_WALLET_URL=http://localhost:1789/api/v1 diff --git a/libs/environment/README.md b/libs/environment/README.md index 32ad9c42f..0666759b5 100644 --- a/libs/environment/README.md +++ b/libs/environment/README.md @@ -12,6 +12,8 @@ The environment variables needed to be present for any app consuming this librar `NX_VEGA_URL` OR `NX_VEGA_CONFIG_URL` - either the network configuration url or a url to a node to directly connect to +`NX_VEGA_WALLET_URL` the default vega wallet URL + For examples, see Block Explorer's .env files [here](../../apps/explorer) ## Running unit tests diff --git a/libs/environment/src/utils/compile-environment.ts b/libs/environment/src/utils/compile-environment.ts index 445c4f786..c733e6434 100644 --- a/libs/environment/src/utils/compile-environment.ts +++ b/libs/environment/src/utils/compile-environment.ts @@ -68,6 +68,8 @@ const getBundledEnvironmentValue = (key: EnvKey) => { return process.env['NX_GITHUB_FEEDBACK_URL']; case 'VEGA_EXPLORER_URL': return process.env['NX_VEGA_EXPLORER_URL']; + case 'VEGA_WALLET_URL': + return process.env['NX_VEGA_WALLET_URL']; } }; diff --git a/libs/environment/src/utils/validate-environment.ts b/libs/environment/src/utils/validate-environment.ts index 2289ab6a2..d3a659c6d 100644 --- a/libs/environment/src/utils/validate-environment.ts +++ b/libs/environment/src/utils/validate-environment.ts @@ -14,6 +14,7 @@ export enum Networks { const schemaObject = { VEGA_URL: z.optional(z.string()), + VEGA_WALLET_URL: z.optional(z.string()), VEGA_CONFIG_URL: z.optional(z.string()), GIT_BRANCH: z.optional(z.string()), GIT_COMMIT_HASH: z.optional(z.string()), diff --git a/libs/wallet/src/connect-dialog/connect-dialog.spec.tsx b/libs/wallet/src/connect-dialog/connect-dialog.spec.tsx index 10bcc271d..77c85e000 100644 --- a/libs/wallet/src/connect-dialog/connect-dialog.spec.tsx +++ b/libs/wallet/src/connect-dialog/connect-dialog.spec.tsx @@ -10,6 +10,7 @@ import { VegaWalletContext } from '../context'; import { VegaConnectDialog } from './connect-dialog'; import type { VegaConnectDialogProps } from '..'; import { RestConnector } from '../connectors'; +import { EnvironmentProvider } from '@vegaprotocol/environment'; let defaultProps: VegaConnectDialogProps; let defaultContextValue: VegaWalletContextShape; @@ -35,16 +36,28 @@ beforeEach(() => { const DEFAULT_URL = 'http://localhost:1789/api/v1'; +const mockEnvironment = { + VEGA_ENV: 'TESTNET', + VEGA_URL: 'https://vega-node.url', + VEGA_NETWORKS: JSON.stringify({}), + GIT_BRANCH: 'test', + GIT_COMMIT_HASH: 'abcdef', + GIT_ORIGIN_URL: 'https://github.com/test/repo', + VEGA_WALLET_URL: DEFAULT_URL, +}; + function generateJSX( props?: Partial, contextValue?: Partial ) { return ( - - - + + + + + ); } diff --git a/libs/wallet/src/rest-connector-form.tsx b/libs/wallet/src/rest-connector-form.tsx index 84666c582..8cbbb6be7 100644 --- a/libs/wallet/src/rest-connector-form.tsx +++ b/libs/wallet/src/rest-connector-form.tsx @@ -1,3 +1,4 @@ +import { useEnvironment } from '@vegaprotocol/environment'; import { t } from '@vegaprotocol/react-helpers'; import { Button, FormGroup, Input, InputError } from '@vegaprotocol/ui-toolkit'; import { useState } from 'react'; @@ -15,21 +16,19 @@ interface RestConnectorFormProps { onAuthenticate: () => void; } -const VEGA_DEFAULT_URL = 'http://localhost:1789/api/v1'; - export function RestConnectorForm({ connector, onAuthenticate, }: RestConnectorFormProps) { const [error, setError] = useState(''); - + const { VEGA_WALLET_URL } = useEnvironment(); const { register, handleSubmit, formState: { errors }, } = useForm({ defaultValues: { - url: VEGA_DEFAULT_URL, + url: VEGA_WALLET_URL, }, });