Skip to content

Commit

Permalink
fix: lint code
Browse files Browse the repository at this point in the history
  • Loading branch information
jhlee-young committed Nov 27, 2022
1 parent 4d22432 commit 1beb176
Show file tree
Hide file tree
Showing 26 changed files with 336 additions and 255 deletions.
10 changes: 10 additions & 0 deletions .babalrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"presets": [
[
"@babel/preset-react",
{ "runtime": "automatic", "importSource": "@emotion/react" },
"@emotion/babel-preset-css-prop"
]
],
"plugins": ["@emotion/babel-plugin"]
}
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"rules": {
"@typescript-eslint/no-explicit-any": "error",
"import/no-unresolved": "off",
"react/no-unknown-property": ["error", { "ignore": ["css"] }],
"import/extensions": "off",
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
Expand All @@ -38,6 +39,7 @@
"@typescript-eslint/no-shadow": "error",
"react/jsx-props-no-spreading": "off",
"react/destructuring-assignment": "off",
"react/prop-types": "off"
"react/prop-types": "off",
"no-console": "off"
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
"preview": "vite preview",
"lint": "eslint --ext .ts,.tsx src",
"format": "prettier **/*.ts **/*.tsx --write"
},
"dependencies": {
"@emotion/react": "^11.10.4",
Expand Down
20 changes: 7 additions & 13 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@ import { useCallback } from "react";
import GlobalStyles from "styles/GlobalStyles";

function App() {
const renderRoute = useCallback(
({ children, ...props }: RouteObject) => {
return (
<Route
key={`${props.path} ${props.index}`}
{...props}
>
{children?.map(renderRoute)}
</Route>
);
},
[],
);
const renderRoute = useCallback(({ children, ...props }: RouteObject) => {
return (
<Route key={`${props.path} ${props.index}`} {...props}>
{children?.map(renderRoute)}
</Route>
);
}, []);

return (
<>
Expand Down
44 changes: 29 additions & 15 deletions src/hooks/useAPI.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { useCallback, useMemo } from "react";
import { Pair, Pool, ReverseSimulation, Simulation} from "types/pair";
import { Pair, Pool, ReverseSimulation, Simulation } from "types/pair";
import { useConnectedWallet, useLCDClient } from "@xpla/wallet-provider";
import { Amount, generateReverseSimulationMsg, generateSimulationMsg, generatePairsMsg } from "utils/dezswap";
import {
Amount,
generateReverseSimulationMsg,
generateSimulationMsg,
generatePairsMsg,
} from "utils/dezswap";
import { Pairs } from "types/factory";
import axios from "axios";
import { AllowedTokenInfo } from "types/token";
Expand All @@ -15,16 +20,18 @@ export const useAPI = () => {
const connectedWallet = useConnectedWallet();
const walletAddress = useMemo(
() => connectedWallet?.walletAddress,
[connectedWallet]
[connectedWallet],
);

const getPairs = useCallback(
async (contractAddress: string, startAfter?: string[]) => {
if (!contractAddress) {
return undefined;
}
const res =
await lcd.wasm.contractQuery<Pairs>(contractAddress, generatePairsMsg(startAfter));
const res = await lcd.wasm.contractQuery<Pairs>(
contractAddress,
generatePairsMsg(startAfter),
);

return res;
},
Expand Down Expand Up @@ -61,22 +68,24 @@ export const useAPI = () => {

const simulate = useCallback(
async (contractAddress: string, offerAsset: string, amount: Amount) => {
const res = await lcd.wasm.contractQuery<Simulation>(contractAddress,
generateSimulationMsg(offerAsset, amount)
const res = await lcd.wasm.contractQuery<Simulation>(
contractAddress,
generateSimulationMsg(offerAsset, amount),
);
return res;
},
[lcd]
[lcd],
);

const reverseSimulate = useCallback(
async (contractAddress: string, askAsset: string, amount: Amount) => {
const res = await lcd.wasm.contractQuery<ReverseSimulation>(contractAddress,
generateReverseSimulationMsg(askAsset, amount)
const res = await lcd.wasm.contractQuery<ReverseSimulation>(
contractAddress,
generateReverseSimulationMsg(askAsset, amount),
);
return res;
},
[lcd]
[lcd],
);

const getNativeTokenBalance = useCallback(
Expand Down Expand Up @@ -110,10 +119,15 @@ export const useAPI = () => {
[lcd, walletAddress],
);

const getAllowedTokenInfos = useCallback(async (network: string): Promise<Record<string, AllowedTokenInfo>> => {
const { data } = await axios.get("https://assets.xpla.io/cw20/tokens.json");
return data[network];
}, []);
const getAllowedTokenInfos = useCallback(
async (network: string): Promise<Record<string, AllowedTokenInfo>> => {
const { data } = await axios.get(
"https://assets.xpla.io/cw20/tokens.json",
);
return data[network];
},
[],
);

const api = useMemo(
() => ({
Expand Down
19 changes: 11 additions & 8 deletions src/hooks/useBalance.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {useEffect, useState} from "react";
import { useEffect, useState } from "react";
import { useConnectedWallet } from "@xpla/wallet-provider";
import { useAPI } from "hooks/useAPI";
import {isNativeTokenAddress} from "utils/dezswap";
import { isNativeTokenAddress } from "utils/dezswap";

export const useBalance = (asset: string) => {
const connectedWallet = useConnectedWallet();
Expand All @@ -18,15 +18,18 @@ export const useBalance = (asset: string) => {
if (isNativeTokenAddress(asset)) {
api
.getNativeTokenBalance(asset)
.then(
(value) => (typeof value !== "undefined" && !isAborted) ? setBalance(`${value}`) : setBalance("0")
.then((value) =>
typeof value !== "undefined" && !isAborted
? setBalance(`${value}`)
: setBalance("0"),
);
} else {
api
.getTokenBalance(asset)
.then(
(value) =>
(typeof value !== "undefined" && !isAborted) ? setBalance(value) : setBalance("0")
.then((value) =>
typeof value !== "undefined" && !isAborted
? setBalance(value)
: setBalance("0"),
);
}
}
Expand All @@ -37,4 +40,4 @@ export const useBalance = (asset: string) => {
}, [api, connectedWallet, asset]);

return balance;
}
};
2 changes: 1 addition & 1 deletion src/hooks/useLCDClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import networks from "constants/network";
export const useLCDClient = (network: string) => {
const lcd = new LCDClient({
URL: networks[network].lcd,
chainID: networks[network].lcd
chainID: networks[network].lcd,
});

return { lcd };
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useNetwork.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {NetworkInfo, useWallet} from "@xpla/wallet-provider";
import {useMemo} from "react";
import { NetworkInfo, useWallet } from "@xpla/wallet-provider";
import { useMemo } from "react";

export const useNetwork = () => {
const { network } = useWallet();

return useMemo(() => network, [network]);
};
};
6 changes: 3 additions & 3 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import App from "App";
import ReactDOM from "react-dom/client";
import { BrowserRouter } from "react-router-dom";
import theme from "styles/theme";
import {QueryClient, QueryClientProvider} from "react-query";
import { QueryClient, QueryClientProvider } from "react-query";

const queryClient = new QueryClient();

Expand All @@ -19,6 +19,6 @@ getChainOptions().then((chainOptions) => {
</BrowserRouter>
</ThemeProvider>
</QueryClientProvider>
</WalletProvider>
</WalletProvider>,
);
});
});
4 changes: 1 addition & 3 deletions src/pages/Playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ const Wrapper = styled(Container)`
`;

function PlaygroundPage() {
return (
<Wrapper>Hello Dezswap!</Wrapper>
);
return <Wrapper>Hello Dezswap!</Wrapper>;
}

export default PlaygroundPage;
14 changes: 14 additions & 0 deletions src/pages/Pool/Provide/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { FormEventHandler, useCallback } from "react";

function ProvidePage() {
const handleSubmit = useCallback<FormEventHandler<HTMLFormElement>>(
(event) => {
/* TODO: implement */
},
[],
);

return <form onSubmit={handleSubmit} />;
}

export default ProvidePage;
5 changes: 5 additions & 0 deletions src/pages/Pool/Provide/useSimulate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const useSimulate = () => {
/* TODO: implement */
};

export default useSimulate;
14 changes: 14 additions & 0 deletions src/pages/Pool/Swap/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { FormEventHandler, useCallback } from "react";

function SwapPage() {
const handleSubmit = useCallback<FormEventHandler<HTMLFormElement>>(
(event) => {
/* TODO: implement */
},
[],
);

return <form onSubmit={handleSubmit} />;
}

export default SwapPage;
5 changes: 5 additions & 0 deletions src/pages/Pool/Swap/useSimulate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const useSimulate = () => {
/* TODO: implement */
};

export default useSimulate;
14 changes: 14 additions & 0 deletions src/pages/Pool/Withdraw/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { FormEventHandler, useCallback } from "react";

function WithdrawPage() {
const handleSubmit = useCallback<FormEventHandler<HTMLFormElement>>(
(event) => {
/* TODO: implement */
},
[],
);

return <form onSubmit={handleSubmit} />;
}

export default WithdrawPage;
5 changes: 5 additions & 0 deletions src/pages/Pool/Withdraw/useSimulate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const useSimulate = () => {
/* TODO: implement */
};

export default useSimulate;
2 changes: 1 addition & 1 deletion src/polyfills/polyfills.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ window.Buffer = Buffer;
window.process = process;

globalThis.Buffer = Buffer;
globalThis.process = process;
globalThis.process = process;
Loading

0 comments on commit 1beb176

Please sign in to comment.