Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
add chunking & remove ethers imports in app
Browse files Browse the repository at this point in the history
  • Loading branch information
subject026 committed Aug 23, 2023
1 parent 90ddab6 commit 609f17c
Show file tree
Hide file tree
Showing 12 changed files with 3,073 additions and 3,457 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"dependencies": {
"@apollo/client": "^3.8.1",
"@esbuild-plugins/node-globals-polyfill": "^0.1.1",
"@ethersproject/providers": "^5.7.2",
"@gnosis.pm/safe-apps-wagmi": "^1.2.0",
"@nomiclabs/hardhat-ethers": "^2.1.1",
"@rollup/plugin-inject": "^4.0.4",
Expand All @@ -35,7 +34,6 @@
"concurrently": "^7.4.0",
"env-cmd": "^10.1.0",
"eslint-plugin-chai-friendly": "^0.7.2",
"ethers": "^5.5.4",
"graphql": "16.6.0",
"gsap": "^3.9.1",
"hardhat-ethernal": "^2.1.0",
Expand All @@ -45,9 +43,11 @@
"react-dom": "^18.2.0",
"react-router-dom": "^6.3.0",
"recharts": "^2.7.3",
"rollup-plugin-visualizer": "^5.9.2",
"tailwindcss": "^3.0.23",
"viem": "^1.5.4",
"vite": "^2.9.8",
"vite": "2.9.8",
"vite-plugin-chunk-split": "^0.4.7",
"vite-plugin-markdown": "^2.1.0",
"wagmi": "^1.3.9",
"web-vitals": "^2.1.4"
Expand Down Expand Up @@ -85,6 +85,7 @@
"prettier": "^2.8.3",
"prettier-plugin-organize-imports": "^3.2.2",
"rimraf": "^3.0.2",
"rollup-plugin-node-polyfills": "^0.2.1",
"ts-jest": "^27.1.3",
"ts-node": "^10.9.1",
"typescript": "^5.1.6",
Expand Down
4 changes: 2 additions & 2 deletions src/components/Header/DesktopNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ function DesktopNavigation() {
<ExternalNavLink href="https://breadchain.mirror.xyz/">
Blog
</ExternalNavLink>
{/* <NavLink
<NavLink
isCurrentPage={location.pathname === '/dashboard'}
to="/dashboard"
>
Dashboard
</NavLink> */}
</NavLink>
</nav>
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/MobileMenu/MobileNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ function MobileNavigation({ handleNavToggle }: IProps) {
>
FAQ
</NavLink>
{/* <NavLink
<NavLink
isCurrentPage={location.pathname === '/dashboard'}
to="/dashboard"
>
Dashboard
</NavLink> */}
</NavLink>
<ExternalNavLink href="https://breadchain.mirror.xyz/">
Blog
</ExternalNavLink>
Expand Down
4 changes: 2 additions & 2 deletions src/components/NativeBalance/NativeBalance.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { formatEther } from 'ethers/lib/utils';
import { formatEther } from 'viem';
import { useBalance } from 'wagmi';
import Elipsis from '../Elipsis/Elipsis';

Expand Down Expand Up @@ -32,7 +32,7 @@ export function NativeBalance({
if (data) {
value = bigNumberFormat
? data.value.toString()
: formatter.format(parseFloat(formatEther(data.value.toString())));
: formatter.format(parseFloat(formatEther(data.value)));
}

switch (status) {
Expand Down
7 changes: 5 additions & 2 deletions src/components/Swap/ApproveContract/ApproveContract.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'ethers';
import { useEffect } from 'react';
import { hexToBigInt } from 'viem';
import { useContractWrite, usePrepareContractWrite } from 'wagmi';

import Button from '../../Button';
Expand All @@ -13,6 +13,9 @@ import {
useTransactionDisplay,
} from '../../../hooks/useTransactionDisplay';

const MAX_INT =
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff';

function transactionIsPending(
transactionDisplay: TTransactionDisplayState,
): boolean {
Expand All @@ -38,7 +41,7 @@ function ApproveContract({ chainConfig }: IProps) {
address: DAI.address,
abi: ERC20ABI,
functionName: 'approve',
args: [BREAD.address, ethers.constants.MaxUint256],
args: [BREAD.address, hexToBigInt(MAX_INT)],
});

const { data, error, isSuccess, write } = useContractWrite(config);
Expand Down
5 changes: 2 additions & 3 deletions src/hooks/useTokenAllowance.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BigNumber } from 'ethers';
import { formatUnits } from 'ethers/lib/utils';
import { formatUnits } from 'viem';
import { useContractRead } from 'wagmi';
import abi from '../ERC20.json';

Expand All @@ -25,7 +24,7 @@ export function useTokenAllowance(
watch,
});

const value = data ? formatUnits(data as BigNumber, 18) : undefined;
const value = data ? formatUnits(BigInt(data as string), 18) : undefined;

return {
value,
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useTokenBalance.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { formatUnits } from 'ethers/lib/utils';
import { formatUnits } from 'viem';
import { useContractRead } from 'wagmi';
import abi from '../ERC20.json';

Expand All @@ -20,7 +20,7 @@ export function useTokenBalance(
watch: true,
});

const value = data ? formatUnits(data as bigint, 18).toString() : '0';
const value = data ? formatUnits(BigInt(data as string), 18).toString() : '0';

return { value, status, error };
}
12 changes: 9 additions & 3 deletions src/modules/dashboard/hooks/useBread.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { gql, useQuery } from '@apollo/client';
import { formatUnits } from 'ethers/lib/utils';
import { useEffect, useMemo } from 'react';
import { formatUnits } from 'viem';

interface IQueryDailySnapshot {
timestamp: string;
Expand Down Expand Up @@ -71,14 +71,20 @@ export default function useBread() {
tokens: {
...(apolloData.tokens as IToken[]),
},
totalClaimedYield: formatUnits(apolloData.totalClaimedYield.amount),
totalClaimedYield: formatUnits(
BigInt(apolloData.totalClaimedYield.amount),
18,
),

tokenDailySnapshots: apolloData.tokenDailySnapshots
.map((day: IQueryDailySnapshot) => {
const date = new Date(
parseInt(day.timestamp, 10) * 1000,
).toDateString();
const supply = parseInt(formatUnits(day.dailyTotalSupply), 10);
const supply = parseInt(
formatUnits(BigInt(day.dailyTotalSupply), 18),
10,
);
return {
date,
supply,
Expand Down
4 changes: 2 additions & 2 deletions src/modules/dashboard/hooks/useYield.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { gql, useQuery } from '@apollo/client';
import { formatUnits } from 'ethers/lib/utils';
import { useMemo } from 'react';
import { formatUnits } from 'viem';

export interface ITotalClaimedYield {
totalClaimedYield: {
Expand Down Expand Up @@ -29,7 +29,7 @@ export default function useYield() {
if (!apolloData) return undefined;

return {
amount: formatUnits(apolloData.totalClaimedYield.amount),
amount: formatUnits(BigInt(apolloData.totalClaimedYield.amount), 18),
};
}, [apolloData]);

Expand Down
10 changes: 9 additions & 1 deletion src/routes/bake.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Suspense, lazy } from 'react';
import BakeLayout from '../components/BakeLayout';

import ConnectWallet from '../components/ConnectWallet';
import Elipsis from '../components/Elipsis';
import UnsupportedNetwork from '../components/UnsupportedNetwork/UnsupportedNetwork';
import { useConnectedUser } from '../hooks/useConnectedUser';

Expand Down Expand Up @@ -30,7 +31,14 @@ export function Bake() {

return (
<BakeLayout>
<Suspense>
<Suspense
fallback={
<p className="pt-16">
loading
<Elipsis />
</p>
}
>
<Swap chainConfig={user.config} accountAddress={user.address} />
</Suspense>
</BakeLayout>
Expand Down
38 changes: 33 additions & 5 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import GlobalPolyFill from '@esbuild-plugins/node-globals-polyfill';
import react from '@vitejs/plugin-react';
import * as path from 'path';
import { defineConfig } from 'vite';
import viteMarkdown, { Mode } from 'vite-plugin-markdown';

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react(), viteMarkdown({ mode: [Mode.HTML] })],
plugins: [
react(),
viteMarkdown({ mode: [Mode.HTML] }),
// chunkSplitPlugin()
],
build: {
target: 'esnext',
sourcemap: false,
Expand All @@ -21,18 +23,44 @@ export default defineConfig({
process: process.env.MODE !== 'production',
}),
],
output: {
manualChunks(id: string) {
if (id.includes('apollo')) {
return 'apollo';
}
if (id.includes('wagmi')) {
return 'wagmi';
}
if (id.includes('react')) {
return 'react';
}
if (id.includes('viem')) {
return 'viem';
}
return null;
},
},
},
},
define: {
globalThis: 'window',
},
// resolve: {
// alias: {
// process: 'process/browser',
// '@': path.resolve(__dirname, './src/'),
// },
// },
resolve: {
alias: {
process: 'process/browser',
'@': path.resolve(__dirname, './src/'),
// polyfills
Buffer: 'vite-compatible-readable-buffer',
stream: 'vite-compatible-readable-stream',
util: 'rollup-plugin-node-polyfills/polyfills/util',
},
},
optimizeDeps: {
disabled: false,
esbuildOptions: {
// Node.js global to browser globalThis
define: {
Expand Down
Loading

0 comments on commit 609f17c

Please sign in to comment.