From 1b99bb7cab7dbf75d7314de8fbd44b80d247a7de Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=BDiga=20Kokelj?=
Date: Mon, 2 Sep 2024 11:30:35 +0200
Subject: [PATCH] Fix Metamask URL in the Gateway + refactor deployment and
passing of args
---
.../manual-deploy-ten-gateway-frontend.yml | 16 +++++++++--
tools/walletextension/frontend/Dockerfile | 3 --
.../frontend/src/api/ethRequests.ts | 9 +++---
.../components/modules/home/disconnected.tsx | 4 +--
.../frontend/src/lib/constants.ts | 28 ++++---------------
.../walletextension/frontend/src/lib/utils.ts | 13 ---------
6 files changed, 24 insertions(+), 49 deletions(-)
diff --git a/.github/workflows/manual-deploy-ten-gateway-frontend.yml b/.github/workflows/manual-deploy-ten-gateway-frontend.yml
index e3fe12fc0b..ecda602e4a 100644
--- a/.github/workflows/manual-deploy-ten-gateway-frontend.yml
+++ b/.github/workflows/manual-deploy-ten-gateway-frontend.yml
@@ -63,6 +63,8 @@ jobs:
declare -a VAR_NAMES=(
"DOCKER_BUILD_TAG_GATEWAY_FE"
"GATEWAY_URL"
+ "NETWORK_NAME"
+ "TENSCAN_URL"
)
for VAR_NAME in "${VAR_NAMES[@]}"; do
@@ -83,6 +85,8 @@ jobs:
echo "IMAGE_NAME_GATEWAY_FE: $IMAGE_NAME_GATEWAY_FE"
echo "DOCKER_BUILD_TAG_GATEWAY_FE: $DOCKER_BUILD_TAG_GATEWAY_FE"
echo "GATEWAY_URL: $GATEWAY_URL"
+ echo "NETWORK_NAME: $NETWORK_NAME"
+ echo "TENSCAN_URL: $TENSCAN_URL"
- uses: actions/checkout@v4
@@ -107,12 +111,14 @@ jobs:
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- - name: Build and Push Docker Image
+ - name: 'Build and Push Docker Image'
run: |
- DOCKER_BUILDKIT=1 docker build --build-arg GATEWAY_API_URL=${{ env.GATEWAY_URL }} -t ${{ env.DOCKER_BUILD_TAG_GATEWAY_FE }} -f ./tools/walletextension/frontend/Dockerfile .
+ DOCKER_BUILDKIT=1 docker build \
+ -t ${{ env.DOCKER_BUILD_TAG_GATEWAY_FE }} \
+ -f ./tools/walletextension/frontend/Dockerfile .
docker push ${{ env.DOCKER_BUILD_TAG_GATEWAY_FE }}
- - name: "Deploy Gateway FE to Azure Container Instances"
+ - name: 'Deploy Gateway FE to Azure Container Instances'
uses: "azure/aci-deploy@v1"
with:
resource-group: ${{ secrets.RESOURCE_GROUP }}
@@ -124,3 +130,7 @@ jobs:
ports: "80"
cpu: 2
memory: 2
+ environment-variables: |
+ NEXT_PUBLIC_API_GATEWAY_URL=${{ env.GATEWAY_URL }}
+ NEXT_PUBLIC_NETWORK_NAME=${{ env.NETWORK_NAME }}
+ NEXT_PUBLIC_TENSCAN_URL=${{ env.TENSCAN_URL }}
diff --git a/tools/walletextension/frontend/Dockerfile b/tools/walletextension/frontend/Dockerfile
index 600dbdf617..c3c0fd8604 100644
--- a/tools/walletextension/frontend/Dockerfile
+++ b/tools/walletextension/frontend/Dockerfile
@@ -1,9 +1,6 @@
# Use an official Node.js LTS version as a base image
FROM node:20-alpine AS base
-ARG GATEWAY_API_URL
-ENV NEXT_PUBLIC_API_GATEWAY_URL=${GATEWAY_API_URL}
-
# Set the working directory
WORKDIR /usr/src/app
diff --git a/tools/walletextension/frontend/src/api/ethRequests.ts b/tools/walletextension/frontend/src/api/ethRequests.ts
index 650c9eb621..ed8583be6e 100644
--- a/tools/walletextension/frontend/src/api/ethRequests.ts
+++ b/tools/walletextension/frontend/src/api/ethRequests.ts
@@ -1,12 +1,11 @@
import {
nativeCurrency,
tenChainIDDecimal,
- tenChainIDHex,
- tenscanLink,
+ tenChainIDHex, tenNetworkName,
+ tenscanAddress,
userStorageAddress,
} from "@/lib/constants";
import {
- getNetworkName,
getRandomIntAsString,
isTenChain,
ethereum,
@@ -114,10 +113,10 @@ export async function addNetworkToMetaMask(rpcUrls: string[]) {
params: [
{
chainId: tenChainIDHex,
- chainName: getNetworkName(),
+ chainName: tenNetworkName,
nativeCurrency,
rpcUrls,
- blockExplorerUrls: [tenscanLink],
+ blockExplorerUrls: [tenscanAddress],
},
],
});
diff --git a/tools/walletextension/frontend/src/components/modules/home/disconnected.tsx b/tools/walletextension/frontend/src/components/modules/home/disconnected.tsx
index 6e741517e8..7c633754e1 100644
--- a/tools/walletextension/frontend/src/components/modules/home/disconnected.tsx
+++ b/tools/walletextension/frontend/src/components/modules/home/disconnected.tsx
@@ -15,7 +15,7 @@ import {
DialogTrigger,
} from "../../ui/dialog";
import Copy from "../common/copy";
-import { testnetUrls, tenChainIDDecimal } from "../../../lib/constants";
+import {tenChainIDDecimal, tenGatewayAddress} from "../../../lib/constants";
import { downloadMetaMask, ethereum } from "@/lib/utils";
const CONNECTION_STEPS = [
@@ -75,7 +75,7 @@ const Disconnected = () => {
-
RPC URL: {testnetUrls.default.url}
+
RPC URL: {tenGatewayAddress}
diff --git a/tools/walletextension/frontend/src/lib/constants.ts b/tools/walletextension/frontend/src/lib/constants.ts
index 70608fcc2d..e0bdbee2ae 100644
--- a/tools/walletextension/frontend/src/lib/constants.ts
+++ b/tools/walletextension/frontend/src/lib/constants.ts
@@ -1,7 +1,11 @@
export const tenGatewayAddress =
process.env.NEXT_PUBLIC_API_GATEWAY_URL || "http://127.0.0.1:1443";
-export const tenscanLink = "https://testnet.tenscan.io";
+export const tenNetworkName =
+ process.env.NEXT_PUBLIC_NETWORK_NAME || "Ten Testnet";
+
+export const tenscanAddress =
+ process.env.NEXT_PUBLIC_TENSCAN_URL || "https://tenscan.io";
export const socialLinks = {
github: "https://github.com/ten-protocol",
@@ -12,28 +16,6 @@ export const socialLinks = {
export const GOOGLE_ANALYTICS_ID = process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS_ID;
-export const testnetUrls = {
- sepolia: {
- name: "Ten Testnet",
- url: "https://sepolia-testnet.ten.xyz",
- rpc: "https://rpc.sepolia-testnet.ten.xyz",
- },
- uat: {
- name: "Ten UAT-Testnet",
- url: "https://uat-testnet.ten.xyz",
- rpc: "https://rpc.uat-testnet.ten.xyz",
- },
- dev: {
- name: "Ten Dev-Testnet",
- url: "https://dev-testnet.ten.xyz",
- rpc: "https://rpc.dev-testnet.ten.xyz",
- },
- default: {
- name: "Ten Testnet",
- url: tenGatewayAddress,
- },
-};
-
export const SWITCHED_CODE = 4902;
export const tokenHexLength = 42;
diff --git a/tools/walletextension/frontend/src/lib/utils.ts b/tools/walletextension/frontend/src/lib/utils.ts
index 3b0e78b9ca..ead2896f5b 100644
--- a/tools/walletextension/frontend/src/lib/utils.ts
+++ b/tools/walletextension/frontend/src/lib/utils.ts
@@ -3,8 +3,6 @@ import { formatDistanceToNow } from "date-fns";
import { twMerge } from "tailwind-merge";
import {
tenChainIDHex,
- tenGatewayAddress,
- testnetUrls,
tokenHexLength,
} from "./constants";
@@ -28,17 +26,6 @@ export function getRandomIntAsString(min: number, max: number) {
return randomInt.toString();
}
-export function getNetworkName() {
- switch (tenGatewayAddress) {
- case testnetUrls.uat.url:
- return testnetUrls.uat.name;
- case testnetUrls.sepolia.url:
- return testnetUrls.sepolia.name;
- default:
- return testnetUrls.default.name;
- }
-}
-
export async function isTenChain() {
if (!ethereum) {
return false;