Skip to content

Commit

Permalink
add different names for different testnets
Browse files Browse the repository at this point in the history
  • Loading branch information
zkokelj committed Oct 4, 2023
1 parent bf0177e commit 7a2a94e
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions tools/walletextension/api/staticOG/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ const idAddAccount = "addAccount";
const idAddAllAccounts = "addAllAccounts";
const idRevokeUserID = "revokeUserID";
const idStatus = "status";
const idConnectButton = "connectButton"
const obscuroGatewayVersion = "v1"
const idConnectButton = "connectButton";
const idAccountsTable = "accountsTable";
const idTableBody = "tableBody";
const obscuroGatewayVersion = "v1";
const pathJoin = obscuroGatewayVersion + "/join/";
const pathAuthenticate = obscuroGatewayVersion + "/authenticate/";
const pathQuery = obscuroGatewayVersion + "/query/";
Expand Down Expand Up @@ -51,6 +53,17 @@ async function fetchAndDisplayVersion() {
}
}

function getNetworkName(gatewayAddress) {
switch(gatewayAddress) {
case 'https://uat-testnet.obscu.ro/':
return 'Obscuro UAT-Testnet';
case 'https://dev-testnet.obscu.ro/':
return 'Obscuro Dev-Testnet';
default:
return 'Obscuro Testnet';
}
}

async function addNetworkToMetaMask(ethereum, userID, chainIDDecimal) {
// add network to MetaMask
let chainIdHex = "0x" + chainIDDecimal.toString(16); // Convert to hexadecimal and prefix with '0x'
Expand All @@ -60,7 +73,7 @@ async function addNetworkToMetaMask(ethereum, userID, chainIDDecimal) {
params: [
{
chainId: chainIdHex,
chainName: 'Obscuro Testnet',
chainName: getNetworkName(obscuroGatewayAddress),
nativeCurrency: {
name: 'Sepolia Ether',
symbol: 'ETH',
Expand Down Expand Up @@ -228,10 +241,10 @@ const initialize = async () => {
const addAllAccountsButton = document.getElementById(idAddAllAccounts);
const revokeUserIDButton = document.getElementById(idRevokeUserID);
const statusArea = document.getElementById(idStatus);
const connectButton = document.getElementById("connectButton");
const connectButton = document.getElementById(idConnectButton);

const accountsTable = document.getElementById('accountsTable')
const tableBody = document.getElementById('tableBody');
const accountsTable = document.getElementById(idAccountsTable)
const tableBody = document.getElementById(idTableBody);
// getUserID from the gateway with getStorageAt method
let userID = await getUserID()

Expand Down Expand Up @@ -264,22 +277,26 @@ const initialize = async () => {
await populateAccountsTable(document, tableBody, userID)
}

// load the current version
await fetchAndDisplayVersion();

// handle which buttons should be shown to the user
if (await isMetamaskConnected()) {
// check if userID exists and has a correct type and length (is valid) and display either
// option to join or to add a new account to existing user
if (isValidUserIDFormat(userID)) {
await displayConnectedAndJoinedSuccessfully()
async function displayCorrectScreenBasedOnMetamaskAndUserID() {
// handle which buttons should be shown to the user
if (await isMetamaskConnected()) {
// check if userID exists and has a correct type and length (is valid) and display either
// option to join or to add a new account to existing user
if (isValidUserIDFormat(userID)) {
await displayConnectedAndJoinedSuccessfully()
} else {
displayOnlyJoin()
}
} else {
displayOnlyJoin()
displayOnlyConnectButton()
}
} else {
displayOnlyConnectButton()
}

// load the current version
await fetchAndDisplayVersion();

await displayCorrectScreenBasedOnMetamaskAndUserID()

joinButton.addEventListener(eventClick, async () => {
// join Obscuro Gateway
Expand Down Expand Up @@ -358,7 +375,6 @@ const initialize = async () => {
})

connectButton.addEventListener(eventClick, async () => {
console.log("connect button!")
await connectAccounts();
location.reload()
})
Expand Down

0 comments on commit 7a2a94e

Please sign in to comment.