Skip to content

Commit 9f06079

Browse files
authored
chore(entrykit): various improvements (#3699)
1 parent 9dc032a commit 9f06079

6 files changed

Lines changed: 36 additions & 13 deletions

File tree

.changeset/loud-keys-give.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@latticexyz/entrykit": patch
3+
---
4+
5+
- EntryKit now returns to the login flow modal after a successful top-up.
6+
- The default chain is now selected as the source chain if the connected chain is not part of selectable chains.
7+
- The "Switch chain" button now uses the primary color, making it appear clickable.
8+
- The successful deposit status message has been updated.

packages/entrykit/src/onboarding/GasBalance.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { useState } from "react";
1+
import { useEffect, useState } from "react";
22
import { Hex, parseEther } from "viem";
3+
import { useQueryClient } from "@tanstack/react-query";
34
import { PendingIcon } from "../icons/PendingIcon";
45
import { Button } from "../ui/Button";
56
import { Balance } from "../ui/Balance";
@@ -11,6 +12,7 @@ import { RelayChains, StepContentProps } from "./common";
1112
import { TruncatedHex } from "../ui/TruncatedHex";
1213
import { useShowMutationError } from "../errors/useShowMutationError";
1314
import { useShowQueryError } from "../errors/useShowQueryError";
15+
import { usePrevious } from "../errors/usePrevious";
1416
import { CopyIcon } from "../icons/CopyIcon";
1517
import { CheckIcon } from "../icons/CheckIcon";
1618

@@ -19,10 +21,12 @@ export type Props = StepContentProps & {
1921
};
2022

2123
export function GasBalance({ isActive, isExpanded, sessionAddress }: Props) {
24+
const queryClient = useQueryClient();
2225
const { chain } = useEntryKitConfig();
2326
const [copied, setCopied] = useState(false);
2427

2528
const balance = useShowQueryError(useBalance({ chainId: chain.id, address: sessionAddress }));
29+
const prevBalance = usePrevious(balance.data);
2630
useWatchBlockNumber({ onBlockNumber: () => balance.refetch() });
2731

2832
const setBalance = useShowMutationError(useSetBalance());
@@ -35,6 +39,12 @@ export function GasBalance({ isActive, isExpanded, sessionAddress }: Props) {
3539
setTimeout(() => setCopied(false), 2000);
3640
};
3741

42+
useEffect(() => {
43+
if (balance.data != null && prevBalance?.value === 0n && balance.data.value > 0n) {
44+
queryClient.invalidateQueries({ queryKey: ["getPrerequisites"] });
45+
}
46+
}, [balance.data, prevBalance, setBalance, sessionAddress, queryClient]);
47+
3848
return (
3949
<div className="flex flex-col gap-4">
4050
<div className="flex justify-between gap-4">

packages/entrykit/src/onboarding/deposit/ChainSelect.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { useMemo } from "react";
1+
import { useEffect, useMemo } from "react";
2+
import { useAccount, useSwitchChain } from "wagmi";
23
import { twMerge } from "tailwind-merge";
34
import * as Select from "@radix-ui/react-select";
45
import { useFrame } from "../../ui/FrameProvider";
5-
import { useAccount, useChains } from "wagmi";
66
import { useTheme } from "../../useTheme";
77
import { ChevronUpIcon } from "../../icons/ChevronUpIcon";
88
import { ChevronDownIcon } from "../../icons/ChevronDownIcon";
@@ -20,8 +20,7 @@ export function ChainSelect({ value, onChange }: Props) {
2020
const theme = useTheme();
2121
const { frame } = useFrame();
2222
const userAccount = useAccount();
23-
24-
const chains = useChains();
23+
const { chains, switchChain } = useSwitchChain();
2524
const relay = useRelay();
2625
const relayChains = relay.data?.chains;
2726

@@ -39,6 +38,14 @@ export function ChainSelect({ value, onChange }: Props) {
3938

4039
const selectedChain = sourceChains.find((c) => c.id === value)!;
4140

41+
useEffect(() => {
42+
if (sourceChains.length > 0 && !selectedChain) {
43+
const defaultChain = sourceChains[0];
44+
onChange(defaultChain.id);
45+
switchChain({ chainId: defaultChain.id });
46+
}
47+
}, [value, selectedChain, sourceChains, onChange, switchChain]);
48+
4249
return (
4350
<Select.Root
4451
value={value.toString()}

packages/entrykit/src/onboarding/deposit/SubmitButton.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export function SubmitButton({ amount, chainId, className, ...buttonProps }: Pro
2020
return (
2121
<Button
2222
type="button"
23+
variant="primary"
2324
className={twMerge("w-full", className)}
2425
pending={switchChain.isPending}
2526
onClick={() => switchChain.switchChain({ chainId })}

packages/entrykit/src/onboarding/deposit/TransferDepositStatus.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export function TransferDepositStatus({
7474
>
7575
deposited
7676
</a>{" "}
77-
<Balance wei={amount} /> !
77+
<Balance wei={amount} />
7878
</>
7979
);
8080
})()}

packages/entrykit/src/onboarding/quarry/GasBalance.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,10 @@ export function GasBalance({ isActive, isExpanded, isFocused, setFocused, userAd
2121
const prevBalance = usePrevious(balance.data || 0n);
2222

2323
useEffect(() => {
24-
const checkBalance = async () => {
25-
if (balance.data != null && prevBalance === 0n && balance.data > 0n) {
26-
await queryClient.invalidateQueries({ queryKey: ["getPrerequisites"] });
27-
setFocused(false);
28-
}
29-
};
30-
checkBalance();
24+
if (balance.data != null && prevBalance === 0n && balance.data > 0n) {
25+
queryClient.invalidateQueries({ queryKey: ["getPrerequisites"] });
26+
setFocused(false);
27+
}
3128
}, [balance.data, prevBalance, setFocused, queryClient, userAddress]);
3229

3330
if (isFocused) {

0 commit comments

Comments
 (0)