Skip to content

Commit

Permalink
Merge pull request #153 from greymass/linting
Browse files Browse the repository at this point in the history
Linting
  • Loading branch information
dafuga authored Oct 3, 2024
2 parents 39220a7 + 6bdbf6c commit 97d36be
Show file tree
Hide file tree
Showing 96 changed files with 333 additions and 296 deletions.
25 changes: 24 additions & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ name: Code Checks
on:
push:

env:
PUBLIC_LOCAL_SIGNER: ''
API_EOS_CHAIN: ''
API_EOS_HISTORY: ''
API_EOS_METRICS: ''
API_JUNGLE4_CHAIN: ''
API_JUNGLE4_HISTORY: ''
API_KYLIN_CHAIN: ''
API_KYLIN_HISTORY: ''

jobs:
formatting:
runs-on: ubuntu-latest
Expand All @@ -13,7 +23,7 @@ jobs:
fetch-depth: 1
- uses: oven-sh/setup-bun@v2
- run: bun install
- run: bun lint
- run: bun run lint
types:
runs-on: ubuntu-latest
steps:
Expand All @@ -23,4 +33,17 @@ jobs:
fetch-depth: 1
- uses: oven-sh/setup-bun@v2
- run: bun install
- run: bun run build-paraglide
- run: bunx tsc --noemit

sveltekit-check:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: oven-sh/setup-bun@v2
- run: bun install
- run: bun run build-paraglide
- run: bun run check
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ export default [
}
},
{
ignores: ['build/', '.svelte-kit/', 'dist/']
ignores: ['build/', '.svelte-kit/', 'dist/', 'src/lib/wharf/contracts/']
}
];
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"private": true,
"scripts": {
"dev": "vite dev",
"build": "npx @inlang/paraglide-js compile --project ./project.inlang --outdir ./src/lib/paraglide && vite build",
"build-paraglide": "npx @inlang/paraglide-js compile --project ./project.inlang --outdir ./src/lib/paraglide",
"build": "bun run build-paraglide && vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
Expand Down
13 changes: 5 additions & 8 deletions src/hooks.server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { sequence } from '@sveltejs/kit/hooks';
import type { Handle, RequestEvent } from '@sveltejs/kit';

import { availableLanguageTags } from '$lib/paraglide/runtime';
import { availableLanguageTags } from '$lib/paraglide/runtime.js';
import { i18n } from '$lib/i18n';
import { isNetworkShortName } from '$lib/wharf/chains';

Expand All @@ -14,7 +14,7 @@ export function getHeaderLang(event: RequestEvent) {
acceptLanguage?.split(',')?.map((lang: string) => lang.split(';')[0].split('-')[0].trim()) ??
[];
for (const locale of locales) {
if (availableLanguageTags.includes(locale)) {
if (availableLanguageTags.find((l: string) => l.toLowerCase() === locale)) {
return locale;
}
}
Expand All @@ -25,16 +25,12 @@ function isAPIPath(pathname: string) {
return /^\/[a-z0-9]+\/api/gm.test(pathname);
}

function isDevPath(pathname: string) {
return /^\/[a-z0-9]+\/debug/gm.test(pathname);
}

function skipRedirect(pathname: string) {
return isAPIPath(pathname);
}

function isLanguage(value: string) {
return availableLanguageTags.find((l) => l.toLowerCase() === value);
return availableLanguageTags.find((l: string) => l.toLowerCase() === value);
}

function isNetwork(value: string) {
Expand Down Expand Up @@ -77,7 +73,8 @@ export async function redirectHandle({ event, resolve }: HandleParams): Promise<
pathMore.unshift(pathFirst);
}

event.locals.lang = lang;
// Ensure that the 'lang' property exists on the 'Locals' type
(event.locals as { lang: string }).lang = lang;

let url = `/${lang}`;
if (network) {
Expand Down
3 changes: 1 addition & 2 deletions src/lib/components/circleprogress.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<script lang="ts">
import { tweened } from 'svelte/motion';
import { cubicInOut } from 'svelte/easing';
import { onMount, type Snippet } from 'svelte';
import type { HTMLAttributes } from 'svelte/elements';
import { type Snippet } from 'svelte';
interface Props {
children?: Snippet;
Expand Down
3 changes: 2 additions & 1 deletion src/lib/components/input/asset.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
}
});
debug &&
if (debug) {
$inspect({
input,
number,
Expand All @@ -115,6 +115,7 @@
satisfiesMinimum,
satisfiesMaximum
});
}
</script>

<TextInput
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/input/assetOrUnits.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
}: AssetOrUnitsProps = $props();
let assetSymbol: Asset.Symbol = $derived(assetValue.symbol);
let assetInputRef: HTMLInputElement;
let unitsInputRef: HTMLInputElement;
let assetInputRef: HTMLInputElement | undefined = $state();
let unitsInputRef: HTMLInputElement | undefined = $state();
function toggleInputType(event: Event) {
event.preventDefault();
Expand Down
3 changes: 2 additions & 1 deletion src/lib/components/input/name.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@
}
});
debug &&
if (debug) {
$inspect({
input,
satisfies
});
}
</script>

<TextInput bind:ref bind:value={input} {autofocus} {...props} />
Expand Down
8 changes: 6 additions & 2 deletions src/lib/components/input/search.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
}
let {
autofocus = false,
network,
ref = $bindable(),
debug = false,
Expand All @@ -26,6 +25,8 @@
let searchValue: string = $state('');
const searchType = $derived.by(() => {
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable no-empty */
try {
PublicKey.from(searchValue);
return 'key';
Expand All @@ -45,6 +46,8 @@
return 'block';
} catch (e) {}
return 'unknown';
/* eslint-enable @typescript-eslint/no-unused-vars */
/* eslint-enable no-empty */
});
const result = $derived.by(() => {
Expand Down Expand Up @@ -91,13 +94,14 @@
searchValue = '';
}
debug &&
if (debug) {
$inspect({
searchValue,
searchType,
result,
open: $open
});
}
</script>

<svelte:window on:keydown={handleKeydown} />
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/layout/grid.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
itemWidth?: string;
}
const { class: className = '', children, itemWidth = '20ch', ...props }: Props = $props();
const { children, itemWidth = '20ch', ...props }: Props = $props();
</script>

<div class={`layout-grid`} {...props} style={`--grid-itemWidth:${itemWidth}`}>
Expand Down
8 changes: 1 addition & 7 deletions src/lib/components/layout/sidebar/content.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@
class?: string;
children: Snippet;
}
const {
threshold = '50%',
children,
tag = 'div',
class: className = '',
...props
}: Props = $props();
const { threshold = '50%', children, tag = 'div', ...props }: Props = $props();
</script>

<!--
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/select/account.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
}
const {
elements: { trigger, overlay, content, title, description, close, portalled },
elements: { trigger, overlay, content, title, close, portalled },
states: { open }
} = createDialog({
// defaultOpen: true,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/select/language.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { page } from '$app/stores';
import { i18n } from '$lib/i18n';
import { availableLanguageTags, languageTag } from '$lib/paraglide/runtime';
import { availableLanguageTags, languageTag } from '$lib/paraglide/runtime.js';
import { createSelect, melt } from '@melt-ui/svelte';
import { fade } from 'svelte/transition';
import ChevronDown from 'lucide-svelte/icons/chevron-down';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/toast/toast.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { fly } from 'svelte/transition';
import { melt, type Toast } from '@melt-ui/svelte';
import { elements as toastElements, type ToastData } from '$lib/state/toaster.svelte';
import type { elements as toastElements, ToastData } from '$lib/state/toaster.svelte';
interface Props {
elements: typeof toastElements;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createI18n } from '@inlang/paraglide-sveltekit';
import * as runtime from '$lib/paraglide/runtime.js';
import * as runtime from './paraglide/runtime';
import type { Asset } from '@wharfkit/antelope';

export const i18n = createI18n(runtime, {
Expand Down
37 changes: 21 additions & 16 deletions src/lib/state/client/account.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,23 +219,28 @@ export function getBalances(
tokenmeta?: TokenMeta[]
): TokenBalance[] {
if (sources.light_account) {
const balances = sources.light_account.map((result) => {
const asset = Asset.from(`${result.amount} ${result.currency}`);
const contract = Name.from(result.contract);
const id = TokenIdentifier.from({
chain,
contract: contract,
symbol: asset.symbol
const balances: TokenBalance[] = [];
sources.light_account.forEach((lightAccount) => {
lightAccount.balances?.forEach((balance) => {
const asset = Asset.from(`${balance.amount} ${balance.currency}`);
const contract = Name.from(balance.contract);
const id = TokenIdentifier.from({
chain: chain,
contract: contract,
symbol: asset.symbol
});
const metadata =
tokenmeta && tokenmeta.length > 0
? tokenmeta.find((meta) => meta.id.equals(id))
: undefined;
balances.push(
TokenBalance.from({
asset,
contract,
metadata: metadata || TokenMeta.from({ id: { chain, contract, symbol: asset.symbol } })
})
);
});
const metadata =
tokenmeta && tokenmeta.length > 0
? tokenmeta.find((meta) => meta.id.equals(id))
: undefined;
return {
asset,
contract,
metadata: metadata || TokenMeta.from({ id: { chain, contract, symbol: asset.symbol } })
};
});

return balances;
Expand Down
5 changes: 3 additions & 2 deletions src/lib/state/network.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
chainConfigs,
chainMapper,
type ChainConfig,
type ChainShortName,
type DefaultContracts,
type FeatureType
} from '$lib/wharf/chains';
Expand All @@ -33,7 +34,7 @@ export class NetworkState {
public fetch = fetch;
public last_update: Date = $state(new Date());
public loaded = $state(false);
public shortname: string;
public shortname: keyof typeof tokens;
public snapOrigin?: string = $state();

public contracts: DefaultContracts;
Expand Down Expand Up @@ -201,7 +202,7 @@ export function getNetwork(chain: ChainDefinition, fetchOverride?: typeof window

export function getChainDefinitionFromParams(network: string): ChainDefinition {
if (network) {
const id = chainMapper.toChainId(network);
const id = chainMapper.toChainId(network as ChainShortName);
const name = chainIdsToIndices.get(id);
if (name) {
// Return the chain that's found
Expand Down
1 change: 1 addition & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class ActivityAction extends Struct {
@Struct.field(Name) declare contract: Name;
@Struct.field(Name) declare action: Name;
@Struct.field(PermissionLevel, { array: true }) declare authorizations: PermissionLevel[];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@Struct.field('any') declare data: any;
@Struct.field(API.v1.OrderedActionsResult) declare raw: API.v1.OrderedActionsResult;
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export function getCacheHeaders(ttl: number, irreversible: boolean = false) {
};
}

export function preventDefault(fn: (event: Event) => void) {
return function (event: Event) {
export function preventDefault<TThis>(fn: (this: TThis, event: Event) => void) {
return function (this: TThis, event: Event) {
event.preventDefault();
fn.call(this, event);
};
Expand Down
4 changes: 4 additions & 0 deletions src/lib/wharf/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ export const chainMap: Record<string, ChainShortName> = {
// f16b1833c747c43682f4386fca9cbb327929334a762755ebec17f6f23c9b8a12: 'waxtestnet'
};

type Invert<M extends Record<keyof M, PropertyKey>> = {
[K in keyof M as M[K]]: K;
};

export function createMappers<M extends Record<keyof M, PropertyKey>>(map: M) {
const invertedMap = (Object.entries(map) as Array<[PropertyKey, PropertyKey]>).reduce(
(inverted, [key, value]) => ({ ...inverted, [value]: key }),
Expand Down
1 change: 1 addition & 0 deletions src/lib/wharf/contracts/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export interface TableTypes {
accounts: Types.account;
stat: Types.currency_stats;
}

export type RowType<T> = T extends keyof TableTypes ? TableTypes[T] : any;
export type TableNames = keyof TableTypes;
export namespace ActionParams {
Expand Down
3 changes: 2 additions & 1 deletion src/lib/wharf/transact.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export interface QueuedTransaction {
network: string;
args: TransactArgs;
options?: TransactOptions;
response?: any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
response?: Record<string, any>;
transaction?: Transaction;
error?: string;
toastId?: string;
Expand Down
3 changes: 2 additions & 1 deletion src/routes/+layout.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type SeoConfig } from 'svead';
import { i18n } from '$lib/i18n';
import type { LoadEvent } from '@sveltejs/kit';

function generateMetadata(url: URL): SeoConfig {
const modified = new URL(url);
Expand All @@ -11,7 +12,7 @@ function generateMetadata(url: URL): SeoConfig {
};
}

export const load = async ({ url }) => {
export const load = async ({ url }: LoadEvent) => {
const baseMetaTags = generateMetadata(url);
return {
baseMetaTags
Expand Down
Loading

0 comments on commit 97d36be

Please sign in to comment.