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

Allow overwriting the RPC URL of the Verida DID client #258

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
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Polygon RPC URL (Optional)
VUE_APP_POLYGON_RPC_URL=

# Verida vault context name. (Required)
VUE_APP_VAULT_CONTEXT_NAME=Verida: Vault

Expand Down
2 changes: 1 addition & 1 deletion src/@types/node/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
declare namespace NodeJS {
export interface ProcessEnv {
NODE_ENV?: "production" | "development" | "test";
VUE_APP_POLYGON_RPC_URL?: string;
VUE_APP_VERIDA_CONTEXT_NAME?: string;
VUE_APP_VERIDA_VAULT_CONTEXT_NAME?: string;
VUE_APP_VERIDA_LOGO_URL?: string;
VUE_APP_VERDIA_LOGIN_TEXT?: string;
VUE_APP_BASE_URL?: string;
VUE_APP_VERIDA_TESTNET_DEFAULT_DID_SERVER?: string;
VUE_APP_VERIDA_ENV?: "testnet" | "mainnet" | "local";
}
}
5 changes: 2 additions & 3 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@

const nodeEnv = process.env.NODE_ENV || "development";

console.log(process.env.VUE_APP_VERIDA_ENV);

Check warning on line 5 in src/config/index.ts

View workflow job for this annotation

GitHub Actions / build-app

Unexpected console statement

const veridaEnv: EnvironmentType = <EnvironmentType>(
process.env.VUE_APP_VERIDA_ENV
);

const veridaRpcUrl = process.env.VUE_APP_POLYGON_RPC_URL;
const veridaLogoUrl = process.env.VUE_APP_VERIDA_LOGO_URL;
const veridaLoginText = process.env.VUE_APP_VERIDA_LOGO_URL;
const veridaContextName = process.env.VUE_APP_VERIDA_CONTEXT_NAME;
const veridaVaultContextName = process.env.VUE_APP_VERIDA_VAULT_CONTEXT_NAME;
const veridaNodeSummaryUrl = process.env.VUE_APP_NODE_SUMMARY_URL;
const veridaNetworkStatusUrl = process.env.VUE_APP_NETWORK_STATUS_URL;
const veridaTestnetDefaultDidServerUrl =
process.env.VUE_APP_VERIDA_TESTNET_DEFAULT_DID_SERVER;
const veridaExplorerUrls = {
mainnet: process.env.VUE_APP_EXPLORER_URL_MAINNET,
testnet: process.env.VUE_APP_EXPLORER_URL_TESTNET,
Expand All @@ -24,11 +23,11 @@
export const config = {
nodeEnv,
veridaEnv,
veridaRpcUrl,
veridaLogoUrl,
veridaLoginText,
veridaContextName,
veridaVaultContextName,
veridaTestnetDefaultDidServerUrl,
veridaNodeSummaryUrl,
veridaNetworkStatusUrl,
veridaExplorerUrls,
Expand Down
11 changes: 7 additions & 4 deletions src/helpers/VeridaHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ import { CREDENTIAL } from "@/constant";
import { Profile } from "@/interface";
import { Client, Context } from "@verida/client-ts";
import { decodeUri, fetchVeridaUri } from "@verida/helpers";
import { IMessaging } from "@verida/types";
import { ClientConfig, IMessaging } from "@verida/types";
import { Credentials } from "@verida/verifiable-credentials";
import dayjs from "dayjs";
import utc from "dayjs/plugin/utc";
import { EventEmitter } from "events";

dayjs.extend(utc);

const userConfig = {
const userConfig: ClientConfig = {
environment: config.veridaEnv,
didServerUrl: config.veridaTestnetDefaultDidServerUrl,
didClientConfig: {
network: config.veridaEnv,
rpcUrl: config.veridaRpcUrl,
},
};

class VeridaClient extends EventEmitter {
Expand All @@ -28,7 +31,7 @@ class VeridaClient extends EventEmitter {
private _messagingInstance: IMessaging | undefined;
on: any;

constructor(config: typeof userConfig) {
constructor(config: ClientConfig) {
super();
this.client = new Client(config);
this.did = "";
Expand Down
Loading