-
Notifications
You must be signed in to change notification settings - Fork 0
Cais gateway UI changes #15
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
base: base-sha/d494bc8c6ad4c6f1008838b2a8d91e044ab53d63
Are you sure you want to change the base?
Changes from all commits
4321d38
13cacfb
b87194d
ec52d10
4f0407d
1a227b2
7f4aafd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -5,6 +5,10 @@ const idRevokeUserID = "revokeUserID"; | |||||||||||||||||||||||||||||||||||||||||
const idStatus = "status"; | ||||||||||||||||||||||||||||||||||||||||||
const idAccountsTable = "accountsTable"; | ||||||||||||||||||||||||||||||||||||||||||
const idTableBody = "tableBody"; | ||||||||||||||||||||||||||||||||||||||||||
const idInformation = "information"; | ||||||||||||||||||||||||||||||||||||||||||
const idInformation2 = "information2"; | ||||||||||||||||||||||||||||||||||||||||||
const idBegin = "begin-box"; | ||||||||||||||||||||||||||||||||||||||||||
const idSpinner = "spinner"; | ||||||||||||||||||||||||||||||||||||||||||
const obscuroGatewayVersion = "v1"; | ||||||||||||||||||||||||||||||||||||||||||
const pathJoin = obscuroGatewayVersion + "/join/"; | ||||||||||||||||||||||||||||||||||||||||||
const pathAuthenticate = obscuroGatewayVersion + "/authenticate/"; | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -51,7 +55,6 @@ async function fetchAndDisplayVersion() { | |||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
function getNetworkName(gatewayAddress) { | ||||||||||||||||||||||||||||||||||||||||||
switch(gatewayAddress) { | ||||||||||||||||||||||||||||||||||||||||||
case 'https://uat-testnet.obscu.ro': | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -63,7 +66,6 @@ function getNetworkName(gatewayAddress) { | |||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
function getRPCFromUrl(gatewayAddress) { | ||||||||||||||||||||||||||||||||||||||||||
// get the correct RPC endpoint for each network | ||||||||||||||||||||||||||||||||||||||||||
switch(gatewayAddress) { | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -271,22 +273,35 @@ const initialize = async () => { | |||||||||||||||||||||||||||||||||||||||||
const joinButton = document.getElementById(idJoin); | ||||||||||||||||||||||||||||||||||||||||||
const revokeUserIDButton = document.getElementById(idRevokeUserID); | ||||||||||||||||||||||||||||||||||||||||||
const statusArea = document.getElementById(idStatus); | ||||||||||||||||||||||||||||||||||||||||||
const informationArea = document.getElementById(idInformation); | ||||||||||||||||||||||||||||||||||||||||||
const informationArea2 = document.getElementById(idInformation2); | ||||||||||||||||||||||||||||||||||||||||||
const beginBox = document.getElementById(idBegin); | ||||||||||||||||||||||||||||||||||||||||||
const spinner = document.getElementById(idSpinner); | ||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+276
to
+279
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When accessing DOM elements using
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
const accountsTable = document.getElementById(idAccountsTable) | ||||||||||||||||||||||||||||||||||||||||||
const tableBody = document.getElementById(idTableBody); | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
// getUserID from the gateway with getStorageAt method | ||||||||||||||||||||||||||||||||||||||||||
let userID = await getUserID() | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
function displayOnlyJoin() { | ||||||||||||||||||||||||||||||||||||||||||
joinButton.style.display = "block" | ||||||||||||||||||||||||||||||||||||||||||
revokeUserIDButton.style.display = "none" | ||||||||||||||||||||||||||||||||||||||||||
accountsTable.style.display = "none" | ||||||||||||||||||||||||||||||||||||||||||
informationArea.style.display = "block" | ||||||||||||||||||||||||||||||||||||||||||
informationArea2.style.display = "none" | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
beginBox.style.visibility = "visible"; | ||||||||||||||||||||||||||||||||||||||||||
spinner.style.visibility = "hidden"; | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
async function displayConnectedAndJoinedSuccessfully() { | ||||||||||||||||||||||||||||||||||||||||||
joinButton.style.display = "none" | ||||||||||||||||||||||||||||||||||||||||||
informationArea.style.display = "none" | ||||||||||||||||||||||||||||||||||||||||||
informationArea2.style.display = "block" | ||||||||||||||||||||||||||||||||||||||||||
revokeUserIDButton.style.display = "block" | ||||||||||||||||||||||||||||||||||||||||||
accountsTable.style.display = "block" | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
await populateAccountsTable(document, tableBody, userID) | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
|
@@ -307,11 +322,13 @@ const initialize = async () => { | |||||||||||||||||||||||||||||||||||||||||
await displayCorrectScreenBasedOnMetamaskAndUserID() | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
joinButton.addEventListener(eventClick, async () => { | ||||||||||||||||||||||||||||||||||||||||||
// clean up any previous errors | ||||||||||||||||||||||||||||||||||||||||||
statusArea.innerText = "" | ||||||||||||||||||||||||||||||||||||||||||
// check if we are on an obscuro chain | ||||||||||||||||||||||||||||||||||||||||||
if (await isObscuroChain()) { | ||||||||||||||||||||||||||||||||||||||||||
userID = await getUserID() | ||||||||||||||||||||||||||||||||||||||||||
if (!isValidUserIDFormat(userID)) { | ||||||||||||||||||||||||||||||||||||||||||
statusArea.innerText = "Please remove existing Obscuro network from metamask and start again." | ||||||||||||||||||||||||||||||||||||||||||
statusArea.innerText = "Existing Obscuro network detected in MetaMask. Please remove before hitting begin" | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||
// we are not on an Obscuro network - try to switch | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -349,11 +366,15 @@ const initialize = async () => { | |||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
userID = await getUserID(); | ||||||||||||||||||||||||||||||||||||||||||
beginBox.style.visibility = "hidden"; | ||||||||||||||||||||||||||||||||||||||||||
spinner.style.visibility = "visible"; | ||||||||||||||||||||||||||||||||||||||||||
for (const account of accounts) { | ||||||||||||||||||||||||||||||||||||||||||
await authenticateAccountWithObscuroGateway(ethereum, account, userID) | ||||||||||||||||||||||||||||||||||||||||||
accountsTable.style.display = "block" | ||||||||||||||||||||||||||||||||||||||||||
await populateAccountsTable(document, tableBody, userID) | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
beginBox.style.visibility = "visible"; | ||||||||||||||||||||||||||||||||||||||||||
spinner.style.visibility = "hidden"; | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
// if accounts change we want to give user chance to add them to Obscuro | ||||||||||||||||||||||||||||||||||||||||||
window.ethereum.on('accountsChanged', async function (accounts) { | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -372,6 +393,8 @@ const initialize = async () => { | |||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
revokeUserIDButton.addEventListener(eventClick, async () => { | ||||||||||||||||||||||||||||||||||||||||||
beginBox.style.visibility = "hidden"; | ||||||||||||||||||||||||||||||||||||||||||
spinner.style.visibility = "visible"; | ||||||||||||||||||||||||||||||||||||||||||
let result = await revokeUserID(userID); | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
await populateAccountsTable(document, tableBody, userID) | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -382,6 +405,8 @@ const initialize = async () => { | |||||||||||||||||||||||||||||||||||||||||
statusArea.innerText = "Revoking UserID failed"; | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||
beginBox.style.visibility = "visible"; | ||||||||||||||||||||||||||||||||||||||||||
spinner.style.visibility = "hidden"; | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
window.addEventListener(eventDomLoaded, checkIfMetamaskIsLoaded); | ||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The naming convention for DOM element IDs and their corresponding JavaScript constants should be consistent to improve code readability and maintainability.