Skip to content

Commit

Permalink
eslint rule curly all (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
turbocrime committed Jul 10, 2024
1 parent e8f4891 commit 32ac0c1
Show file tree
Hide file tree
Showing 62 changed files with 364 additions and 126 deletions.
5 changes: 5 additions & 0 deletions .changeset/eight-ducks-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@repo/eslint-config': minor
---

add rule curly all
3 changes: 2 additions & 1 deletion apps/extension/src/approve-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ export const approveTransaction = async (
if (popupResponse) {
const resAuthorizeRequest = AuthorizeRequest.fromJson(popupResponse.authorizeRequest);

if (!authorizeRequest.equals(resAuthorizeRequest))
if (!authorizeRequest.equals(resAuthorizeRequest)) {
throw new Error('Invalid response from popup');
}
}

return popupResponse?.choice;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ const handleRequest = (ev: MessageEvent<unknown>) => {
PraxConnection,
undefined | PenumbraRequestFailure
>(PraxConnection.Request);
if (failure)
if (failure) {
window.postMessage({ [PRAX]: failure } satisfies PraxMessage<PenumbraRequestFailure>, '/');
}
})();
}
};
Expand Down
4 changes: 3 additions & 1 deletion apps/extension/src/ctx/full-viewing-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { localExtStorage } from '../storage/local';

export const getFullViewingKey = async () => {
const wallet0 = (await localExtStorage.get('wallets'))[0];
if (!wallet0) throw new ConnectError('No wallet available', Code.FailedPrecondition);
if (!wallet0) {
throw new ConnectError('No wallet available', Code.FailedPrecondition);
}

return FullViewingKey.fromJsonString(wallet0.fullViewingKey);
};
12 changes: 9 additions & 3 deletions apps/extension/src/ctx/spend-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@ import { generateSpendKey } from '@penumbra-zone/wasm/keys';

export const getSpendKey = async () => {
const passKeyJson = await sessionExtStorage.get('passwordKey');
if (!passKeyJson) throw new ConnectError('User must login', Code.Unauthenticated);
if (!passKeyJson) {
throw new ConnectError('User must login', Code.Unauthenticated);
}
const passKey = await Key.fromJson(passKeyJson);

const wallet0 = (await localExtStorage.get('wallets'))[0];
if (!wallet0) throw new ConnectError('No wallet found');
if (!wallet0) {
throw new ConnectError('No wallet found');
}

const seedBox = Box.fromJson(wallet0.custody.encryptedSeedPhrase);
const seedPhrase = await passKey.unseal(seedBox);
if (!seedPhrase) throw new ConnectError('Unable to decrypt seed phrase', Code.Unauthenticated);
if (!seedPhrase) {
throw new ConnectError('Unable to decrypt seed phrase', Code.Unauthenticated);
}

return generateSpendKey(seedPhrase);
};
4 changes: 3 additions & 1 deletion apps/extension/src/ctx/wallet-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { localExtStorage } from '../storage/local';

export const getWalletId = async () => {
const wallet0 = (await localExtStorage.get('wallets'))[0];
if (!wallet0) throw new ConnectError('No wallet available', Code.FailedPrecondition);
if (!wallet0) {
throw new ConnectError('No wallet available', Code.FailedPrecondition);
}

return WalletId.fromJsonString(wallet0.id);
};
4 changes: 3 additions & 1 deletion apps/extension/src/entry/offscreen-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {
} from '@penumbra-zone/types/internal-msg/offscreen';

chrome.runtime.onMessage.addListener((req, _sender, respond) => {
if (!isOffscreenRequest(req)) return false;
if (!isOffscreenRequest(req)) {
return false;
}
const { type, request } = req;
if (isActionBuildRequest(request)) {
void (async () => {
Expand Down
4 changes: 3 additions & 1 deletion apps/extension/src/hooks/chain-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { viewClient } from '../clients';

const getChainIdViaViewService = async (): Promise<string> => {
const { parameters } = await viewClient.appParameters({});
if (!parameters?.chainId) throw new Error('No chainId in response');
if (!parameters?.chainId) {
throw new Error('No chainId in response');
}

return parameters.chainId;
};
Expand Down
12 changes: 9 additions & 3 deletions apps/extension/src/hooks/full-sync-height.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ import { createPromiseClient } from '@connectrpc/connect';

const tryGetMax = (a?: number, b?: number): number | undefined => {
// Height can be 0n which is falsy, so should compare to undefined state
if (a === undefined) return b;
if (b === undefined) return a;
if (a === undefined) {
return b;
}
if (b === undefined) {
return a;
}

return Math.max(a, b);
};
Expand All @@ -31,7 +35,9 @@ export const useSyncProgress = () => {
const { data: queriedLatest, error } = useQuery({
queryKey: ['latestBlockHeight'],
queryFn: async () => {
if (!grpcEndpoint) return;
if (!grpcEndpoint) {
return;
}
const tendermintClient = createPromiseClient(
TendermintProxyService,
createGrpcWebTransport({ baseUrl: grpcEndpoint }),
Expand Down
4 changes: 3 additions & 1 deletion apps/extension/src/hooks/validation-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ export const useValidationResult = (
value: string,
validations?: Validation[],
): undefined | Validation => {
if (!validations) return;
if (!validations) {
return;
}
const results = validations.filter(v => v.checkFn(value));
const error = results.find(v => v.type === 'error');
return error ? error : results.find(v => v.type === 'warn');
Expand Down
3 changes: 2 additions & 1 deletion apps/extension/src/listeners/message-prax-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ chrome.runtime.onMessage.addListener(

void (async () => {
const alreadyApproved = await alreadyApprovedSender(validSender);
if (alreadyApproved)
if (alreadyApproved) {
void chrome.tabs.sendMessage(validSender.tab.id, PraxConnection.Init, {
// init only the specific document
frameId: validSender.frameId,
documentId: validSender.documentId,
});
}
})();

// handler is done
Expand Down
11 changes: 8 additions & 3 deletions apps/extension/src/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ export const popup = async <M extends PopupMessage>(
const response = await chrome.runtime
.sendMessage<InternalRequest<M>, InternalResponse<M>>(req)
.catch((e: unknown) => {
if (isChromeResponderDroppedError(e)) return null;
else throw e;
if (isChromeResponderDroppedError(e)) {
return null;
} else {
throw e;
}
});
if (response && 'error' in response) {
throw errorFromJson(response.error, undefined, ConnectError.from(response));
Expand Down Expand Up @@ -58,7 +61,9 @@ const throwIfAlreadyOpen = (path: string) =>
],
})
.then(popupContexts => {
if (popupContexts.length) throw Error('Popup already open');
if (popupContexts.length) {
throw Error('Popup already open');
}
});

const throwIfNeedsLogin = async () => {
Expand Down
12 changes: 9 additions & 3 deletions apps/extension/src/routes/page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ export const pageIndexLoader = async () => {
const grpcEndpoint = await localExtStorage.get('grpcEndpoint');
const frontendUrl = await localExtStorage.get('frontendUrl');

if (!wallets.length) return redirect(PagePath.WELCOME);
if (!grpcEndpoint) return redirect(PagePath.SET_GRPC_ENDPOINT);
if (!frontendUrl) return redirect(PagePath.SET_DEFAULT_FRONTEND);
if (!wallets.length) {
return redirect(PagePath.WELCOME);
}
if (!grpcEndpoint) {
return redirect(PagePath.SET_GRPC_ENDPOINT);
}
if (!frontendUrl) {
return redirect(PagePath.SET_DEFAULT_FRONTEND);
}

return null;
};
Expand Down
4 changes: 3 additions & 1 deletion apps/extension/src/routes/popup/approval/origin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export const OriginApproval = () => {
window.close();
};

if (!requestOrigin) return null;
if (!requestOrigin) {
return null;
}

return (
<FadeTransition>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ export const TransactionApproval = () => {
const { selectedTransactionView, selectedTransactionViewName, setSelectedTransactionViewName } =
useTransactionViewSwitcher();

if (!authReqString) return null;
if (!authReqString) {
return null;
}
const authorizeRequest = AuthorizeRequest.fromJsonString(authReqString);
if (!authorizeRequest.plan || !selectedTransactionView) return null;
if (!authorizeRequest.plan || !selectedTransactionView) {
return null;
}

const approve = () => {
setChoice(UserChoice.Approved);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export const useTransactionViewSwitcher = (): {
useState<TransactionViewTab>(TransactionViewTab.SENDER);

const deserializedTransactionViews = useMemo(() => {
if (!asSender || !asReceiver || !asPublic) return {};
if (!asSender || !asReceiver || !asPublic) {
return {};
}

return {
asSender: TransactionView.fromJsonString(asSender),
Expand Down
4 changes: 3 additions & 1 deletion apps/extension/src/routes/popup/home/frontend-link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export const FrontendLink = () => {

// In case the frontendUrl is not set, prevent the link action, and open the settings page instead
const onClick: MouseEventHandler = event => {
if (frontendUrl) return;
if (frontendUrl) {
return;
}
event.stopPropagation();
navigate(PopupPath.SETTINGS_DEFAULT_FRONTEND);
};
Expand Down
8 changes: 6 additions & 2 deletions apps/extension/src/routes/popup/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export interface PopupLoaderData {
export const popupIndexLoader = async (): Promise<Response | PopupLoaderData> => {
await needsOnboard();
const redirect = await needsLogin();
if (redirect) return redirect;
if (redirect) {
return redirect;
}

return {
fullSyncHeight: await localExtStorage.get('fullSyncHeight'),
Expand All @@ -34,7 +36,9 @@ export const popupIndexLoader = async (): Promise<Response | PopupLoaderData> =>
const getAddrByIndex =
(wallet?: Wallet) =>
(index: number, ephemeral: boolean): Address => {
if (!wallet) throw new Error('No active wallet');
if (!wallet) {
throw new Error('No active wallet');
}

const fullViewingKey = FullViewingKey.fromJsonString(wallet.fullViewingKey);
return ephemeral
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ import { Address } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/k
export const getAddressOwnershipInfoFromBech32mAddress = async (
bech32mAddress: string,
): Promise<AddressOwnershipInfo | undefined> => {
if (!bech32mAddress) return undefined;
if (!bech32mAddress) {
return undefined;
}

try {
const { addressIndex } = await viewClient.indexByAddress({
address: new Address({ altBech32m: bech32mAddress }),
});

if (!addressIndex) return { isValidAddress: true, belongsToWallet: false };
if (!addressIndex) {
return { isValidAddress: true, belongsToWallet: false };
}

return {
addressIndexAccount: addressIndex.account,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export const Result = ({
}: {
addressOwnershipInfo?: AddressOwnershipInfo;
}) => {
if (!addressOwnershipInfo) return null;
if (!addressOwnershipInfo) {
return null;
}

if (!addressOwnershipInfo.isValidAddress) {
return (
Expand Down
8 changes: 6 additions & 2 deletions apps/extension/src/routes/popup/popup-needs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { sessionExtStorage } from '../../storage/session';

export const needsLogin = async (): Promise<Response | null> => {
const password = await sessionExtStorage.get('passwordKey');
if (password) return null;
if (password) {
return null;
}

return redirect(PopupPath.LOGIN);
};
Expand All @@ -15,7 +17,9 @@ export const needsOnboard = async () => {
const grpcEndpoint = await localExtStorage.get('grpcEndpoint');
const frontendUrl = await localExtStorage.get('frontendUrl');

if (wallets.length && grpcEndpoint !== undefined && frontendUrl !== undefined) return null;
if (wallets.length && grpcEndpoint !== undefined && frontendUrl !== undefined) {
return null;
}

void chrome.runtime.openOptionsPage();
window.close();
Expand Down
4 changes: 3 additions & 1 deletion apps/extension/src/routes/popup/settings/settings-rpc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export const SettingsRPC = () => {
const { promise, resolve } = Promise.withResolvers<void>();
setCountdownTime(seconds);
setInterval(() => {
if (!seconds) resolve(undefined);
if (!seconds) {
resolve(undefined);
}
setCountdownTime(--seconds);
}, 1000);
return promise;
Expand Down
15 changes: 11 additions & 4 deletions apps/extension/src/rpc/rethrow-impl-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@ const wrapUnaryImpl =
(req: AnyMessage, ctx: HandlerContext) => {
try {
const result = methodImplementation(req, ctx);
if (result instanceof Promise)
if (result instanceof Promise) {
return result.catch((e: unknown) => {
if (globalThis.__DEV__) console.debug(ctx.method.name, req, e);
if (globalThis.__DEV__) {
console.debug(ctx.method.name, req, e);
}
throw ConnectError.from(e);
});
}
return result;
} catch (e) {
if (globalThis.__DEV__) console.debug(ctx.method.name, req, e);
if (globalThis.__DEV__) {
console.debug(ctx.method.name, req, e);
}
throw ConnectError.from(e);
}
};
Expand All @@ -31,7 +36,9 @@ const wrapServerStreamingImpl = (
yield result;
}
} catch (e) {
if (globalThis.__DEV__) console.debug(ctx.method.name, req, e);
if (globalThis.__DEV__) {
console.debug(ctx.method.name, req, e);
}
throw ConnectError.from(e);
}
};
Expand Down
8 changes: 6 additions & 2 deletions apps/extension/src/rpc/tendermint-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ export const makeTendermintProxyZeroNanos = (
): Pick<ServiceImpl<typeof TendermintProxyService>, 'getBlockByHeight'> => ({
getBlockByHeight: async req => {
const r = await c.getBlockByHeight(req);
if (r.block?.header?.time?.nanos) r.block.header.time.nanos = 0;
if (r.block?.lastCommit?.signatures.length) r.block.lastCommit.signatures = [];
if (r.block?.header?.time?.nanos) {
r.block.header.time.nanos = 0;
}
if (r.block?.lastCommit?.signatures.length) {
r.block.lastCommit.signatures = [];
}
return r;
},
});
7 changes: 5 additions & 2 deletions apps/extension/src/senders/disconnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import { removeOriginRecord } from '../storage/origin';

export const disconnectSender = (disconnect: { origin: string }) =>
void alreadyApprovedSender(disconnect).then(hasApproval => {
if (!hasApproval) throw new Error('Sender does not possess approval');
else void removeOriginRecord(disconnect.origin);
if (!hasApproval) {
throw new Error('Sender does not possess approval');
} else {
void removeOriginRecord(disconnect.origin);
}
});
Loading

0 comments on commit 32ac0c1

Please sign in to comment.