Skip to content

Commit dd32736

Browse files
committed
fix no wallet loader. default target chain to source. eliminate obsolete api requests
1 parent 74bf1b2 commit dd32736

File tree

10 files changed

+77
-65
lines changed

10 files changed

+77
-65
lines changed

app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"dev": "vite",
88
"build": "tsc -b && vite build",
9-
"lint": "eslint .",
9+
"lint": "tsc --noEmit --skipLibCheck",
1010
"preview": "vite preview"
1111
},
1212
"dependencies": {

widget/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ensofinance/shortcuts-widget",
3-
"version": "1.0.40",
3+
"version": "1.0.41",
44
"type": "module",
55
"homepage": "https://www.enso.build/",
66
"repository": {

widget/src/components/RouteIndication.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import {
88
HStack,
99
} from "@chakra-ui/react";
1010
import { ChevronsRight } from "lucide-react";
11-
import { Address, isAddress } from "viem";
12-
import { RouteData } from "@ensofinance/sdk";
13-
import { Token, useTokenFromList } from "@/util/common";
11+
import { type Address, isAddress } from "viem";
12+
import { type RouteData } from "@ensofinance/sdk";
13+
import { type Token, useTokenFromList } from "@/util/common";
1414
import { useEnsoToken } from "@/util/enso";
1515
import { TokenIcon } from "@/components/TokenIndicator";
1616

widget/src/components/SwapInput.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { useEffect, useState } from "react";
22
import { useDebounce } from "@uidotdev/usehooks";
33
import { Box, chakra, Flex, Skeleton, Text, Button } from "@chakra-ui/react";
44
import { useAccount } from "wagmi";
5-
import { Address, isAddress } from "viem";
5+
import { type Address, isAddress } from "viem";
66
import TokenSelector from "@/components/TokenSelector";
77
import { formatNumber, formatUSD, normalizeValue } from "@/util";
88
import { useTokenBalance } from "@/util/wallet";
99
import { useEnsoToken } from "@/util/enso";
1010
import { SupportedChainId } from "@/constants";
11-
import { ProjectFilter } from "@/types";
11+
import { type ProjectFilter } from "@/types";
1212

1313
const SwapInput = ({
1414
chainId,

widget/src/components/SwapWidget.tsx

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
Button,
1212
} from "@chakra-ui/react";
1313
import { ArrowDown, Fuel, TriangleAlert } from "lucide-react";
14-
import { Address, isAddress } from "viem";
14+
import { type Address, isAddress } from "viem";
1515
import { mainnet } from "viem/chains";
1616
import { Toaster } from "@/components/ui/toaster";
1717
import {
@@ -45,7 +45,7 @@ import { ClipboardLink, ClipboardRoot } from "@/components/ui/clipboard";
4545
import RouteIndication from "@/components/RouteIndication";
4646
import { Tooltip } from "@/components/ui/tooltip";
4747
import Slippage from "@/components/Slippage";
48-
import { NotifyType, ObligatedToken, WidgetComponentProps } from "@/types";
48+
import { NotifyType, ObligatedToken, type WidgetComponentProps } from "@/types";
4949

5050
const BridgingFee = ({
5151
gasValue,
@@ -109,7 +109,7 @@ const SwapWidget = ({
109109
);
110110

111111
const chainId = usePriorityChainId();
112-
const { chainId: wagmiChainId } = useAccount();
112+
const { chainId: wagmiChainId, address } = useAccount();
113113
const setOutChainId = useStore((state) => state.setTokenOutChainId);
114114
const outChainId = useStore((state) => state.tokenOutChainId ?? chainId);
115115
const obligatedChainId = useStore((state) => state.obligatedChainId);
@@ -143,8 +143,11 @@ const SwapWidget = ({
143143
if (chainId === wagmiChainId) {
144144
switchChain({ chainId: newChainId });
145145
}
146+
if (!tokenOut) {
147+
setOutChainId(newChainId);
148+
}
146149
},
147-
[wagmiChainId, chainId, setObligatedChainId, switchChain]
150+
[wagmiChainId, chainId, switchChain, tokenOut]
148151
);
149152

150153
// Notify parent of state changes when any relevant state changes
@@ -447,49 +450,53 @@ const SwapWidget = ({
447450
</Flex>
448451
</Box>
449452

450-
<Flex w={"full"} gap={4}>
451-
{wrongChain ? (
452-
<Button
453-
size="lg"
454-
borderRadius={"lg"}
455-
colorPalette={"blue"}
456-
onClick={() => switchChain({ chainId })}
457-
>
458-
Switch to {getChainName(chainId)}
459-
</Button>
460-
) : (
461-
approveNeeded && (
453+
{address ? (
454+
<Flex w={"full"} gap={4}>
455+
{wrongChain ? (
462456
<Button
463457
size="lg"
464458
borderRadius={"lg"}
465459
colorPalette={"blue"}
466-
flex={1}
467-
loading={approve.isLoading}
468-
onClick={approve.write}
460+
onClick={() => switchChain({ chainId })}
469461
>
470-
Approve
462+
Switch to {getChainName(chainId)}
471463
</Button>
472-
)
473-
)}
464+
) : (
465+
approveNeeded && (
466+
<Button
467+
size="lg"
468+
borderRadius={"lg"}
469+
colorPalette={"blue"}
470+
flex={1}
471+
loading={approve.isLoading}
472+
onClick={approve.write}
473+
>
474+
Approve
475+
</Button>
476+
)
477+
)}
474478

475-
<Tooltip content={swapWarning} disabled={!swapWarning}>
476-
<Button
477-
size="lg"
478-
borderRadius={"lg"}
479-
colorPalette={"blue"}
480-
flex={1}
481-
disabled={swapDisabled}
482-
loading={sendTransaction.isLoading || routerLoading}
483-
onClick={
484-
needToAcceptWarning
485-
? showPriceImpactWarning
486-
: sendTransaction.send
487-
}
488-
>
489-
{chainId === outChainId ? "Swap" : "Bridge"}
490-
</Button>
491-
</Tooltip>
492-
</Flex>
479+
<Tooltip content={swapWarning} disabled={!swapWarning}>
480+
<Button
481+
size="lg"
482+
borderRadius={"lg"}
483+
colorPalette={"blue"}
484+
flex={1}
485+
disabled={swapDisabled}
486+
loading={sendTransaction.isLoading || routerLoading}
487+
onClick={
488+
needToAcceptWarning
489+
? showPriceImpactWarning
490+
: sendTransaction.send
491+
}
492+
>
493+
{chainId === outChainId ? "Swap" : "Bridge"}
494+
</Button>
495+
</Tooltip>
496+
</Flex>
497+
) : (
498+
<Text>Please connect your wallet</Text>
499+
)}
493500

494501
{error && (
495502
<Text color="red.500" fontSize="xs" mt={1}>

widget/src/components/TokenIndicator.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Box, Flex, Text } from "@chakra-ui/react";
2-
import { Token } from "@/util/common";
2+
import { type Token } from "@/util/common";
33
import {
44
MOCK_IMAGE_URL,
55
SupportedChainId,

widget/src/components/TokenSelector.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import {
99
Box,
1010
} from "@chakra-ui/react";
1111
import { useMemo } from "react";
12-
import { Address, isAddress } from "viem";
12+
import { type Address, isAddress } from "viem";
1313
import { FixedSizeList as List } from "react-window";
14-
import { Token, useCurrentChainList } from "@/util/common";
14+
import { type Token, useCurrentChainList } from "@/util/common";
1515
import { formatNumber, normalizeValue } from "@/util";
1616
import { useEnsoBalances, useEnsoToken } from "@/util/enso";
1717
import { SupportedChainId } from "@/constants";
@@ -431,7 +431,6 @@ const TokenSelector = ({
431431
key={token.address}
432432
style={style}
433433
borderRadius={"md"}
434-
_hover={{ background: "bg.subtle" }}
435434
>
436435
<DetailedTokenIndicator token={token as TokenWithBalance} />
437436
</SelectItem>

widget/src/util/common.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useQuery } from "@tanstack/react-query";
22
import { useAccount } from "wagmi";
3-
import { Address, zeroAddress } from "viem";
3+
import { type Address, zeroAddress } from "viem";
44
import {
55
CHAINS_ETHERSCAN,
66
CHAINS_NATIVE_TOKENS,
@@ -271,7 +271,7 @@ export const useOutChainId = () => {
271271

272272
export const usePriorityChainId = (priorityChainId?: SupportedChainId) => {
273273
const obligatedChainId = useStore((state) => state.obligatedChainId);
274-
const { chainId } = useAccount();
274+
const { chainId = 1 } = useAccount();
275275

276276
return priorityChainId ?? obligatedChainId ?? chainId;
277277
};

widget/src/util/enso.tsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
import { Address } from "viem";
21
import { useAccount } from "wagmi";
3-
import { useQuery } from "@tanstack/react-query";
2+
import { useQuery, type UseQueryResult } from "@tanstack/react-query";
43
import { useCallback, useMemo } from "react";
54
import {
65
EnsoClient,
7-
RouteParams,
8-
BundleAction,
9-
BundleParams,
6+
type RouteParams,
7+
type BundleAction,
8+
type BundleParams,
109
BundleActionType,
11-
ProtocolData,
1210
} from "@ensofinance/sdk";
13-
import { isAddress } from "viem";
11+
import { type Address, isAddress } from "viem";
1412
import {
15-
Token,
13+
type Token,
1614
usePriorityChainId,
1715
useOutChainId,
1816
useTokenFromList,
@@ -315,13 +313,20 @@ export const useBundleData = (
315313
});
316314
};
317315

316+
type UseEnsoDataResult = UseQueryResult<
317+
Awaited<ReturnType<EnsoClient["getRouterData"]>>,
318+
Error
319+
> & {
320+
sendTransaction: ReturnType<typeof useSendEnsoTransaction>;
321+
};
322+
318323
export const useEnsoData = (
319324
amountIn: string,
320325
tokenIn: Address,
321326
tokenOut: Address,
322327
slippage: number,
323328
onSuccess?: (hash: string) => void
324-
) => {
329+
): UseEnsoDataResult => {
325330
const { address = VITALIK_ADDRESS } = useAccount();
326331
const chainId = usePriorityChainId();
327332
const outChainId = useOutChainId();
@@ -375,13 +380,13 @@ export const useEnsoData = (
375380
tokens: [tokenToData],
376381
} = useEnsoToken({
377382
address: routerParams.tokenOut,
378-
enabled: true,
383+
enabled: isAddress(routerParams.tokenOut),
379384
});
380385
const {
381386
tokens: [tokenFromData],
382387
} = useEnsoToken({
383388
address: routerParams.tokenIn,
384-
enabled: true,
389+
enabled: isAddress(routerParams.tokenIn),
385390
});
386391

387392
const swapTitle = `Purchase ${formatNumber(

widget/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"@/*": ["./src/*"]
99
},
1010
"jsx": "react-jsx",
11-
"declaration": true
11+
"declaration": true,
12+
"verbatimModuleSyntax": true
1213
}
1314
}

0 commit comments

Comments
 (0)