Skip to content

Commit

Permalink
feat: better naming
Browse files Browse the repository at this point in the history
  • Loading branch information
zugdev committed Dec 21, 2024
1 parent b5c844a commit f801b95
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions static/handle-approval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function isValidAmount(): boolean {
return isValid;
}

export function isApprovalValid() {
export function isApprovalButtonsValid() {
const isConnected = appState.getIsConnectedState();
const isAddressValid = isValidAddress();
const isAmountValid = isValidAmount();
Expand Down Expand Up @@ -107,7 +107,7 @@ async function onApproveClick() {
renderErrorInModal(error as Error);
} finally {
approveButton.textContent = originalText;
isApprovalValid(); // re-check the state to restore buttons correctly
isApprovalButtonsValid(); // re-check the state to restore buttons correctly
}
}

Expand Down Expand Up @@ -141,11 +141,11 @@ async function onRevokeClick() {
renderErrorInModal(error as Error);
} finally {
revokeButton.textContent = originalText;
isApprovalValid(); // re-check state to restore buttons correctly
isApprovalButtonsValid(); // re-check state to restore buttons correctly
}
}

export function setupValidityListener() {
amountInput.addEventListener("change", isApprovalValid);
addressInput.addEventListener("change", isApprovalValid);
export function setupButtonValidityListener() {
amountInput.addEventListener("change", isApprovalButtonsValid);
addressInput.addEventListener("change", isApprovalButtonsValid);
}
16 changes: 8 additions & 8 deletions static/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Ethers5Adapter } from "@reown/appkit-adapter-ethers5";
import { anvil, gnosis, mainnet, polygon, optimism, arbitrum, base, bsc, blast, zksync, avalanche, worldchain, AppKitNetwork } from "@reown/appkit/networks";
import { ethers } from "ethers";
import { renderErrorInModal } from "./display-popup-modal";
import { updateTokens } from "./populate-dropdown";
import { isApprovalValid, setupApproveButton, setupRevokeButton, setupValidityListener } from "./handle-approval";
import { updateTokenDropdown } from "./populate-dropdown";
import { isApprovalButtonsValid, setupApproveButton, setupRevokeButton, setupButtonValidityListener } from "./handle-approval";

// all unhandled errors are caught and displayed in a modal
window.addEventListener("error", (event: ErrorEvent) => renderErrorInModal(event.error));
Expand Down Expand Up @@ -90,8 +90,8 @@ async function initializeProviderAndSigner() {
}

// update UI elements that depend on connection state
isApprovalValid();
updateTokens();
isApprovalButtonsValid();
updateTokenDropdown();
}

function handleNetworkSwitch() {
Expand All @@ -111,10 +111,10 @@ function handleNetworkSwitch() {

export async function mainModule() {
try {
setupValidityListener(); // setup amount and token validity listeners
updateTokens(); // update known tokens on the dropdown
setupApproveButton(); // setup approve button
setupRevokeButton(); // setup revoke button
setupButtonValidityListener();
updateTokenDropdown();
setupApproveButton();
setupRevokeButton();
handleNetworkSwitch();

// initialize for the first time
Expand Down
2 changes: 1 addition & 1 deletion static/populate-dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const tokensByNetwork: { [key: number]: { [token: string]: string } } = {
const tokenSelector = document.querySelector(".token-selector") as HTMLInputElement;
const tokenOptions = document.querySelector("#token-options") as HTMLSelectElement;

export function updateTokens() {
export function updateTokenDropdown() {
const networkId = Number(appState.getChainId());

let tokens = {};
Expand Down

0 comments on commit f801b95

Please sign in to comment.