Skip to content

Commit

Permalink
linting + clean
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre Meyer committed Jul 23, 2023
1 parent 6fbcd88 commit 97411f8
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 17 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ module.exports = {
ecmaVersion: 'latest',
sourceType: 'module',
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
},
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-explicit-any': ['warn'],
'@typescript-eslint/no-unsafe-member-access': ['warn'],
'@typescript-eslint/no-unsafe-assignment': 'off',
},
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "index.js",
"scripts": {
"preinstall": "npx only-allow pnpm",
"lint": "pnpm eslint src/",
"generate": "npx openapi-typescript https://api.enso.finance/api-json -o src/generated/api.d.ts",
"build": "pnpm build:setup && rollup -c",
"build:setup": "pnpm gts clean && mkdir dist && jq 'del(.scripts) | del(.devDependencies) | del(.private) | del(.pnpm)' package.json > dist/package.json",
Expand Down
4 changes: 2 additions & 2 deletions src/api/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ export const queryRouteWithApprovals = async (
if (!route) return { status: 'error', errorMessage: 'No route was found', route: null };

let approvals: ApproveTransaction[] | null = null;
let transfers: TransferTransaction[] | null = null;
// let transfers: TransferTransaction[] | null = null;

if (transferMethod === 'APPROVE_TRANSFERFROM') {
const allowances = await queryApprovals({ fromAddress: executor, chainId });

// Calculate approvals
let approvalAmountsNeeded: Record<string, BigNumberish> = {};
const approvalAmountsNeeded: Record<string, BigNumberish> = {};

(Array.isArray(tokenIn) ? tokenIn : [tokenIn]).forEach((token, index) => {
if (!isNativeToken(token)) {
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/internal/useLoadingStateFromQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { useMemo } from 'react';
import { LoadingState } from 'src/types';

export interface UseLoadingStateFromQueryArgs {
data: unknown | undefined;
error: unknown | undefined;
data: any | undefined;
error: any | undefined;
isLoading: boolean;
}

Expand Down
8 changes: 4 additions & 4 deletions src/hooks/useExecutePosition/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const useExecutePosition = (args?: UseExecutePositionArgs): UseExecuteSho
apiKey: context.apiKey,
transferMethod: args.options?.transferMethod ?? 'APPROVE_TRANSFERFROM',
chainId: args.position.chainId,
executor: defaultedExecutor as Address,
executor: defaultedExecutor,
amountIn: args.amountIn,
tokenIn: args.tokenIn,
tokenOut: positionToken as `0x${string}`,
Expand Down Expand Up @@ -68,7 +68,7 @@ export const useExecutePosition = (args?: UseExecutePositionArgs): UseExecuteSho
const executeRoute = useCallback(async () => {
if (!preparedTransaction) throw new Error('No route execution transaction available');
return walletClient?.sendTransaction(preparedTransaction);
}, [preparedTransaction]);
}, [preparedTransaction, walletClient]);

const executeApprovalsOrTransfers = useCallback(() => {
const transactionFuncs = routeQueryResponse?.approvals?.map(
Expand All @@ -82,7 +82,7 @@ export const useExecutePosition = (args?: UseExecutePositionArgs): UseExecuteSho
if (!transactionFuncs) return;

return Promise.all(transactionFuncs);
}, [routeQueryResponse]);
}, [routeQueryResponse, walletClient]);

const executionDetails = useMemo((): UseExecuteShortcutPayload['executionDetails'] => {
if (enabledQuery && routeQueryResponse && routeQueryResponse.route) {
Expand Down Expand Up @@ -115,7 +115,7 @@ export const useExecutePosition = (args?: UseExecutePositionArgs): UseExecuteSho
})),
};
}
}, [enabledQuery, routeQueryResponse, walletClient]);
}, [enabledQuery, routeQueryResponse, walletClient, executeRoute]);

const loadingState = useLoadingStateFromQuery({
isLoading: routeQueryLoading,
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useExecutePosition/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ExecutableRoute, Position } from 'src/types/api';
import { BigNumberish, LoadingState, TransferMethods } from 'src/types/enso';
import { Address } from 'viem';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type TransactionFunc = () => Promise<any> | void;

export type UseExecuteShortcutPayload = {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/usePositions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const usePositions = (args: UsePositionsArgs): UsePositionsPayload => {
const loadingState = useLoadingStateFromQuery({ data, error, isLoading });

const filteredData = useMemo(() => {
let filters: FilterType[] = [];
const filters: FilterType[] = [];
if (args.chain) {
filters.push((row: Position) => row.chainId === args.chain);
}
Expand Down
2 changes: 1 addition & 1 deletion src/queries/approve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const queryApprove = async (options: QueryApproveOptions): Promise<QueryA

const response = await fetch(`${ENSO_API}/api/v1/wallet/approve?${queryString.stringify(queryParams)}`);

const json = await response.json();
const json = (await response.json()) as QueryApproveResponse;

if (!json.tx) throw new Error('No valid response');
return json;
Expand Down
6 changes: 3 additions & 3 deletions src/queries/positions.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { USE_POSITIONS_DATA_SOURCE } from 'src/constants';
import { Position } from 'src/types/api';

export type QueryMetaPositionsArgs = {};
export type QueryMetaPositionsArgs = Record<never, never>;
export type QueryPositionsResponse = Position[];

export const queryPositions = async (): Promise<QueryPositionsResponse> => {
const response = await fetch(USE_POSITIONS_DATA_SOURCE);

const json = await response.json();
const json = (await response.json()) as QueryPositionsResponse;

if (!Array.isArray(json)) throw new Error('No valid response');
return json as QueryPositionsResponse;
return json;
};
12 changes: 8 additions & 4 deletions src/queries/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export type QueryRouteOptions = {
};
export type QueryRouteResponse = ExecutableRoute;

type APIError = { error: string; message: string; statusCode: number };
type APIResponse = ExecutableRoute | APIError;

export const queryRoute = async (options: QueryRouteOptions): Promise<QueryRouteResponse | undefined> => {
const queryParams = {
chainId: options.chainId,
Expand Down Expand Up @@ -48,9 +51,10 @@ export const queryRoute = async (options: QueryRouteOptions): Promise<QueryRoute
'Content-Type': 'application/json',
},
});
const route = (await routeResponse.json()) as ExecutableRoute;
if (!route.tx) {
throw new Error((route as any).error && (route as any).message ? (route as any).message : 'No valid response');
const route = (await routeResponse.json()) as APIResponse;
if (!(route as ExecutableRoute).tx) {
const err = route as APIError;
throw new Error(err.error && err.message ? err.message : 'No valid response');
}
return route;
return route as ExecutableRoute;
};

0 comments on commit 97411f8

Please sign in to comment.