Skip to content

Commit

Permalink
chore: format code (#291)
Browse files Browse the repository at this point in the history
chore: format code

---
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with
[ReviewStack](https://reviewstack.dev/solana-labs/explorer/pull/291).
* #292
* __->__ #291
  • Loading branch information
steveluscher authored Sep 15, 2023
1 parent d94063a commit 73e4e20
Show file tree
Hide file tree
Showing 18 changed files with 555 additions and 564 deletions.
2 changes: 1 addition & 1 deletion app/@analytics/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ export default function Analytics() {
</Script>
</>
);
}
}
11 changes: 6 additions & 5 deletions app/components/LiveTransactionStatsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -443,13 +443,14 @@ function PingBarChart({
<div class="value">${val.mean} ms</div>
<div class="label">
<p class="mb-0">${val.confirmed} of ${val.submitted} confirmed</p>
${val.loss
${
val.loss
? `<p class="mb-0">${val.loss.toLocaleString(undefined, {
minimumFractionDigits: 2,
style: 'percent',
})} loss</p>`
minimumFractionDigits: 2,
style: 'percent',
})} loss</p>`
: ''
}
}
${SERIES_INFO[series].label(seriesLength - i)}min ago
</div>
`;
Expand Down
18 changes: 10 additions & 8 deletions app/components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export function SearchBar() {
const localOptions = buildOptions(search, cluster, clusterInfo?.epochInfo.epoch);
const tokenOptions = await buildTokenOptions(search, cluster);
const tokenOptionsAppendable = tokenOptions ? [tokenOptions] : [];
const domainOptions = hasDomainSyntax(search) && cluster === Cluster.MainnetBeta ?
await buildDomainOptions(search) ?? [] : [];
const domainOptions =
hasDomainSyntax(search) && cluster === Cluster.MainnetBeta ? (await buildDomainOptions(search)) ?? [] : [];

return [...localOptions, ...tokenOptionsAppendable, ...domainOptions];
}
Expand Down Expand Up @@ -85,7 +85,9 @@ export function SearchBar() {
components={{ DropdownIndicator }}
classNamePrefix="search-bar"
/* workaround for https://github.com/JedWatson/react-select/issues/5714 */
onFocus={() => { selectRef.current?.handleInputChange(search, { action: 'set-value' }) }}
onFocus={() => {
selectRef.current?.handleInputChange(search, { action: 'set-value' });
}}
/>
</div>
</div>
Expand Down Expand Up @@ -173,17 +175,16 @@ async function buildTokenOptions(search: string, cluster: Cluster): Promise<Sear
if (matchedTokens.length > 0) {
return {
label: 'Tokens',
options: matchedTokens
options: matchedTokens,
};
}
}

async function buildDomainOptions(search: string) {
const domainInfoResponse = await fetch(`/api/domain-info/${search}`);
const domainInfo = await domainInfoResponse.json() as FetchedDomainInfo;
const domainInfo = (await domainInfoResponse.json()) as FetchedDomainInfo;

if (domainInfo && domainInfo.owner && domainInfo.address) {

return [
{
label: 'Domain Owner',
Expand All @@ -204,7 +205,8 @@ async function buildDomainOptions(search: string) {
value: [search],
},
],
}];
},
];
}
}

Expand Down Expand Up @@ -248,7 +250,7 @@ function buildOptions(rawSearch: string, cluster: Cluster, currentEpoch?: bigint
});

// Parse as BigInt but not if it starts eg 0x or 0b
if (currentEpoch !== undefined && !(/^0\w/.test(search)) && BigInt(search) <= currentEpoch + 1n) {
if (currentEpoch !== undefined && !/^0\w/.test(search) && BigInt(search) <= currentEpoch + 1n) {
options.push({
label: 'Epoch',
options: [
Expand Down
4 changes: 2 additions & 2 deletions app/providers/cluster.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ async function updateCluster(dispatch: Dispatch, cluster: Cluster, customUrl: st
new URL(customUrl);

const transportUrl = clusterUrl(cluster, customUrl);
const transport = createDefaultRpcTransport({ url: transportUrl })
const rpc = createSolanaRpc({ transport })
const transport = createDefaultRpcTransport({ url: transportUrl });
const rpc = createSolanaRpc({ transport });

const [firstAvailableBlock, epochSchedule, epochInfo] = await Promise.all([
rpc.getFirstAvailableBlock().send(),
Expand Down
10 changes: 6 additions & 4 deletions app/providers/supply.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export enum Status {
type Lamports = bigint;

type Supply = Readonly<{
circulating: Lamports,
nonCirculating: Lamports,
total: Lamports,
circulating: Lamports;
nonCirculating: Lamports;
total: Lamports;
}>;

type State = Supply | Status | string;
Expand Down Expand Up @@ -52,7 +52,9 @@ async function fetch(dispatch: Dispatch, cluster: Cluster, url: string) {
const transport = createDefaultRpcTransport({ url });
const rpc = createSolanaRpc({ transport });

const supplyResponse = await rpc.getSupply({ commitment: 'finalized', excludeNonCirculatingAccountsList: true }).send();
const supplyResponse = await rpc
.getSupply({ commitment: 'finalized', excludeNonCirculatingAccountsList: true })
.send();
const supply: Supply = {
circulating: supplyResponse.value.circulating,
nonCirculating: supplyResponse.value.nonCirculating,
Expand Down
12 changes: 5 additions & 7 deletions app/supply/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import { SupplyProvider } from '@providers/supply';
import { PropsWithChildren } from 'react';

export default function SupplyLayout({ children }: PropsWithChildren<Record<string, never>>) {
return (
<SupplyProvider>
<RichListProvider>
{children}
</RichListProvider>
</SupplyProvider>
);
return (
<SupplyProvider>
<RichListProvider>{children}</RichListProvider>
</SupplyProvider>
);
}
12 changes: 5 additions & 7 deletions app/tx/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import { PropsWithChildren } from 'react';
import { AccountsProvider } from '../providers/accounts';

export default function TxLayout({ children }: PropsWithChildren<Record<string, never>>) {
return (
<TransactionsProvider>
<AccountsProvider>
{children}
</AccountsProvider>
</TransactionsProvider>
);
return (
<TransactionsProvider>
<AccountsProvider>{children}</AccountsProvider>
</TransactionsProvider>
);
}
10 changes: 5 additions & 5 deletions app/utils/domain-info.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getHashedName, getNameAccountKey, getNameOwner } from "@bonfida/spl-name-service";
import { Connection, PublicKey } from "@solana/web3.js";
import { getHashedName, getNameAccountKey, getNameOwner } from '@bonfida/spl-name-service';
import { Connection, PublicKey } from '@solana/web3.js';

// Address of the SOL TLD
export const SOL_TLD_AUTHORITY = new PublicKey('58PwtjSDuFHuUkYjH9BYnnQKHfwo9reZhC2zMJv9JPkx');
Expand Down Expand Up @@ -30,9 +30,9 @@ export async function getDomainInfo(domain: string, connection: Connection) {
const registry = await getNameOwner(connection, domainKey);
return registry && registry.registry.owner
? {
address: domainKey.toString(),
owner: registry.registry.owner.toString(),
}
address: domainKey.toString(),
owner: registry.registry.owner.toString(),
}
: null;
} catch {
return null;
Expand Down
42 changes: 15 additions & 27 deletions app/utils/epoch-schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ const MINIMUM_SLOT_PER_EPOCH = BigInt(32);

export interface EpochSchedule {
/** The maximum number of slots in each epoch */
slotsPerEpoch: bigint,
slotsPerEpoch: bigint;
/** The first epoch with `slotsPerEpoch` slots */
firstNormalEpoch: bigint,
firstNormalEpoch: bigint;
/** The first slot of `firstNormalEpoch` */
firstNormalSlot: bigint
firstNormalSlot: bigint;
}

// Returns the number of trailing zeros in the binary representation of n
Expand All @@ -23,13 +23,13 @@ function trailingZeros(n: bigint): number {
function nextPowerOfTwo(n: bigint): bigint {
if (n === 0n) return 1n;
n--;
n |= n >> 1n
n |= n >> 2n
n |= n >> 4n
n |= n >> 8n
n |= n >> 16n
n |= n >> 32n
return n + 1n
n |= n >> 1n;
n |= n >> 2n;
n |= n >> 4n;
n |= n >> 8n;
n |= n >> 16n;
n |= n >> 32n;
return n + 1n;
}

/**
Expand All @@ -38,10 +38,7 @@ function nextPowerOfTwo(n: bigint): bigint {
* @param slot The slot to get the epoch number for
* @returns The epoch number that contains or will contain the given slot
*/
export function getEpochForSlot(
epochSchedule: EpochSchedule,
slot: bigint,
): bigint {
export function getEpochForSlot(epochSchedule: EpochSchedule, slot: bigint): bigint {
if (slot < epochSchedule.firstNormalSlot) {
const epoch =
trailingZeros(nextPowerOfTwo(slot + MINIMUM_SLOT_PER_EPOCH + BigInt(1))) -
Expand All @@ -63,17 +60,11 @@ export function getEpochForSlot(
* @param epoch Epoch to get the first slot for
* @returns First slot in the epoch
*/
export function getFirstSlotInEpoch(
epochSchedule: EpochSchedule,
epoch: bigint
): bigint {
export function getFirstSlotInEpoch(epochSchedule: EpochSchedule, epoch: bigint): bigint {
if (epoch <= epochSchedule.firstNormalEpoch) {
return ((2n ** epoch) - 1n) * MINIMUM_SLOT_PER_EPOCH;
return (2n ** epoch - 1n) * MINIMUM_SLOT_PER_EPOCH;
} else {
return (
(epoch - epochSchedule.firstNormalEpoch) * epochSchedule.slotsPerEpoch +
epochSchedule.firstNormalSlot
);
return (epoch - epochSchedule.firstNormalEpoch) * epochSchedule.slotsPerEpoch + epochSchedule.firstNormalSlot;
}
}

Expand All @@ -83,9 +74,6 @@ export function getFirstSlotInEpoch(
* @param epoch Epoch to get the last slot for
* @returns Last slot in the epoch
*/
export function getLastSlotInEpoch(
epochSchedule: EpochSchedule,
epoch: bigint
): bigint {
export function getLastSlotInEpoch(epochSchedule: EpochSchedule, epoch: bigint): bigint {
return getFirstSlotInEpoch(epochSchedule, epoch + 1n) - 1n;
}
22 changes: 11 additions & 11 deletions app/utils/local-storage.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
let localStorageIsAvailableDecision: boolean | undefined;
export function localStorageIsAvailable() {
if (localStorageIsAvailableDecision === undefined) {
const test = 'test';
try {
localStorage.setItem(test, test);
localStorage.removeItem(test);
localStorageIsAvailableDecision = true;
} catch (e) {
localStorageIsAvailableDecision = false;
if (localStorageIsAvailableDecision === undefined) {
const test = 'test';
try {
localStorage.setItem(test, test);
localStorage.removeItem(test);
localStorageIsAvailableDecision = true;
} catch (e) {
localStorageIsAvailableDecision = false;
}
}
}
return localStorageIsAvailableDecision;
}
return localStorageIsAvailableDecision;
}
2 changes: 1 addition & 1 deletion app/utils/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export function percentage(numerator: bigint, denominator: bigint, decimals: num
// since bigint is integer, we need to multiply first to get decimals
// see https://stackoverflow.com/a/63095380/1375972
const pow = 10 ** decimals;
return Number(numerator * BigInt(100 * pow) / denominator) / pow;
return Number((numerator * BigInt(100 * pow)) / denominator) / pow;
}
6 changes: 1 addition & 5 deletions app/utils/name-service.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
'use client';

import {
getFilteredProgramAccounts,
NAME_PROGRAM_ID,
performReverseLookup,
} from '@bonfida/spl-name-service';
import { getFilteredProgramAccounts, NAME_PROGRAM_ID, performReverseLookup } from '@bonfida/spl-name-service';
import { useCluster } from '@providers/cluster';
import { Connection, PublicKey } from '@solana/web3.js';
import { Cluster } from '@utils/cluster';
Expand Down
Loading

0 comments on commit 73e4e20

Please sign in to comment.