Skip to content

Commit 3949090

Browse files
committed
disable invalid requests. use own viem
1 parent 38e6dfa commit 3949090

File tree

5 files changed

+42
-18
lines changed

5 files changed

+42
-18
lines changed

pnpm-lock.yaml

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

widget/index.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useMemo, useState } from "react";
1+
import { useContext, useEffect, useMemo, useState } from "react";
22
import {
33
ChakraProvider,
44
createSystem,
@@ -7,6 +7,7 @@ import {
77
EnvironmentProvider,
88
} from "@chakra-ui/react";
99
import { Address } from "viem";
10+
import { WagmiContext } from "wagmi";
1011
import posthog from "posthog-js";
1112
import root from "react-shadow/emotion";
1213
import { CacheProvider } from "@emotion/react";
@@ -47,6 +48,16 @@ const Widget = ({
4748
null
4849
);
4950

51+
const context = useContext(WagmiContext);
52+
53+
useEffect(() => {
54+
if (!context) {
55+
console.error(
56+
"Wagmi context is not available. Ensure you are using the EVMProvider."
57+
);
58+
}
59+
}, [context]);
60+
5061
useEffect(() => {
5162
if (!shadow?.shadowRoot || cache) return;
5263
const emotionCache = createCache({

widget/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ensofinance/shortcuts-widget",
3-
"version": "1.0.25",
3+
"version": "1.0.28",
44
"type": "module",
55
"homepage": "https://www.enso.build/",
66
"repository": {
@@ -32,13 +32,13 @@
3232
"react-shadow": "^20.6.0",
3333
"react-window": "^1.8.11",
3434
"url": "^0.11.4",
35+
"viem": "^2.22.1",
3536
"zustand": "^5.0.3"
3637
},
3738
"peerDependencies": {
3839
"@tanstack/react-query": "^5.62.10",
3940
"react": "^18.2.0 || ^19.0.0",
4041
"react-dom": "^18.2.0 || ^19.0.0",
41-
"viem": "2.x",
4242
"wagmi": "^2.14.16"
4343
},
4444
"peerDependenciesMeta": {
@@ -61,7 +61,6 @@
6161
"prettier": "^3.4.2",
6262
"typescript": "~5.6.2",
6363
"typescript-eslint": "^8.18.2",
64-
"viem": "2.x",
6564
"vite": "^6.0.5",
6665
"vite-plugin-dts": "^4.4.0",
6766
"vite-plugin-lib-inject-css": "^2.2.1",

widget/src/util/wallet.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
useWriteContract,
1212
UseWriteContractReturnType,
1313
} from "wagmi";
14-
import { Address, BaseError } from "viem";
14+
import { Address, BaseError, isAddress } from "viem";
1515
import { useQuery, useQueryClient } from "@tanstack/react-query";
1616
import { RouteData } from "@ensofinance/sdk";
1717
import {
@@ -71,6 +71,12 @@ export const useErc20Balance = (
7171
abi: erc20Abi,
7272
functionName: "balanceOf",
7373
args: [address],
74+
query: {
75+
enabled:
76+
isAddress(address) &&
77+
isAddress(tokenAddress) &&
78+
!compareCaseInsensitive(tokenAddress, ETH_ADDRESS),
79+
},
7480
});
7581
};
7682

@@ -90,6 +96,9 @@ export const useTokenBalance = (
9096
const { data: balance, queryKey: balanceQueryKey } = useBalance({
9197
address,
9298
chainId,
99+
query: {
100+
enabled: compareCaseInsensitive(token, ETH_ADDRESS),
101+
},
93102
});
94103

95104
useEffect(() => {
@@ -115,6 +124,12 @@ export const useAllowance = (token: Address, spender: Address) => {
115124
abi: erc20Abi,
116125
functionName: "allowance",
117126
args: [address, spender],
127+
query: {
128+
enabled:
129+
isAddress(address) &&
130+
isAddress(token) &&
131+
!compareCaseInsensitive(token, ETH_ADDRESS),
132+
},
118133
});
119134

120135
useEffect(() => {
@@ -125,7 +140,7 @@ export const useAllowance = (token: Address, spender: Address) => {
125140
};
126141

127142
export const useApprove = (token: Address, target: Address, amount: string) => {
128-
const tokenData = useTokenFromList(token);
143+
const [tokenData] = useTokenFromList(token);
129144
const chainId = usePriorityChainId();
130145

131146
return {

widget/vite.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export default defineConfig(({ mode }) => ({
2626
"react",
2727
"react-dom",
2828
"wagmi",
29-
"viem",
3029
"@tanstack/react-query",
3130
"react/jsx-runtime",
3231
"react/jsx-dev-runtime",

0 commit comments

Comments
 (0)