chore: eliminate all ESLint warnings, enforce --max-warnings 0

Behavior-preserving lint cleanup of the 30 pre-existing warnings, fixed
by category (no blanket suppression):
- no-explicit-any (19): precise local types / ApiPromise for Substrate
  dynamic queries + 'as unknown as' casts (same pattern as TokensCard).
- no-console (4): dev-gated (import.meta.env.DEV) / warn; main.tsx prod
  console-suppression kept with a scoped documented disable.
- no-non-null-assertion (4): replaced '!' with explicit guards reusing
  the existing fallback/return paths.
- react-hooks/exhaustive-deps (3): missing dep is 't' (i18n) — adding it
  would re-fire blockchain fetches on language change; kept deps with a
  documented intentional disable.

Tighten the lint gate from --max-warnings 30 to 0 so no new warnings can
land. Verified: tsc 0 errors, eslint --max-warnings 0 clean, vite build ok.
This commit is contained in:
2026-06-14 09:21:12 -07:00
parent 97e5723aa5
commit 2017ae77da
11 changed files with 199 additions and 93 deletions
+59 -21
View File
@@ -74,10 +74,25 @@ export function SwapModal({ isOpen, onClose }: SwapModalProps) {
const hezFree = hezAccount.data.free.toString();
const hezBalance = (parseInt(hezFree) / 1e12).toFixed(4);
// Helper to extract balance from asset query result
const getAssetBalance = (result: any, decimals: number, fractionDigits: number): string => {
// Helper to extract balance from an asset storage query result. The
// shape is the subset of the @pezkuwi/api Option/Codec result we read.
type AssetQueryResult = {
isEmpty: boolean;
isSome?: boolean;
unwrap?: () => { toJSON(): unknown };
toJSON(): unknown;
};
const getAssetBalance = (
result: AssetQueryResult | null,
decimals: number,
fractionDigits: number
): string => {
if (!result || result.isEmpty) return '0'.padEnd(fractionDigits + 2, '0');
const data = result.isSome ? result.unwrap().toJSON() : result.toJSON();
const data = (
result.isSome && result.unwrap ? result.unwrap().toJSON() : result.toJSON()
) as {
balance?: { toString(): string };
} | null;
if (data && data.balance) {
return (parseInt(data.balance.toString()) / Math.pow(10, decimals)).toFixed(
fractionDigits
@@ -155,8 +170,21 @@ export function SwapModal({ isOpen, onClose }: SwapModalProps) {
const decimals2 = getDecimals(asset2);
const oneUnit = BigInt(Math.pow(10, decimals1));
// assetConversionApi is a runtime API not present in the base
// @pezkuwi/api typings; describe just the call we use.
type QuoteResult = { isNone: boolean; unwrap(): { toString(): string } };
type AssetConversionCall = {
assetConversionApi: {
quotePriceExactTokensForTokens: (
asset1: ReturnType<typeof formatAssetLocation>,
asset2: ReturnType<typeof formatAssetLocation>,
amount: string,
includeFee: boolean
) => Promise<QuoteResult>;
};
};
const quote = await (
assetHubApi.call as any
assetHubApi.call as unknown as AssetConversionCall
).assetConversionApi.quotePriceExactTokensForTokens(
formatAssetLocation(asset1),
formatAssetLocation(asset2),
@@ -257,28 +285,38 @@ export function SwapModal({ isOpen, onClose }: SwapModalProps) {
true
);
// Minimal shape of the signAndSend result fields we read (the full
// @pezkuwi/api ISubmittableResult is unavailable because `tx` above is
// produced from an untyped runtime extrinsic).
type SwapDispatchError = {
isModule: boolean;
asModule: Parameters<typeof assetHubApi.registry.findMetaError>[0];
toString(): string;
};
type SwapTxResult = {
status: { isFinalized: boolean };
dispatchError?: SwapDispatchError;
};
// Wait for transaction to be finalized
await new Promise<void>((resolve, reject) => {
tx.signAndSend(
keypair,
({ status, dispatchError }: { status: any; dispatchError: any }) => {
if (status.isFinalized) {
if (dispatchError) {
let errorMsg = t('swap.swapFailed');
if (dispatchError.isModule) {
const decoded = assetHubApi.registry.findMetaError(dispatchError.asModule);
errorMsg = `${decoded.section}.${decoded.name}: ${decoded.docs.join(' ')}`;
} else if (dispatchError.toString) {
errorMsg = dispatchError.toString();
}
console.error('Swap error:', errorMsg);
reject(new Error(errorMsg));
} else {
resolve();
tx.signAndSend(keypair, ({ status, dispatchError }: SwapTxResult) => {
if (status.isFinalized) {
if (dispatchError) {
let errorMsg = t('swap.swapFailed');
if (dispatchError.isModule) {
const decoded = assetHubApi.registry.findMetaError(dispatchError.asModule);
errorMsg = `${decoded.section}.${decoded.name}: ${decoded.docs.join(' ')}`;
} else if (dispatchError.toString) {
errorMsg = dispatchError.toString();
}
console.error('Swap error:', errorMsg);
reject(new Error(errorMsg));
} else {
resolve();
}
}
).catch(reject);
}).catch(reject);
});
setSuccess(true);