Some checks failed
check / check (push) Failing after 2m16s
script/lint ran `prettier --check .`, byte for byte what script/fmt-check
runs, so make check checked formatting twice and did no static analysis on
a cryptocurrency wallet. Two used-but-not-imported crashes shipped past it.
ESLint is pinned in package.json with @eslint/js recommended as the base and
a flat config in eslint.config.js. no-undef and no-unused-vars are restated
error-level so a future recommended-set change cannot downgrade them.
Globals are declared per tree rather than globally, because a too-wide set
hides the next unimported identifier: browser for the popup and content
scripts, service worker for src/background/ and src/shared/, browser for the
one documented POPUP ONLY module in src/shared/, jest for tests/, node for
build.js, and both for the e2e harnesses, which carry the callbacks they
ship into the page inline.
Two rules new to the recommended set are off, and both would have cost
something to satisfy. no-useless-assignment flags the `password = null` and
`decryptedSecret = null` wipes in approval.js and confirmTx.js: those
assignments are dead by construction, which is the point of them, and the
rule's fix is to delete the wipe. preserve-caught-error would change what
the wallet's error paths throw, which is a decision of its own.
Every remaining violation is fixed: 41 unused bindings and 53 undefined
identifiers. Unused catch bindings became `catch {`, which the repo already
used; the shared init(ctx) view signature keeps its parameter as _ctx in the
three views that do not read it. src/shared/uniswap.js keeps its unused
V2_SWAP_EXACT_OUT decoder behind a scoped disable, because deleting it would
widen the gap it represents rather than close it (#283).
Linting is containerized. script/lint builds the Dockerfile's new lint stage
so the ESLint deciding whether this repo is green is the pinned one and not
whatever the host has; AUTISTMASK_LINT_NATIVE, set only in that image, is
what makes make check inside the CI build lint in place instead of recursing
into docker. The check stage takes a COPY --from=lint dependency so a lint
failure fails the whole build early rather than racing it.
No --fix anywhere in the lint path: make check remains non-mutating.
The README claim that a used-but-not-imported identifier is invisible to
make check, and the same claim in script/test-e2e, are no longer true and
are corrected.
117 lines
3.7 KiB
JavaScript
117 lines
3.7 KiB
JavaScript
const {
|
|
$,
|
|
showView,
|
|
showFlash,
|
|
goBack,
|
|
clearViewStack,
|
|
onViewLeave,
|
|
} = require("./helpers");
|
|
const { state, saveState } = require("../../shared/state");
|
|
const { decryptWithPassword } = require("../../shared/vault");
|
|
const {
|
|
removeWalletFromState,
|
|
broadcastActiveChanged,
|
|
} = require("../../shared/walletDelete");
|
|
|
|
let deleteWalletIndex = null;
|
|
let ctx = null;
|
|
|
|
// Drop the password from the DOM and the wallet selection from the
|
|
// closure. Registered as the view-leave handler as well as run on entry,
|
|
// so the typed password does not sit in the hidden view after the user
|
|
// navigates away by any route, including the Settings gear.
|
|
function clear() {
|
|
deleteWalletIndex = null;
|
|
$("delete-wallet-password").value = "";
|
|
$("delete-wallet-flash").textContent = "";
|
|
$("delete-wallet-flash").style.visibility = "hidden";
|
|
}
|
|
|
|
function show(walletIdx) {
|
|
clear();
|
|
deleteWalletIndex = walletIdx;
|
|
const wallet = state.wallets[walletIdx];
|
|
$("delete-wallet-name").textContent =
|
|
wallet.name || "Wallet " + (walletIdx + 1);
|
|
showView("delete-wallet-confirm");
|
|
}
|
|
|
|
function init(_ctx) {
|
|
ctx = _ctx;
|
|
|
|
onViewLeave("delete-wallet-confirm", clear);
|
|
|
|
// No wipe here: goBack() routes through showView(), which runs the
|
|
// leave hook.
|
|
$("btn-delete-wallet-back").addEventListener("click", () => {
|
|
goBack();
|
|
});
|
|
|
|
$("btn-delete-wallet-confirm").addEventListener("click", async () => {
|
|
const pw = $("delete-wallet-password").value;
|
|
if (!pw) {
|
|
$("delete-wallet-flash").textContent =
|
|
"Please enter your password.";
|
|
$("delete-wallet-flash").style.visibility = "visible";
|
|
return;
|
|
}
|
|
|
|
if (deleteWalletIndex === null) {
|
|
$("delete-wallet-flash").textContent =
|
|
"No wallet selected for deletion.";
|
|
$("delete-wallet-flash").style.visibility = "visible";
|
|
return;
|
|
}
|
|
|
|
const btn = $("btn-delete-wallet-confirm");
|
|
btn.disabled = true;
|
|
btn.classList.add("text-muted");
|
|
|
|
const walletIdx = deleteWalletIndex;
|
|
const wallet = state.wallets[walletIdx];
|
|
|
|
// Verify password against the wallet's encrypted data
|
|
try {
|
|
await decryptWithPassword(wallet.encryptedSecret, pw);
|
|
} catch {
|
|
$("delete-wallet-flash").textContent =
|
|
"That password is incorrect. Please try again.";
|
|
$("delete-wallet-flash").style.visibility = "visible";
|
|
btn.disabled = false;
|
|
btn.classList.remove("text-muted");
|
|
return;
|
|
}
|
|
|
|
// Remove the wallet and repair selection, permissions and hasWallet
|
|
const { activeAddressChanged } = removeWalletFromState(
|
|
state,
|
|
walletIdx,
|
|
);
|
|
|
|
deleteWalletIndex = null;
|
|
|
|
if (!state.hasWallet) {
|
|
clearViewStack();
|
|
await saveState();
|
|
// Save before broadcasting: the background reads the active
|
|
// address back out of storage to build accountsChanged.
|
|
if (activeAddressChanged) broadcastActiveChanged();
|
|
showView("welcome");
|
|
} else {
|
|
await saveState();
|
|
if (activeAddressChanged) broadcastActiveChanged();
|
|
// Reset stack to [main] so Settings back goes home.
|
|
// Use require() lazily to avoid circular dependency
|
|
// (settings.js requires deleteWallet.js).
|
|
clearViewStack();
|
|
state.viewStack.push("main");
|
|
ctx.renderWalletList();
|
|
const settings = require("./settings");
|
|
settings.show();
|
|
showFlash("Wallet deleted.");
|
|
}
|
|
});
|
|
}
|
|
|
|
module.exports = { init, show };
|