From 8b5ba692670aa7a6d20fca9ef98a0958b9051d16 Mon Sep 17 00:00:00 2001 From: RcleydsonR Date: Tue, 24 Jan 2023 18:48:13 -0300 Subject: [PATCH] Add environment plugin to change from import meta env to process env --- package.json | 3 ++- src/blockchain/addresses.ts | 4 ++-- src/blockchain/events.ts | 10 +++++----- src/router/index.ts | 2 +- src/services/index.ts | 2 +- vite.config.ts | 3 ++- yarn.lock | 5 +++++ 7 files changed, 18 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index a446a6d..1cc3ed5 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "start": "vite --host=0.0.0.0 --port 3000", "build": "run-p type-check build-only", "preview": "vite preview", - "test:unit": "jest", + "test": "jest", "test:watch": "jest --verbose --watch", "serve": "vue-cli-service serve", "build-only": "vite build", @@ -52,6 +52,7 @@ "ts-jest": "^27.0.0", "typescript": "~4.7.4", "vite": "^3.1.8", + "vite-plugin-environment": "^1.1.3", "vitest": "^0.27.1", "vue-tsc": "^1.0.8", "vue3-jest": "^27.0.0-alpha.1" diff --git a/src/blockchain/addresses.ts b/src/blockchain/addresses.ts index 8fc74fe..126da86 100644 --- a/src/blockchain/addresses.ts +++ b/src/blockchain/addresses.ts @@ -27,8 +27,8 @@ const getProviderUrl = (): string => { const etherStore = useEtherStore(); const possibleProvidersUrls: { [key: string]: string } = { - Ethereum: import.meta.env.VITE_GOERLI_API_URL, - Polygon: import.meta.env.VITE_MUMBAI_API_URL, + Ethereum: process.env.VITE_GOERLI_API_URL ? process.env.VITE_GOERLI_API_URL : "", + Polygon: process.env.VITE_MUMBAI_API_URL ? process.env.VITE_MUMBAI_API_URL : "", }; return possibleProvidersUrls[etherStore.networkName]; diff --git a/src/blockchain/events.ts b/src/blockchain/events.ts index f0242d0..bd88cd3 100644 --- a/src/blockchain/events.ts +++ b/src/blockchain/events.ts @@ -11,14 +11,14 @@ const getNetworksLiquidity = async (): Promise => { console.log("Loading events"); const goerliProvider = new ethers.providers.JsonRpcProvider( - import.meta.env.VITE_GOERLI_API_URL, + process.env.VITE_GOERLI_API_URL, 5 ); // goerli provider const mumbaiProvider = new ethers.providers.JsonRpcProvider( - import.meta.env.VITE_MUMBAI_API_URL, + process.env.VITE_MUMBAI_API_URL, 80001 ); // mumbai provider - + const p2pContractGoerli = new ethers.Contract( "0x5f3EFA9A90532914545CEf527C530658af87e196", p2pix.abi, @@ -29,7 +29,7 @@ const getNetworksLiquidity = async (): Promise => { p2pix.abi, mumbaiProvider ); - + const depositListGoerli = await getValidDeposits(p2pContractGoerli); const depositListMumbai = await getValidDeposits(p2pContractMumbai); @@ -55,7 +55,7 @@ const getValidDeposits = async ( const filterDeposits = p2pContract.filters.DepositAdded(null); const eventsDeposits = await p2pContract.queryFilter(filterDeposits); - p2pContract = getContract(); // get metamask provider contract + if(!contract) p2pContract = getContract(); // get metamask provider contract const depositList = await Promise.all( eventsDeposits.map(async (deposit) => { diff --git a/src/router/index.ts b/src/router/index.ts index bdce7dd..c3ab72c 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -5,7 +5,7 @@ import ManageBidsView from "../views/ManageBidsView.vue"; import SellerView from "@/views/SellerView.vue"; const router = createRouter({ - history: createWebHistory(import.meta.env.BASE_URL), + history: createWebHistory(process.env.BASE_URL), routes: [ { path: "/", diff --git a/src/services/index.ts b/src/services/index.ts index 8f4cc1a..149da3f 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -8,7 +8,7 @@ const defaultConfig = { const api = axios.create({ ...defaultConfig, - baseURL: import.meta.env.VITE_API_URL, + baseURL: process.env.VITE_API_URL, }); export default api; diff --git a/vite.config.ts b/vite.config.ts index b20d948..1f30a4e 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -3,10 +3,11 @@ import { fileURLToPath, URL } from "node:url"; import { defineConfig } from "vite"; import vue from "@vitejs/plugin-vue"; import vueJsx from "@vitejs/plugin-vue-jsx"; +import EnvironmentPlugin from 'vite-plugin-environment'; // https://vitejs.dev/config/ export default defineConfig({ - plugins: [vue(), vueJsx()], + plugins: [vue(), vueJsx(), EnvironmentPlugin('all')], resolve: { alias: { "@": fileURLToPath(new URL("./src", import.meta.url)), diff --git a/yarn.lock b/yarn.lock index 2745b3f..7bfa59e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5924,6 +5924,11 @@ vite-node@0.27.1: source-map-support "^0.5.21" vite "^3.0.0 || ^4.0.0" +vite-plugin-environment@^1.1.3: + version "1.1.3" + resolved "https://registry.yarnpkg.com/vite-plugin-environment/-/vite-plugin-environment-1.1.3.tgz#d01a04abb2f69730a4866c9c9db51d3dab74645b" + integrity sha512-9LBhB0lx+2lXVBEWxFZC+WO7PKEyE/ykJ7EPWCq95NEcCpblxamTbs5Dm3DLBGzwODpJMEnzQywJU8fw6XGGGA== + "vite@^3.0.0 || ^4.0.0", vite@^3.1.8: version "3.1.8" resolved "https://registry.npmjs.org/vite/-/vite-3.1.8.tgz"